blob: 7e143f8e11039a3589df39bf9246bb547d07ef87 [file] [log] [blame]
Dennis Kempin19e972b2013-06-20 13:21:38 -07001#! /usr/bin/env python
2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
Dennis Kempin6e03a432013-06-25 09:00:53 -07006from mtedit import MTEdit
7from mtlib import Log
8from mtreplay import MTReplay
Dennis Kempin19e972b2013-06-20 13:21:38 -07009from mtstat import MTStat
Dennis Kempin6e03a432013-06-25 09:00:53 -070010from optparse import OptionParser
Dennis Kempin19e972b2013-06-20 13:21:38 -070011
12usage = """Multitouch Statistic Collector
13
14Download latest N feedback reports
15$ %prog -d N
Dennis Kempin6e03a432013-06-25 09:00:53 -070016
17Run and print statistics
18$ %prog
19
20Randomly select N logs and run
21$ %prog -n N
22
23Search all (or -n N) logs for occurence of TAG and
24serve the search results in MTEdit
25$ %prog -s TAG
Dennis Kempin19e972b2013-06-20 13:21:38 -070026"""
27
28def main():
29 parser = OptionParser(usage=usage)
30 parser.add_option('-d',
31 dest='download', default=None,
32 help='download more log files')
33 parser.add_option('-o',
34 dest='offset', default=0,
35 help='offset for downloading log files')
36 parser.add_option('-n',
37 dest='number', default=None,
38 help='number of log files to gather stats on')
Dennis Kempin6e03a432013-06-25 09:00:53 -070039 parser.add_option('-s',
40 dest='search', default=None,
41 help='search for specific tags')
Dennis Kempin19e972b2013-06-20 13:21:38 -070042 (options, args) = parser.parse_args()
43
44 stat = MTStat()
45 if options.download:
46 stat.Download(options.download, options.offset)
47 return
48
49 number = None if options.number is None else int(options.number)
Dennis Kempin6e03a432013-06-25 09:00:53 -070050
51 if options.search:
52 results = stat.Search(options.search, number)
53 print "Found occurences in %d files" % len(results)
54 print "Serving results, press CTRL-C to abort"
55 for filename, entries in results.items():
56 print "%d occurences in %s:" % (len(entries), filename)
57 for entry in entries:
58 print " %f" % entry.timestamp
59 first = entries[0]
60
61 replay_results = MTReplay().Replay(Log(first.id))
62 editor = MTEdit()
63 editor.View(replay_results.log, first.timestamp)
64 raw_input("Press Enter to continue...")
65 return
66
Dennis Kempin19e972b2013-06-20 13:21:38 -070067 results = stat.GatherStats(number)
Dennis Kempin6e03a432013-06-25 09:00:53 -070068 for key, (count, ratio) in results.items():
69 print key, '=', count, "(%d%%)" % (ratio * 100)
Dennis Kempin19e972b2013-06-20 13:21:38 -070070
71if __name__ == '__main__':
72 main()