Chromium Code Reviews| Index: tools/telemetry/telemetry/web_perf/metrics/blob_timeline.py |
| diff --git a/tools/telemetry/telemetry/web_perf/metrics/blob_timeline.py b/tools/telemetry/telemetry/web_perf/metrics/blob_timeline.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..af1d8fa1e75c6e1ce09b8ecca6c45eae5af17ba1 |
| --- /dev/null |
| +++ b/tools/telemetry/telemetry/web_perf/metrics/blob_timeline.py |
| @@ -0,0 +1,103 @@ |
| +# Copyryight 2015 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import sys |
| + |
| +from telemetry.value import list_of_scalar_values |
| +from telemetry.web_perf.metrics import timeline_based_metric |
| + |
| + |
| +WRITE_INTERACTION_LABEL = 'Action_CreateBlob' |
| +WRITE_EVENT_NAME = 'Registry::RegisterBlob' |
| +READ_INTERACTION_LABEL = 'Action_ReadBlobs' |
| +READ_EVENT_NAME = 'BlobRequest' |
| +WRITE_READ_INTERACTION_LABEL = 'BlobCreateAndRead' |
| + |
| + |
| +class BlobTimelineMetric(timeline_based_metric.TimelineBasedMetric): |
| + """BlobTimelineMetric reports timing information about blob storage. |
| + |
| + The following metrics are added to the results: |
| + * blob write times in the Action_CreateBlob interaction (blob_writes) |
| + * blob read time in the Action_ReadBlobs interaction (blob_reads) |
| + * BlobCreateAndRead interaction length, for measuring total time |
| + to write and then read a blob. (blob_write_reads) |
| + """ |
| + |
| + |
| + def __init__(self): |
| + super(BlobTimelineMetric, self).__init__() |
| + |
| + def AddResults(self, model, renderer_thread, interactions, results): |
| + assert interactions |
| + |
| + browser_process = [p for p in model.GetAllProcesses() |
| + if p.name == "Browser"][0] |
| + |
| + write_events = [] |
| + read_events = [] |
| + for event in renderer_thread.parent.IterAllEvents( |
| + event_predicate=(lambda e: e.name == WRITE_EVENT_NAME)): |
| + write_events.append(event) |
| + for event in browser_process.parent.IterAllEvents( |
| + event_predicate=(lambda e: e.name == READ_EVENT_NAME)): |
|
eakuefner
2015/05/28 20:36:56
this looks fine, but let it be known that _if_ you
dmurph
2015/05/29 05:05:47
Switched to static methods
|
| + read_events.append(event) |
| + |
| + self._AddWriteResultsInternal(write_events, interactions, results) |
| + self._AddReadResultsInternal(read_events, interactions, results) |
| + |
| + def _AddWriteResultsInternal(self, events, interactions, results): |
| + writes = [] |
| + write_then_reads = [] |
| + |
| + for interaction in interactions: |
| + if interaction.label == WRITE_READ_INTERACTION_LABEL: |
| + write_then_reads.append(interaction.end - interaction.start) |
|
nednguyen
2015/05/28 05:10:12
This is the wrong way of using timeline interactio
dmurph
2015/05/29 05:05:47
Based on external discussion, switched to using th
|
| + continue |
| + elif interaction.label != WRITE_INTERACTION_LABEL: |
| + continue |
| + for duration in [(e.end - e.start) for e in events |
| + if (interaction.start <= e.start <= interaction.end) and |
| + e.name == WRITE_EVENT_NAME]: |
| + writes.append(duration) |
|
nednguyen
2015/05/28 05:10:12
You can use e.thread_duration to make sure that yo
dmurph
2015/05/29 05:05:47
Done.
|
| + |
| + if writes: |
| + results.AddValue(list_of_scalar_values.ListOfScalarValues( |
| + page=results.current_page, |
| + name='blob_writes', |
| + units='ms', |
| + values=writes, |
| + description=('List of durations of blob writes.'))) |
| + if write_then_reads: |
| + results.AddValue(list_of_scalar_values.ListOfScalarValues( |
| + page=results.current_page, |
| + name='blob_write_reads', |
| + units='ms', |
| + values=write_then_reads, |
| + description=('List of times for blob creation then read.'))) |
| + |
| + |
| + def _AddReadResultsInternal(self, events, interactions, results): |
| + reads = [] |
| + |
| + for interaction in interactions: |
| + if interaction.label != READ_INTERACTION_LABEL: |
| + continue |
| + min_read_start = sys.maxint |
| + max_read_end = -sys.maxint - 1 |
| + for event in [e for e in events |
| + if (interaction.start <= e.start <= interaction.end) and |
| + e.name == READ_EVENT_NAME]: |
| + min_read_start = min(event.start, min_read_start) |
|
nednguyen
2015/05/28 05:10:12
why can we just use reads.append(e.thread_duration
dmurph
2015/05/29 05:05:47
Done.
|
| + max_read_end = max(event.end, max_read_end) |
| + if min_read_start != sys.maxint: |
| + reads.append(max_read_end - min_read_start) |
| + |
| + if reads: |
| + results.AddValue(list_of_scalar_values.ListOfScalarValues( |
| + page=results.current_page, |
| + name='blob_reads', |
| + units='ms', |
| + values=reads, |
| + description=('List of durations of blob part reads (not whole blob)'))) |