Merge lp:~stefanor/ibid/objstats-examine into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera
Status: Merged
Approved by: Jonathan Hitchcock
Approved revision: not available
Merged at revision: 774
Proposed branch: lp:~stefanor/ibid/objstats-examine
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: 114 lines (+54/-30)
1 file modified
scripts/ibid-objgraph (+54/-30)
To merge this branch: bzr merge lp:~stefanor/ibid/objstats-examine
Reviewer Review Type Date Requested Status
Jonathan Hitchcock Approve
Michael Gorven Approve
Review via email: mp+15515@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michael Gorven (mgorven) wrote :

Um, okay.
 review approve

review: Approve
Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/ibid-objgraph'
2--- scripts/ibid-objgraph 2009-10-19 15:07:40 +0000
3+++ scripts/ibid-objgraph 2009-12-01 22:25:20 +0000
4@@ -16,6 +16,8 @@
5 types are a list of object types to graph""")
6 parser.add_option('-o', '--output', dest='output', metavar='FILE',
7 help='Output to filename rather than interactive')
8+parser.add_option('-e', '--examine', dest='examine', metavar='TIME',
9+ default=None, help='Instead of graphing, find what changed at TIME')
10 parser.add_option('-d', '--dpi', dest='dpi',
11 help='Output DPI')
12
13@@ -24,7 +26,7 @@
14 if len(args) < 1:
15 sys.stderr.write("Log file required\n")
16 sys.exit(2)
17-if len(args) < 2:
18+if options.examine is None and len(args) < 2:
19 sys.stderr.write("At least one type required\n")
20 sys.exit(2)
21
22@@ -37,41 +39,63 @@
23
24 botname = header.split(':', 1)[1].strip()
25
26+if options.examine is not None:
27+ options.examine=dateutil.parser.parse(options.examine)
28+
29 types = args[1:]
30
31 times = []
32 data = []
33
34 for line in f:
35- timestamp, json = line.split(' ', 1)
36-
37- times.append(date2num(dateutil.parser.parse(timestamp)))
38-
39- json = json.loads(json)
40- data.append([json.get(type, 0) for type in types])
41-
42-times = numpy.array(times, dtype=float)
43-data = numpy.array(data, dtype=int)
44-
45-fig = pyplot.figure()
46-ax = fig.add_subplot(111)
47-ax.set_xlabel('time (s)')
48-ax.set_ylabel('Objects (k)', color='b')
49-ax.grid(True)
50-
51-ax.set_color_cycle(list('brgycmk'))
52-
53-for i, type in enumerate(types):
54- ax.plot_date(times, data[:,i], '-', label=type)
55-
56-pyplot.legend(loc='best')
57-pyplot.title(botname + ' Object Stats')
58-
59-fig.autofmt_xdate()
60-
61-if options.output:
62- pyplot.savefig(options.output, dpi=options.dpi)
63+ timestamp, stats = line.split(' ', 1)
64+
65+ timestamp = dateutil.parser.parse(timestamp)
66+ times.append(date2num(timestamp))
67+
68+ stats = json.loads(stats)
69+ if options.examine is None:
70+ data.append([stats.get(type, 0) for type in types])
71+ else:
72+ if timestamp < options.examine:
73+ data = [stats]
74+ else:
75+ data.append(stats)
76+ break
77+
78+if options.examine is None:
79+ times = numpy.array(times, dtype=float)
80+ data = numpy.array(data, dtype=int)
81+
82+ fig = pyplot.figure()
83+ ax = fig.add_subplot(111)
84+ ax.set_xlabel('time (s)')
85+ ax.set_ylabel('Objects (k)', color='b')
86+ ax.grid(True)
87+
88+ ax.set_color_cycle(list('brgycmk'))
89+
90+ for i, type in enumerate(types):
91+ ax.plot_date(times, data[:,i], '-', label=type)
92+
93+ pyplot.legend(loc='best')
94+ pyplot.title(botname + ' Object Stats')
95+
96+ fig.autofmt_xdate()
97+
98+ if options.output:
99+ pyplot.savefig(options.output, dpi=options.dpi)
100+ else:
101+ pyplot.show()
102+
103 else:
104- pyplot.show()
105+ delta = []
106+ for key, value in data[1].iteritems():
107+ if key in data[0]:
108+ delta.append((value - data[0][key], key))
109+
110+ delta.sort(reverse=True)
111+ for item in delta:
112+ print '%i\t%s' % item
113
114 # vi: set et sta sw=4 ts=4:

Subscribers

People subscribed via source and target branches