1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
8 def IsTimelineInteractionRecord(event_name):
9 return event_name.startswith('Interaction.')
12 class TimelineInteractionRecord(object):
13 """Represents an interaction that took place during a timeline recording.
15 As a page runs, typically a number of different (simulated) user interactions
16 take place. For instance, a user might click a button in a mail app causing a
17 popup to animate in. Then they might press another button that sends data to a
18 server and simultaneously closes the popup without an animation. These are two
21 From the point of view of the page, each interaction might have a different
22 logical name: ClickComposeButton and SendEmail, for instance. From the point
23 of view of the benchmarking harness, the names aren't so interesting as what
24 the performance expectations are for that interaction: was it loading
25 resources from the network? was there an animation?
27 Determining these things is hard to do, simply by observing the state given to
28 a page from javascript. There are hints, for instance if network requests are
29 sent, or if a CSS animation is pending. But this is by no means a complete
32 Instead, we expect pages to mark up the timeline what they are doing, with
33 logical names, and flags indicating the semantics of that interaction. This
34 is currently done by pushing markers into the console.time/timeEnd API: this
35 for instance can be issued in JS:
37 var str = 'Interaction.SendEmail/is_smooth,is_loading_resources';
39 setTimeout(function() {
43 When run with perf.measurements.timeline_based_measurement running, this will
44 then cause a TimelineInteractionRecord to be created for this range and both
45 smoothness and network metrics to be reported for the marked up 1000ms
49 def __init__(self, logical_name, start, end):
51 self.logical_name = logical_name
54 self.is_smooth = False
55 self.is_loading_resources = False
59 m = re.match('Interaction\.(.+)\/(.+)', event.name)
61 logical_name = m.group(1)
63 flags = m.group(2).split(',')
67 m = re.match('Interaction\.(.+)', event.name)
69 logical_name = m.group(1)
72 record = TimelineInteractionRecord(logical_name, event.start, event.end)
74 if not f in ('is_smooth', 'is_loading_resources'):
76 'Unrecognized flag in timeline Interaction record: %s' % f)
77 record.is_smooth = 'is_smooth' in flags
78 record.is_loading_resources = 'is_loading_resources' in flags
81 def GetResultNameFor(self, result_name):
82 return "%s-%s" % (self.logical_name, result_name)