def FetchTimeseriesData(args): def _MatchesAllFilters(test_path): return all(f in test_path for f in args.filters) api = dashboard_api.PerfDashboardCommunicator(args) with tables.DbSession(args.database_file) as con: # Get test_paths. if args.benchmark is not None: api = dashboard_api.PerfDashboardCommunicator(args) test_paths = api.dashboard.ListTestPaths(args.benchmark, sheriff=args.sheriff) elif args.input_file is not None: test_paths = list(_ReadTestPathsFromFile(args.input_file)) elif args.study is not None: test_paths = list(args.study.IterTestPaths(api)) else: raise ValueError('No source for test paths specified') # Apply --filter's to test_paths. if args.filters: test_paths = filter(_MatchesAllFilters, test_paths) num_found = len(test_paths) print '%d test paths found!' % num_found # Filter out test_paths already in cache. if args.use_cache: test_paths = list(_IterStaleTestPaths(con, test_paths)) num_skipped = num_found - len(test_paths) if num_skipped: print '(skipping %d test paths already in the database)' % num_skipped # Use worker pool to fetch test path data. total_seconds = worker_pool.Run( 'Fetching data of %d timeseries: ' % len(test_paths), _FetchTimeseriesWorker, args, test_paths) print '[%.1f test paths per second]' % (len(test_paths) / total_seconds) if args.output_csv is not None: print print 'Post-processing data for study ...' dfs = [] with tables.DbSession(args.database_file) as con: for test_path in test_paths: df = tables.timeseries.GetTimeSeries(con, test_path) dfs.append(df) df = studies.PostProcess(pandas.concat(dfs, ignore_index=True)) with utils.OpenWrite(args.output_csv) as f: df.to_csv(f, index=False) print 'Wrote timeseries data to:', args.output_csv
def testGetMostRecentPoint_empty(self): test_path = ('ChromiumPerf/android-nexus5/loading.mobile' '/timeToFirstInteractive/PageSet/Google') with tables.DbSession(':memory:') as con: point = tables.timeseries.GetMostRecentPoint(con, test_path) self.assertIsNone(point)
def FetchAlertsData(args): api = dashboard_api.PerfDashboardCommunicator(args) with tables.DbSession(args.database_file) as con: # Get alerts. num_alerts = 0 bug_ids = set() # TODO: This loop may be slow when fetching thousands of alerts, needs a # better progress indicator. for data in api.IterAlertData(args.benchmark, args.sheriff, args.days): alerts = tables.alerts.DataFrameFromJson(data) pandas_sqlite.InsertOrReplaceRecords(con, 'alerts', alerts) num_alerts += len(alerts) bug_ids.update(alerts['bug_id'].unique()) print '%d alerts found!' % num_alerts # Get set of bugs associated with those alerts. bug_ids.discard(0) # A bug_id of 0 means untriaged. print '%d bugs found!' % len(bug_ids) # Filter out bugs already in cache. if args.use_cache: known_bugs = set(b for b in bug_ids if tables.bugs.Get(con, b) is not None) if known_bugs: print '(skipping %d bugs already in the database)' % len( known_bugs) bug_ids.difference_update(known_bugs) # Use worker pool to fetch bug data. total_seconds = worker_pool.Run( 'Fetching data of %d bugs: ' % len(bug_ids), _FetchBugsWorker, args, bug_ids) print '[%.1f bugs per second]' % (len(bug_ids) / total_seconds)
def testGetMostRecentPoint_success(self): test_path = ('ChromiumPerf/android-nexus5/loading.mobile' '/timeToFirstInteractive/PageSet/Google') data = { 'test_path': test_path, 'improvement_direction': 1, 'timeseries': [ [ 'revision', 'value', 'timestamp', 'r_commit_pos', 'r_chromium' ], [ 547397, 2300.3, '2018-04-01T14:16:32.000', '547397', 'adb123' ], [ 547398, 2750.9, '2018-04-01T18:24:04.000', '547398', 'cde456' ], [ 547423, 2342.2, '2018-04-02T02:19:00.000', '547423', 'fab789' ], ] } timeseries = tables.timeseries.DataFrameFromJson(data) with tables.DbSession(':memory:') as con: pandas_sqlite.InsertOrReplaceRecords(con, 'timeseries', timeseries) point = tables.timeseries.GetMostRecentPoint(con, test_path) self.assertEqual(point['point_id'], 547423)
def testGetTimeSeries_withSummaryMetric(self): test_path = tables.timeseries.Key(test_suite='loading.mobile', measurement='timeToFirstInteractive', bot='ChromiumPerf:android-nexus5', test_case='') data = { 'improvement_direction': 'down', 'units': 'ms', 'data': [ SamplePoint(547397, 2300.3), SamplePoint(547398, 2750.9), SamplePoint(547423, 2342.2), ] } timeseries_in = tables.timeseries.DataFrameFromJson(test_path, data) with tables.DbSession(':memory:') as con: pandas_sqlite.InsertOrReplaceRecords(con, 'timeseries', timeseries_in) timeseries_out = tables.timeseries.GetTimeSeries(con, test_path) # Both DataFrame's should be equal, except the one we get out of the db # does not have an index defined. timeseries_in = timeseries_in.reset_index() self.assertTrue(timeseries_in.equals(timeseries_out))
def testGetMostRecentPoint_empty(self): test_path = tables.timeseries.Key(test_suite='loading.mobile', measurement='timeToFirstInteractive', bot='ChromiumPerf:android-nexus5', test_case='Wikipedia') with tables.DbSession(':memory:') as con: point = tables.timeseries.GetMostRecentPoint(con, test_path) self.assertIsNone(point)
def testGetTimeSeries_withSummaryMetric(self): test_path = ( 'ChromiumPerf/android-nexus5/loading.mobile/timeToFirstInteractive' ) data = { 'test_path': test_path, 'improvement_direction': 1, 'timeseries': [ [ 'revision', 'value', 'timestamp', 'r_commit_pos', 'r_chromium' ], [ 547397, 2300.3, '2018-04-01T14:16:32.000', '547397', 'adb123' ], [ 547398, 2750.9, '2018-04-01T18:24:04.000', '547398', 'cde456' ], [ 547423, 2342.2, '2018-04-02T02:19:00.000', '547423', 'fab789' ], ] } timeseries_in = tables.timeseries.DataFrameFromJson(data) with tables.DbSession(':memory:') as con: pandas_sqlite.InsertOrReplaceRecords(con, 'timeseries', timeseries_in) timeseries_out = tables.timeseries.GetTimeSeries(con, test_path) print timeseries_out # Both DataFrame's should be equal, except the one we get out of the db # does not have an index defined. timeseries_in = timeseries_in.reset_index() self.assertTrue(timeseries_in.equals(timeseries_out))
def testGetMostRecentPoint_success(self): test_path = tables.timeseries.Key(test_suite='loading.mobile', measurement='timeToFirstInteractive', bot='ChromiumPerf:android-nexus5', test_case='Wikipedia') data = { 'improvement_direction': 'down', 'units': 'ms', 'data': [ SamplePoint(547397, 2300.3), SamplePoint(547398, 2750.9), SamplePoint(547423, 2342.2), ] } timeseries = tables.timeseries.DataFrameFromJson(test_path, data) with tables.DbSession(':memory:') as con: pandas_sqlite.InsertOrReplaceRecords(con, 'timeseries', timeseries) point = tables.timeseries.GetMostRecentPoint(con, test_path) self.assertEqual(point['point_id'], 547423)