Dennis Kempin | 19e972b | 2013-06-20 13:21:38 -0700 | [diff] [blame] | 1 | #! /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 Kempin | 6e03a43 | 2013-06-25 09:00:53 -0700 | [diff] [blame^] | 6 | from mtedit import MTEdit |
| 7 | from mtlib import Log |
| 8 | from mtreplay import MTReplay |
Dennis Kempin | 19e972b | 2013-06-20 13:21:38 -0700 | [diff] [blame] | 9 | from mtstat import MTStat |
Dennis Kempin | 6e03a43 | 2013-06-25 09:00:53 -0700 | [diff] [blame^] | 10 | from optparse import OptionParser |
Dennis Kempin | 19e972b | 2013-06-20 13:21:38 -0700 | [diff] [blame] | 11 | |
| 12 | usage = """Multitouch Statistic Collector |
| 13 | |
| 14 | Download latest N feedback reports |
| 15 | $ %prog -d N |
Dennis Kempin | 6e03a43 | 2013-06-25 09:00:53 -0700 | [diff] [blame^] | 16 | |
| 17 | Run and print statistics |
| 18 | $ %prog |
| 19 | |
| 20 | Randomly select N logs and run |
| 21 | $ %prog -n N |
| 22 | |
| 23 | Search all (or -n N) logs for occurence of TAG and |
| 24 | serve the search results in MTEdit |
| 25 | $ %prog -s TAG |
Dennis Kempin | 19e972b | 2013-06-20 13:21:38 -0700 | [diff] [blame] | 26 | """ |
| 27 | |
| 28 | def 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 Kempin | 6e03a43 | 2013-06-25 09:00:53 -0700 | [diff] [blame^] | 39 | parser.add_option('-s', |
| 40 | dest='search', default=None, |
| 41 | help='search for specific tags') |
Dennis Kempin | 19e972b | 2013-06-20 13:21:38 -0700 | [diff] [blame] | 42 | (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 Kempin | 6e03a43 | 2013-06-25 09:00:53 -0700 | [diff] [blame^] | 50 | |
| 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 Kempin | 19e972b | 2013-06-20 13:21:38 -0700 | [diff] [blame] | 67 | results = stat.GatherStats(number) |
Dennis Kempin | 6e03a43 | 2013-06-25 09:00:53 -0700 | [diff] [blame^] | 68 | for key, (count, ratio) in results.items(): |
| 69 | print key, '=', count, "(%d%%)" % (ratio * 100) |
Dennis Kempin | 19e972b | 2013-06-20 13:21:38 -0700 | [diff] [blame] | 70 | |
| 71 | if __name__ == '__main__': |
| 72 | main() |