サンプルプログラム集
提供: Wikinote
2011年2月26日 (土) 00:58時点におけるHagio (トーク | 投稿記録)による版 (新しいページ: '== C == == Python == === calc_buddy.py === /proc/buddyinfo のそれぞれのゾーンの合計サイズを計算するスクリプト。 タイムスタンプを付けて...')
C
Python
calc_buddy.py
/proc/buddyinfo のそれぞれのゾーンの合計サイズを計算するスクリプト。 タイムスタンプを付けて記録したファイルにも対応。
$ ./calc_buddy.py Node 0, zone DMA 46 5 3 0 0 0 0 1 1 1 0 3856 KB Node 0, zone Normal 327 2 1 1 1 1 1 0 0 0 1 5916 KB Node 0, zone HighMem 78051 15607 279 2 59 17 2 0 0 0 0 448052 KB
ソースコード <toggledisplay>
#!/usr/bin/env python
import sys
if len(sys.argv) == 1:
files = [ open('/proc/buddyinfo', 'r') ]
ts_shift = 4;
else:
files = [ open(f) for f in sys.argv[1:] ]
ts_shift = 6;
for file in files:
for line in file:
if len(line) > 1:
print line[:-1],
fields = line.split()
total = 0
for val in range(0,11):
total += int(fields[ts_shift + val]) * 4 * 2**val
print total, "KB"
else:
print line,
file.close()
</toggledisplay>