def DownloadJobResultsAsCsv(api, job_id, output_file): """Download the perf results of a job as a csv file.""" job = api.pinpoint.Job(job_id, with_state=True) # TODO: Make this also work for jobs that ran on windows platform. results_file = posixpath.join(job['arguments']['benchmark'], 'perf_results.json') print 'Fetching results for %s job %s:' % (job['status'].lower(), job_id) with open(output_file, 'wb') as f: writer = csv.writer(f) writer.writerow(('change', 'isolate') + histograms_df.COLUMNS) num_rows = 0 for change_id, isolate_hash in job_results.IterTestOutputIsolates(job): print '- isolate: %s ...' % isolate_hash histograms = api.isolate.RetrieveFile(isolate_hash, results_file) for row in histograms_df.IterRows(json.loads(histograms)): writer.writerow((change_id, isolate_hash) + row) num_rows += 1 print 'Wrote data from %d histograms in %s.' % (num_rows, output_file)
def testIterRows(self): run1 = { 'benchmarkStart': 1234567890000, 'labels': ['run1'], 'benchmarks': ['system_health'], 'deviceIds': ['device1'] } # Second run on same device ten minutes later. run2 = { 'benchmarkStart': 1234567890000 + 600000, 'labels': ['run2'], 'benchmarks': ['system_health'], 'deviceIds': ['device1'] } hists = histogram_set.HistogramSet([ TestHistogram('startup', 'ms', [8, 10, 12], stories=['story1'], traceUrls=['http://url/to/trace1'], **run1), TestHistogram('memory', 'sizeInBytes', [256], stories=['story2'], traceUrls=['http://url/to/trace2'], **run1), TestHistogram('memory', 'sizeInBytes', [512], stories=['story2'], traceUrls=['http://url/to/trace3'], **run2), ]) expected = [ ('startup', 'ms', 10.0, 2.0, 3, 'run1', 'system_health', 'story1', '2009-02-13 23:31:30', 'device1', 'http://url/to/trace1'), ('memory', 'sizeInBytes', 256.0, 0.0, 1, 'run1', 'system_health', 'story2', '2009-02-13 23:31:30', 'device1', 'http://url/to/trace2'), ('memory', 'sizeInBytes', 512.0, 0.0, 1, 'run2', 'system_health', 'story2', '2009-02-13 23:41:30', 'device1', 'http://url/to/trace3'), ] self.assertItemsEqual(histograms_df.IterRows(hists.AsDicts()), expected)
def DownloadJobResultsAsCsv(job_ids, only_differences, output_file): """Download the perf results of a job as a csv file.""" with open(output_file, 'wb') as f: writer = csv.writer(f) writer.writerow(('job_id', 'change', 'isolate') + histograms_df.COLUMNS) num_rows = 0 for job_id in job_ids: job = pinpoint_service.Job(job_id, with_state=True) os_path = _OsPathFromJob(job) results_file = os_path.join(job['arguments']['benchmark'], 'perf_results.json') print 'Fetching results for %s job %s:' % (job['status'].lower(), job_id) for change_id, isolate_hash in job_results.IterTestOutputIsolates( job, only_differences): print '- isolate: %s ...' % isolate_hash histograms = isolate_service.RetrieveFile( isolate_hash, results_file) for row in histograms_df.IterRows(json.loads(histograms)): writer.writerow((job_id, change_id, isolate_hash) + row) num_rows += 1 print 'Wrote data from %d histograms in %s.' % (num_rows, output_file)