kmod/scripts/parse-depmod

78 lines
1.8 KiB
Python
Executable File

#!/usr/bin/python
import sys
import os.path
import argparse
def parse_table(f):
curr = 0
x = []
y = []
while (True):
line = f.readline()
if line == '#####\n':
if curr == 3:
break
else:
curr += 1
elif curr == 2:
v = [int(i) for i in line.strip().split()]
x += [v[0]]
y += [v[1]]
return x, y
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.anchored_artists import AnchoredText
def add_at(ax, t, loc=2):
fp = dict(size=9)
_at = AnchoredText(t, loc=loc, prop=fp)
_at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2")
_at.patch.set_alpha(0.8)
_at.patch.set_fc('#A9A9A9')
ax.add_artist(_at)
return _at
parser = argparse.ArgumentParser()
parser.add_argument('--save', action='store_true')
parser.add_argument('files', nargs='*')
args = parser.parse_args()
figs = []
for fn in args.files:
fig = plt.figure()
figs += [fig]
with open(fn) as f:
for i in range(0, 3):
x, y = parse_table(f)
fit = np.polyfit(x, y, 1)
fit_fn = np.poly1d(fit)
ax = fig.add_subplot(2, 2, i, axisbg='#f6f6f6')
ax.plot(x, y, 'b', x, fit_fn(x), 'r')
ax.set_xlabel('bucket')
ax.set_ylabel('entries')
ax.axis('tight')
add_at(ax, 'mean=%.2f\nstddev=%.2f' % (np.mean(y), np.std(y)))
ax.grid(True)
tit = os.path.splitext(os.path.basename(fn))[0]
fig.suptitle('Hash distribution on buckets: %s' % tit, weight='bold',
size='large')
fig.tight_layout()
fig.subplots_adjust(top=0.9)
if args.save:
for fig, fn in zip(figs, args.files):
fig.savefig(os.path.splitext(fn)[0] + '.png')
else:
plt.show()