5 # This tool lets you parse multiple fio log files and look at interaval
6 # statistics even when samples are non-uniform. For instance:
8 # fiologparser.py -s *bw*
10 # to see per-interval sums for all bandwidth logs or:
12 # fiologparser.py -a *clat*
14 # to see per-interval average completion latency.
20 parser = argparse.ArgumentParser()
21 parser.add_argument('-i', '--interval', required=False, type=int, default=1000, help='interval of time in seconds.')
22 parser.add_argument('-d', '--divisor', required=False, type=int, default=1, help='divide the results by this value.')
23 parser.add_argument('-f', '--full', dest='full', action='store_true', default=False, help='print full output.')
24 parser.add_argument('-A', '--all', dest='allstats', action='store_true', default=False,
25 help='print all stats for each interval.')
26 parser.add_argument('-a', '--average', dest='average', action='store_true', default=False, help='print the average for each interval.')
27 parser.add_argument('-s', '--sum', dest='sum', action='store_true', default=False, help='print the sum for each interval.')
28 parser.add_argument("FILE", help="collectl log output files to parse", nargs="+")
29 args = parser.parse_args()
33 def get_ftime(series):
36 if ftime == 0 or ts.last.end < ftime:
40 def print_full(ctx, series):
41 ftime = get_ftime(series)
45 while (start < ftime):
46 end = ftime if ftime < end else end
47 results = [ts.get_value(start, end) for ts in series]
48 print("%s, %s" % (end, ', '.join(["%0.3f" % i for i in results])))
52 def print_sums(ctx, series):
53 ftime = get_ftime(series)
57 while (start < ftime):
58 end = ftime if ftime < end else end
59 results = [ts.get_value(start, end) for ts in series]
60 print("%s, %0.3f" % (end, sum(results)))
64 def print_averages(ctx, series):
65 ftime = get_ftime(series)
69 while (start < ftime):
70 end = ftime if ftime < end else end
71 results = [ts.get_value(start, end) for ts in series]
72 print("%s, %0.3f" % (end, float(sum(results))/len(results)))
76 # FIXME: this routine is computationally inefficient
77 # and has O(N^2) behavior
78 # it would be better to make one pass through samples
79 # to segment them into a series of time intervals, and
80 # then compute stats on each time interval instead.
81 # to debug this routine, use
82 # # sort -n -t ',' -k 2 small.log
85 def my_extend( vlist, val ):
89 array_collapser = lambda vlist, val: my_extend(vlist, val)
91 def print_all_stats(ctx, series):
92 ftime = get_ftime(series)
95 print('start-time, samples, min, avg, median, 90%, 95%, 99%, max')
96 while (start < ftime): # for each time interval
97 end = ftime if ftime < end else end
98 sample_arrays = [ s.get_samples(start, end) for s in series ]
99 samplevalue_arrays = []
100 for sample_array in sample_arrays:
101 samplevalue_arrays.append(
102 [ sample.value for sample in sample_array ] )
103 # collapse list of lists of sample values into list of sample values
104 samplevalues = reduce( array_collapser, samplevalue_arrays, [] )
105 # compute all stats and print them
106 mymin = min(samplevalues)
107 myavg = sum(samplevalues) / float(len(samplevalues))
108 mymedian = median(samplevalues)
109 my90th = percentile(samplevalues, 0.90)
110 my95th = percentile(samplevalues, 0.95)
111 my99th = percentile(samplevalues, 0.99)
112 mymax = max(samplevalues)
113 print( '%f, %d, %f, %f, %f, %f, %f, %f, %f' % (
114 start, len(samplevalues),
115 mymin, myavg, mymedian, my90th, my95th, my99th, mymax))
117 # advance to next interval
118 start += ctx.interval
123 return float(s[(len(s)-1)/2]+s[(len(s)/2)])/2
125 def percentile(values, p):
132 return (s[int(f)] * (c-k)) + (s[int(c)] * (k-f))
134 def print_default(ctx, series):
135 ftime = get_ftime(series)
141 while (start < ftime):
142 end = ftime if ftime < end else end
143 results = [ts.get_value(start, end) for ts in series]
144 averages.append(sum(results))
145 weights.append(end-start)
146 start += ctx.interval
150 for i in range(0, len(averages)):
151 total += averages[i]*weights[i]
152 print('%0.3f' % (total/sum(weights)))
154 class TimeSeries(object):
155 def __init__(self, ctx, fn):
161 def read_data(self, fn):
165 (time, value, foo, bar) = line.rstrip('\r\n').rsplit(', ')
166 self.add_sample(p_time, int(time), int(value))
169 def add_sample(self, start, end, value):
170 sample = Sample(ctx, start, end, value)
171 if not self.last or self.last.end < end:
173 self.samples.append(sample)
175 def get_samples(self, start, end):
177 for s in self.samples:
178 if s.start >= start and s.end <= end:
179 sample_list.append(s)
182 def get_value(self, start, end):
184 for sample in self.samples:
185 value += sample.get_contribution(start, end)
188 class Sample(object):
189 def __init__(self, ctx, start, end, value):
195 def get_contribution(self, start, end):
196 # short circuit if not within the bound
197 if (end < self.start or start > self.end):
200 sbound = self.start if start < self.start else start
201 ebound = self.end if end > self.end else end
202 ratio = float(ebound-sbound) / (end-start)
203 return self.value*ratio/ctx.divisor
206 if __name__ == '__main__':
210 series.append(TimeSeries(ctx, fn))
212 print_sums(ctx, series)
214 print_averages(ctx, series)
216 print_full(ctx, series)
218 print_all_stats(ctx, series)
220 print_default(ctx, series)