Clean up systrace a bit.

Extract the various event definitions into a table instead of a
switch statement.

Add a --link-assets option to systrace.py to generate a trace.html
file that has the CSS and JS assets linked in rather than embedded,
which is useful for debugging purposes.

Fixed a bug in the tests for lineRE.

Bug: 6488845
Change-Id: I90634f7144fa0a050b911bb9854e5d5662dd6330
diff --git a/config.py b/config.py
new file mode 100755
index 0000000..9480678
--- /dev/null
+++ b/config.py
@@ -0,0 +1,47 @@
+#!/usr/bin/python
+
+#
+# Original input files in the source tree.
+#
+
+js_in_files = (
+  'init.js',
+  'src/shared/js/cr.js',
+  'src/shared/js/cr/event_target.js',
+  'src/shared/js/cr/ui.js',
+  'src/shared/js/cr/ui/focus_outline_manager.js',
+  'src/shared/js/cr/ui/tabs.js',
+  'src/shared/js/util.js',
+  'src/tracing/overlay.js',
+  'src/tracing/tracing_controller.js',
+  'src/tracing/timeline_model.js',
+  'src/tracing/linux_perf_importer.js',
+  'src/tracing/trace_event_importer.js',
+  'src/tracing/sorted_array_utils.js',
+  'src/tracing/measuring_stick.js',
+  'src/tracing/timeline.js',
+  'src/tracing/timeline_analysis.js',
+  'src/tracing/timeline_track.js',
+  'src/tracing/fast_rect_renderer.js',
+  'src/tracing/profiling_view.js',
+  'src/tracing/timeline_view.js',
+)
+
+css_in_files = (
+  'src/shared/css/tabs.css',
+  'src/shared/css/widgets.css',
+  'src/tracing/overlay.css',
+  'src/tracing/profiling_view.css',
+  'src/tracing/timeline_analysis.css',
+  'src/tracing/timeline_view.css',
+  'src/tracing/timeline.css',
+  'src/tracing/tracing_controller.css',
+)
+
+#
+# Compiled output files generated by update.py.
+#
+
+js_out_file = 'script.js'
+
+css_out_file = 'style.css'
diff --git a/script.js b/script.js
index 12130a2..20ad6ac 100644
--- a/script.js
+++ b/script.js
@@ -1,160 +1,160 @@
-function onLoad(){reload()}function reload(){if(linuxPerfData){var f=new tracing.TimelineModel;f.importEvents("[]",!0,[linuxPerfData]);var c=document.querySelector(".view");cr.ui.decorate(c,tracing.TimelineView);c.model=f;c.tabIndex=1;c.timeline.focusElement=c}}document.addEventListener("DOMContentLoaded",onLoad);var global=this;
-this.cr=function(){function f(b,d,g,a){var e=new cr.Event(d+"Change");e.propertyName=d;e.newValue=g;e.oldValue=a;b.dispatchEvent(e)}function c(b){return b.replace(/([A-Z])/g,"-$1").toLowerCase()}function a(d,a){switch(a){case b.JS:var g=d+"_";return function(){return this[g]};case b.ATTR:var e=c(d);return function(){return this.getAttribute(e)};case b.BOOL_ATTR:return e=c(d),function(){return this.hasAttribute(e)}}}function e(d,a,g){switch(a){case b.JS:var e=d+"_";return function(b){var a=this[e];
-b!==a&&(this[e]=b,g&&g.call(this,b,a),f(this,d,b,a))};case b.ATTR:var i=c(d);return function(b){var a=this[i];b!==a&&(void 0==b?this.removeAttribute(i):this.setAttribute(i,b),g&&g.call(this,b,a),f(this,d,b,a))};case b.BOOL_ATTR:return i=c(d),function(b){var a=this[i];b!==a&&(b?this.setAttribute(i,d):this.removeAttribute(i),g&&g.call(this,b,a),f(this,d,b,a))}}}function i(b,d,g){var a=cr.doc.createEvent("Event");a.initEvent(b,!!d,!!g);a.__proto__=global.Event.prototype;return a}var b={JS:"js",ATTR:"attr",
-BOOL_ATTR:"boolAttr"},d=1;return{addSingletonGetter:function(b){b.getInstance=function(){return b.instance_||(b.instance_=new b)}},createUid:function(){return d++},define:function(b,d){var a;a=b.split(".");for(var e=global,c;a.length&&(c=a.shift());)e=c in e?e[c]:e[c]={};a=e;var e=d(),h;for(h in e)(c=Object.getOwnPropertyDescriptor(e,h))&&Object.defineProperty(a,h,c)},defineProperty:function(d,c,g,i){"function"==typeof d&&(d=d.prototype);g=g||b.JS;d.__lookupGetter__(c)||d.__defineGetter__(c,a(c,g));
-d.__lookupSetter__(c)||d.__defineSetter__(c,e(c,g,i))},dispatchPropertyChange:f,dispatchSimpleEvent:function(b,d,a,e){d=new cr.Event(d,a,e);return b.dispatchEvent(d)},Event:i,getUid:function(b){return b.hasOwnProperty("uid")?b.uid:b.uid=d++},initialize:function(){if(global.document)i.prototype={__proto__:global.Event.prototype},cr.isMac=/Mac/.test(navigator.platform),cr.isWindows=/Win/.test(navigator.platform),cr.isChromeOS=/CrOS/.test(navigator.userAgent),cr.isLinux=/Linux/.test(navigator.userAgent),
-cr.isGTK=/GTK/.test(chrome.toolkit),cr.isViews=/views/.test(chrome.toolkit),cr.isTouchOptimized=!!chrome.touchOptimized,cr.isTouchOptimized&&doc.documentElement.setAttribute("touch-optimized","");else{var b=cr;Object.defineProperty(global,"cr",{get:function(){Object.defineProperty(global,"cr",{value:b});b.initialize();return b},configurable:!0})}},PropertyKind:b,get doc(){return document}}}();cr.initialize();cr.define("cr",function(){function f(){}f.prototype={addEventListener:function(c,a){this.listeners_||(this.listeners_=Object.create(null));if(c in this.listeners_){var e=this.listeners_[c];0>e.indexOf(a)&&e.push(a)}else this.listeners_[c]=[a]},removeEventListener:function(c,a){if(this.listeners_&&c in this.listeners_){var e=this.listeners_[c],i=e.indexOf(a);0<=i&&(1==e.length?delete this.listeners_[c]:e.splice(i,1))}},dispatchEvent:function(c){if(!this.listeners_)return!0;var a=this;c.__defineGetter__("target",
-function(){return a});c.preventDefault=function(){this.returnValue=!1};var e=c.type,i=0;if(e in this.listeners_)for(var e=this.listeners_[e].concat(),b=0,d;d=e[b];b++)i=d.handleEvent?i|!1===d.handleEvent.call(d,c):i|!1===d.call(this,c);return!i&&c.returnValue}};return{EventTarget:f}});cr.define("cr.ui",function(){function f(c,a){return(a&&a.ownerDocument?a.ownerDocument:cr.doc).createElement(c)}return{decorate:function(c,a){var e;e="string"==typeof c?cr.doc.querySelectorAll(c):[c];for(var i=0,b;b=e[i];i++)b instanceof a||a.decorate(b)},define:function(c){function a(b){var d=e(i,b);a.decorate(d);for(var c in b)d[c]=b[c];return d}var e,i;"function"==typeof c?(e=c,i=""):(e=f,i=c);a.decorate=function(b){b.__proto__=a.prototype;b.decorate()};return a},limitInputWidth:function(c,a,e){function i(){if(c.scrollWidth>
-k)c.style.width=k+"px";else{c.style.width=0;var b=c.scrollWidth;c.style.width=b<e?e+"px":b+"px"}}c.style.width="10px";var b=c.ownerDocument.defaultView,d=b.getComputedStyle(c),b=b.getComputedStyle(a),j="rtl"==d.direction,f=c.getBoundingClientRect(),g=a.getBoundingClientRect(),f=j?g.right-f.right:f.left-g.left,d=parseInt(d.borderLeftWidth,10)+parseInt(d.paddingLeft,10)+parseInt(d.paddingRight,10)+parseInt(d.borderRightWidth,10),b=j?parseInt(b.paddingLeft,10):parseInt(b.paddingRight,10),k=a.clientWidth-
-f-d-b;c.addEventListener("input",i);i()}}});cr.define("cr.ui",function(){function f(a){this.classList_=a.documentElement.classList;var e=this;a.addEventListener("keydown",function(a){9==a.keyCode&&(e.visible=!0)},!0);a.addEventListener("mousedown",function(){e.visible=!1},!0)}f.prototype={set visible(a){a?this.classList_.add("focus-outline-visible"):this.classList_.remove("focus-outline-visible")},get visible(){this.classList_.contains("focus-outline-visible")}};var c=[];f.forDocument=function(a){for(var e=0;e<c.length;e++)if(a==c[e][0])return c[e][1];
-e=new f(a);c.push([a,e]);return e};return{FocusOutlineManager:f}});cr.define("cr.ui",function(){function f(){for(var d={TABBOX:c,TABS:a,TAB:e,TABPANELS:i,TABPANEL:b},j,f=0;j=this.children[f];f++){var g=d[j.tagName];g&&cr.ui.decorate(j,g)}}var c=cr.ui.define("tabbox");c.prototype={__proto__:HTMLElement.prototype,decorate:function(){f.call(this);this.addEventListener("selectedChange",this.handleSelectedChange_,!0);this.selectedIndex=0},handleSelectedChange_:function(b){var a=b.target;b.newValue&&(a.parentElement&&a.parentElement.parentElement)==this&&(this.selectedIndex=
-Array.prototype.indexOf.call(a.parentElement.children,a))},selectedIndex_:-1};cr.defineProperty(c,"selectedIndex",cr.PropertyKind.JS_PROP,function(b){for(var a,e,g=0;a=this.children[g];g++)for(var c=0;e=a.children[c];c++)e.selected=c==b});var a=cr.ui.define("tabs");a.prototype={__proto__:HTMLElement.prototype,decorate:function(){f.call(this);this.tabIndex=0;this.addEventListener("keydown",this.handleKeyDown_.bind(this));this.focusOutlineManager_=cr.ui.FocusOutlineManager.forDocument(this.ownerDocument)},
-handleKeyDown_:function(b){var a=0;switch(b.keyIdentifier){case "Left":case "Up":a=-1;break;case "Right":case "Down":a=1}a&&("rtl"==this.ownerDocument.defaultView.getComputedStyle(this).direction&&(a*=-1),b=this.children.length,this.parentElement.selectedIndex=(this.parentElement.selectedIndex+a+b)%b,this.focusOutlineManager_.visible=!0)}};var e=cr.ui.define("tab");e.prototype={__proto__:HTMLElement.prototype,decorate:function(){var b=this;this.addEventListener(cr.isMac?"click":"mousedown",function(){b.selected=
-!0})}};cr.defineProperty(e,"selected",cr.PropertyKind.BOOL_ATTR);var i=cr.ui.define("tabpanels");i.prototype={__proto__:HTMLElement.prototype,decorate:f};var b=cr.ui.define("tabpanel");b.prototype={__proto__:HTMLElement.prototype,decorate:function(){}};cr.defineProperty(b,"selected",cr.PropertyKind.BOOL_ATTR);return{TabBox:c,Tabs:a,Tab:e,TabPanels:i,TabPanel:b}});global=this;function $(f){return document.getElementById(f)}function chromeSend(f,c,a,e){var i=global[a];global[a]=function(){global[a]=i;var b=Array.prototype.slice.call(arguments);return e.apply(global,b)};chrome.send(f,c)}function url(f){f=f.replace(/(\(|\)|\,|\s|\'|\"|\\)/g,"\\$1");/\\\\$/.test(f)&&(f+=" ");return'url("'+f+'")'}function parseQueryParams(f){for(var c={},f=unescape(f.search.substring(1)).split("&"),a=0;a<f.length;a++){var e=f[a].split("=");c[e[0]]=e[1]}return c}
-function findAncestorByClass(f,c){return findAncestor(f,function(a){return a.classList?a.classList.contains(c):null})}function findAncestor(f,c){for(var a=!1;null!=f&&!(a=c(f));)f=f.parentNode;return a?f:null}function swapDomNodes(f,c){var a=f.nextSibling;if(a==c)swapDomNodes(c,f);else{var e=f.parentNode;c.parentNode.replaceChild(f,c);e.insertBefore(c,a)}}
-function disableTextSelectAndDrag(){document.onselectstart=function(f){f.preventDefault()};document.ondragstart=function(f){f.preventDefault()}}function isRTL(){return"rtl"==document.documentElement.dir}function assert(f,c){if(!f){var a="Assertion failed";c&&(a=a+": "+c);throw Error(a);}}function getRequiredElement(f){var c=$(f);assert(c,"Missing required element: "+f);return c}
-document.addEventListener("click",function(f){if(f.returnValue){var c=f.target;if(c.nodeType==Node.ELEMENT_NODE&&c.webkitMatchesSelector("A, A *")){for(;"A"!=c.tagName;)c=c.parentElement;if(("file:"==c.protocol||"about:"==c.protocol)&&(0==f.button||1==f.button))chrome.send("navigateToUrl",[c.href,c.target,f.button,f.altKey,f.ctrlKey,f.metaKey,f.shiftKey]),f.preventDefault()}}});function appendParam(f,c,a){c=encodeURIComponent(c)+"="+encodeURIComponent(a);return-1==f.indexOf("?")?f+"?"+c:f+"&"+c};cr.define("tracing",function(){var f=cr.ui.define("div");f.prototype={__proto__:HTMLDivElement.prototype,decorate:function(){this.classList.add("overlay-root");this.visible=!1;this.contentHost=this.ownerDocument.createElement("div");this.contentHost.classList.add("content-host");this.tabCatcher=this.ownerDocument.createElement("span");this.tabCatcher.tabIndex=0;this.appendChild(this.contentHost);this.onKeydownBoundToThis_=this.onKeydown_.bind(this);this.onFocusInBoundToThis_=this.onFocusIn_.bind(this);
-this.addEventListener("mousedown",this.onMousedown_.bind(this))},showOverlay:function(a){a.oldParent_=a.parentNode;this.contentHost.appendChild(a);this.contentHost.appendChild(this.tabCatcher);this.ownerDocument.body.classList.add("disabled-by-overlay");this.visible=!0;a.tabIndex=0;var e=a.querySelector("button, input, list, select, a");e||(e=a);e.focus();this.ownerDocument.addEventListener("focusin",this.onFocusInBoundToThis_,!0);a.addEventListener("keydown",this.onKeydownBoundToThis_)},onMousedown_:function(a){a.target==
-this&&a.preventDefault()},onFocusIn_:function(a){a.target==this.tabCatcher&&window.setTimeout(this.focusOverlay_.bind(this),0)},focusOverlay_:function(){this.contentHost.firstChild.focus()},onKeydown_:function(a){9==a.keyCode&&(a.shiftKey&&a.target==this.contentHost.firstChild)&&a.preventDefault()},hideOverlay:function(a){this.visible=!1;this.ownerDocument.body.classList.remove("disabled-by-overlay");this.lastFocusOut_=void 0;a.parentNode.removeChild(this.tabCatcher);a.oldParent_?(a.oldParent_.appendChild(a),
-delete a.oldParent_):this.contentHost.removeChild(a);a.removeEventListener("keydown",this.onKeydownBoundToThis_);this.ownerDocument.removeEventListener("focusin",this.onFocusInBoundToThis_)}};cr.defineProperty(f,"visible",cr.PropertyKind.BOOL_ATTR);var c=cr.ui.define("div");c.prototype={__proto__:HTMLDivElement.prototype,decorate:function(){if(!this.ownerDocument.querySelector(".overlay-root")){var a=this.ownerDocument.createElement("div");cr.ui.decorate(a,f);this.ownerDocument.body.appendChild(a)}this.classList.add("overlay");
-this.visible=!1},onVisibleChanged_:function(){var a=this.ownerDocument.querySelector(".overlay-root");this.visible?a.showOverlay(this):a.hideOverlay(this)}};cr.defineProperty(c,"visible",cr.PropertyKind.BOOL_ATTR,c.prototype.onVisibleChanged_);return{Overlay:c}});cr.define("tracing",function(){function f(){this.overlay_=document.createElement("div");this.overlay_.className="tracing-overlay";cr.ui.decorate(this.overlay_,tracing.Overlay);this.statusDiv_=document.createElement("div");this.overlay_.appendChild(this.statusDiv_);this.bufferPercentDiv_=document.createElement("div");this.overlay_.appendChild(this.bufferPercentDiv_);this.stopButton_=document.createElement("button");this.stopButton_.onclick=this.endTracing.bind(this);this.stopButton_.textContent="Stop tracing";
-this.overlay_.appendChild(this.stopButton_);this.traceEvents_=[];this.systemTraceEvents_=[];this.onKeydownBoundToThis_=this.onKeydown_.bind(this);this.onKeypressBoundToThis_=this.onKeypress_.bind(this);chrome.send("tracingControllerInitialized")}f.prototype={__proto__:cr.EventTarget.prototype,gpuInfo_:void 0,clientInfo_:void 0,tracingEnabled_:!1,tracingEnding_:!1,systemTraceDataFilename_:void 0,onRequestBufferPercentFullComplete:function(c){this.overlay_.visible&&(window.setTimeout(this.beginRequestBufferPercentFull_.bind(this),
-250),this.bufferPercentDiv_.textContent="Buffer usage: "+Math.round(100*c)+"%")},beginRequestBufferPercentFull_:function(){chrome.send("beginRequestBufferPercentFull")},beginTracing:function(c){if(this.tracingEnabled_)throw Error("Tracing already begun.");this.stopButton_.hidden=!1;this.statusDiv_.textContent="Tracing active.";this.tracingEnabled_=this.overlay_.visible=!0;console.log("Beginning to trace...");this.statusDiv_.textContent="Tracing active.";this.traceEvents_=[];this.systemTraceEvents_=
-[];chrome.send("beginTracing",[c||!1]);this.beginRequestBufferPercentFull_();c=new cr.Event("traceBegun");c.events=this.traceEvents_;this.dispatchEvent(c);c=new cr.Event("traceEventsChanged");c.numEvents=this.traceEvents_.length;this.dispatchEvent(c);window.addEventListener("keypress",this.onKeypressBoundToThis_);window.addEventListener("keydown",this.onKeydownBoundToThis_)},onKeydown_:function(c){27==c.keyCode&&this.endTracing()},onKeypress_:function(c){"Enter"==c.keyIdentifier&&this.endTracing()},
-onClientInfoUpdate:function(c){this.clientInfo_=c},onGpuInfoUpdate:function(c){this.gpuInfo_=c},get isTracingEnabled(){return this.tracingEnabled_},get traceEvents(){return this.traceEvents_},onTraceDataCollected:function(c){this.statusDiv_.textContent="Processing trace...";this.traceEvents_.push.apply(this.traceEvents_,c)},endTracing:function(){if(!this.tracingEnabled_)throw Error("Tracing not begun.");this.tracingEnding_||(this.tracingEnding_=!0,this.statusDiv_.textContent="Ending trace...",console.log("Finishing trace"),
-this.statusDiv_.textContent="Downloading trace data...",this.stopButton_.hidden=!0,window.setTimeout(function(){chrome.send("endTracingAsync")},100))},onEndTracingComplete:function(){window.removeEventListener("keydown",this.onKeydownBoundToThis_);window.removeEventListener("keypress",this.onKeypressBoundToThis_);this.tracingEnding_=this.tracingEnabled_=this.overlay_.visible=!1;console.log("onEndTracingComplete p1 with "+this.traceEvents_.length+" events.");var c=new cr.Event("traceEnded");c.events=
-this.traceEvents_;this.dispatchEvent(c)},onSystemTraceDataCollected:function(c){console.log("onSystemTraceDataCollected with "+c.length+" chars of data.");this.systemTraceEvents_=c},get systemTraceEvents(){return this.systemTraceEvents_},beginLoadTraceFile:function(){chrome.send("loadTraceFile")},onLoadTraceFileComplete:function(c){c.traceEvents?this.traceEvents_=c.traceEvents:c.length?this.traceEvents_=c:console.log("Expected an array when loading the trace file");c.systemTraceEvents?this.systemTraceEvents_=
-c.systemTraceEvents:c.length?this.systemTraceEvents_=c:console.log("Expected an array when loading the trace file");c=new cr.Event("loadTraceFileComplete");c.events=this.traceEvents_;this.dispatchEvent(c)},onLoadTraceFileCanceled:function(){cr.dispatchSimpleEvent(this,"loadTraceFileCanceled")},beginSaveTraceFile:function(){chrome.send("saveTraceFile",[JSON.stringify({traceEvents:this.traceEvents_,systemTraceEvents:this.systemTraceEvents_,clientInfo:this.clientInfo_,gpuInfo:this.gpuInfo_})])},onSaveTraceFileComplete:function(){cr.dispatchSimpleEvent(this,
-"saveTraceFileComplete")},onSaveTraceFileCanceled:function(){cr.dispatchSimpleEvent(this,"saveTraceFileCanceled")},selfTest:function(){this.beginTracing();window.setTimeout(this.endTracing.bind(This),500)}};return{TracingController:f}});cr.define("tracing",function(){function f(b,a,d,g,e){this.title=b;this.start=d;this.colorId=a;this.args=g;this.didNotFinish=!1;void 0!==e&&(this.duration=e)}function c(b,a,d,g,e){f.call(this,b,a,d,g,e);this.subSlices=[]}function a(b,a,d,g){f.call(this,b,a,d,g)}function e(b,a){if(!b)throw"Parent must be provided.";this.parent=b;this.tid=a;this.subRows=[[]];this.asyncSlices=new j(this.ptid)}function i(b,a,d){this.parent=b;this.id=a;this.name=d;this.seriesNames=[];this.seriesColors=[];this.timestamps=
-[];this.samples=[]}function b(b){this.pid=b;this.threads={};this.counters={}}function d(b){this.cpuNumber=b;this.slices=[];this.counters={}}function j(b){this.name=b;this.slices=[]}function o(b){for(var a=0,d=0;d<b.length;++d)a=(a+37*a+11*b.charCodeAt(d))%4294967295;return a}function g(b,a){this.cpus={};this.processes={};this.importErrors=[];this.asyncSliceGroups={};b&&this.importEvents(b,a)}function k(){}function m(b){this.text_=b}f.prototype={selected:!1,duration:void 0,get end(){return this.start+
-this.duration}};c.prototype={__proto__:f.prototype};a.prototype={__proto__:f.prototype,id:void 0,startThread:void 0,endThread:void 0,subSlices:void 0};var h={};e.getPTIDFromPidAndTid=function(b,a){h[b]||(h[b]={});h[b][a]||(h[b][a]=b+":"+a);return h[b][a]};e.prototype={name:void 0,get ptid(){return e.getPTIDFromPidAndTid(this.tid,this.parent.pid)},getSubrow:function(b){for(;b>=this.subRows.length;)this.subRows.push([]);return this.subRows[b]},shiftSubRow_:function(b,a){for(var d=0;d<b.length;d++){var g=
-b[d];g.start+=a}},shiftTimestampsForward:function(b){this.cpuSlices&&this.shiftSubRow_(this.cpuSlices,b);for(var a=0;a<this.subRows.length;a++)this.shiftSubRow_(this.subRows[a],b);this.asyncSlices.shiftTimestampsForward(b)},updateBounds:function(){var b=[],a;0!=this.subRows[0].length&&(a=this.subRows[0],b.push(a[0].start),b.push(a[a.length-1].end));this.asyncSlices.slices.length&&(this.asyncSlices.updateBounds(),b.push(this.asyncSlices.minTimestamp),b.push(this.asyncSlices.maxTimestamp));b.length?
-(this.minTimestamp=Math.min.apply(Math,b),this.maxTimestamp=Math.max.apply(Math,b)):this.maxTimestamp=this.minTimestamp=void 0},get userFriendlyName(){return this.parent.pid+": "+(this.name||this.tid)},get userFriendlyDetails(){return"pid: "+this.parent.pid+", tid: "+this.tid+(this.name?", name: "+this.name:"")}};e.compare=function(a,d){if(a.parent.pid!=d.parent.pid)return b.compare(a.parent,d.parent.pid);if(a.name&&d.name){var g=a.name.localeCompare(d.name);return 0==g?a.tid-d.tid:g}return a.name?
--1:d.name?1:a.tid-d.tid};i.prototype={__proto__:Object.prototype,get numSeries(){return this.seriesNames.length},get numSamples(){return this.timestamps.length},shiftTimestampsForward:function(b){for(var a=0;a<this.timestamps.length;a++)this.timestamps[a]+=b},updateBounds:function(){if(this.seriesNames.length!=this.seriesColors.length)throw"seriesNames.length must match seriesColors.length";if(this.numSeries*this.numSamples!=this.samples.length)throw"samples.length must be a multiple of numSamples.";
-this.totals=[];if(0==this.samples.length)this.maxTimestamp=this.minTimestamp=void 0,this.maxTotal=0;else{this.minTimestamp=this.timestamps[0];this.maxTimestamp=this.timestamps[this.timestamps.length-1];for(var b=this.numSeries,a=-Infinity,d=0;d<this.timestamps.length;d++){for(var g=0,e=0;e<b;e++)g+=this.samples[d*b+e],this.totals.push(g);g>a&&(a=g)}this.maxTotal=a}}};i.compare=function(a,d){if(a.parent.pid!=d.parent.pid)return b.compare(a.parent,d.parent.pid);var g=a.name.localeCompare(d.name);return 0==
-g?a.tid-d.tid:g};b.prototype={get numThreads(){var b=0,a;for(a in this.threads)b++;return b},shiftTimestampsForward:function(b){for(var a in this.threads)this.threads[a].shiftTimestampsForward(b);for(var d in this.counters)this.counters[d].shiftTimestampsForward(b)},getOrCreateThread:function(b){this.threads[b]||(this.threads[b]=new e(this,b));return this.threads[b]},getOrCreateCounter:function(b,a){var d=b+"."+a;this.counters[d]||(this.counters[d]=new i(this,d,a));return this.counters[d]}};b.compare=
-function(b,a){return b.pid-a.pid};d.prototype={getOrCreateCounter:function(b,a){var d;d=b.length?b+"."+a:a;this.counters[d]||(this.counters[d]=new i(this,d,a));return this.counters[d]},shiftTimestampsForward:function(b){for(var a=0;a<this.slices.length;a++)this.slices[a].start+=b;for(var d in this.counters)this.counters[d].shiftTimestampsForward(b)},updateBounds:function(){this.slices.length?(this.minTimestamp=this.slices[0].start,this.maxTimestamp=this.slices[this.slices.length-1].end):this.maxTimestamp=
-this.minTimestamp=void 0}};d.compare=function(b,a){return b.cpuNumber-a.cpuNumber};j.prototype={__proto__:Object.prototype,push:function(b){this.slices.push(b)},get length(){return this.slices.length},subRows_:void 0,sortSlices_:function(){this.slices.sort(function(b,a){return b.start-a.start})},shiftTimestampsForward:function(b){for(var a=0;a<this.slices.length;a++){var d=this.slices[a];d.start+=b;for(var g=0;g<d.subSlices.length;g++)d.subSlices[g].start+=b}},updateBounds:function(){this.sortSlices_();
-this.slices.length?(this.minTimestamp=this.slices[0].start,this.maxTimestamp=this.slices[this.slices.length-1].end):this.maxTimestamp=this.minTimestamp=void 0;this.subRows_=void 0},get subRows(){this.subRows_||this.rebuildSubRows_();return this.subRows_},rebuildSubRows_:function(){this.sortSlices_();for(var b=[],a=0;a<this.slices.length;a++){for(var d=this.slices[a],g=!1,e=0;e<b.length;e++){var c=b[e];if(d.start>=c[c.length-1].end){g=!0;if(void 0===d.subSlices||1>d.subSlices.length)throw"TimelineAsyncEvent missing subSlices: "+
-d.name;for(e=0;e<d.subSlices.length;e++)c.push(d.subSlices[e]);break}}if(!g&&(c=[],void 0!==d.subSlices)){for(e=0;e<d.subSlices.length;e++)c.push(d.subSlices[e]);b.push(c)}}this.subRows_=b},computeSubGroups:function(){for(var b={},a=0;a<this.slices.length;++a){var d=this.slices[a],g=d.startThread.ptid;b[g]||(b[g]=new j(this.name));b[g].slices.push(d)}var a=[],e;for(e in b)d=b[e],d.updateBounds(),a.push(d);return a}};i.compare=function(a,d){if(a.parent.pid!=d.parent.pid)return b.compare(a.parent,d.parent.pid);
-var g=a.name.localeCompare(d.name);return 0==g?a.tid-d.tid:g};var l=[{r:138,g:113,b:152},{r:175,g:112,b:133},{r:127,g:135,b:225},{r:93,g:81,b:137},{r:116,g:143,b:119},{r:178,g:214,b:122},{r:87,g:109,b:147},{r:119,g:155,b:95},{r:114,g:180,b:160},{r:132,g:85,b:103},{r:157,g:210,b:150},{r:148,g:94,b:86},{r:164,g:108,b:138},{r:139,g:191,b:150},{r:110,g:99,b:145},{r:80,g:129,b:109},{r:125,g:140,b:149},{r:93,g:124,b:132},{r:140,g:85,b:140},{r:104,g:163,b:162},{r:132,g:141,b:178},{r:131,g:105,b:147},{r:135,
-g:183,b:98},{r:152,g:134,b:177},{r:141,g:188,b:141},{r:133,g:160,b:210},{r:126,g:186,b:148},{r:112,g:198,b:205},{r:180,g:122,b:195},{r:203,g:144,b:152},{r:182,g:125,b:143},{r:126,g:200,b:148},{r:133,g:160,b:210},{r:240,g:240,b:240}],q=l.length-4,r=l.length,v=l.concat(l.map(function(b){var a;a=240<=b.r&&240<=b.g&&240<=b.b?-0.2:0.45;return{r:Math.min(255,b.r+Math.floor(b.r*a)),g:Math.min(255,b.g+Math.floor(b.g*a)),b:Math.min(255,b.b+Math.floor(b.b*a))}})).map(function(b){return"rgb("+b.r+","+b.g+","+
-b.b+")"}),u={},y=[];g.registerImporter=function(b){y.push(b)};k.canImport=function(b){return b instanceof Array&&0==b.length?!0:"string"===typeof b||b instanceof String?0==b.length:!1};k.prototype={__proto__:Object.prototype,importEvents:function(){},finalizeImport:function(){}};g.registerImporter(k);g.prototype={__proto__:cr.EventTarget.prototype,get numProcesses(){var b=0,a;for(a in this.processes)b++;return b},getOrCreateCpu:function(b){this.cpus[b]||(this.cpus[b]=new d(b));return this.cpus[b]},
-getOrCreateProcess:function(a){this.processes[a]||(this.processes[a]=new b(a));return this.processes[a]},pruneEmptyThreads:function(){for(var b in this.processes){var a=this.processes[b],d={},g;for(g in a.threads){for(var e=a.threads[g],c=!1,q=0;q<e.subRows.length;q++)c|=0<e.subRows[q].length;if(c||0<e.asyncSlices.length)d[g]=e}a.threads=d}},updateBounds:function(){for(var b=Infinity,a=-b,d=!1,g=this.getAllThreads(),e=0;e<g.length;e++){var c=g[e];c.updateBounds();void 0!=c.minTimestamp&&void 0!=c.maxTimestamp&&
-(b=Math.min(b,c.minTimestamp),a=Math.max(a,c.maxTimestamp),d=!0)}g=this.getAllCounters();for(e=0;e<g.length;e++)c=g[e],c.updateBounds(),void 0!=c.minTimestamp&&void 0!=c.maxTimestamp&&(d=!0,b=Math.min(b,c.minTimestamp),a=Math.max(a,c.maxTimestamp));for(var q in this.cpus)e=this.cpus[q],e.updateBounds(),void 0!=e.minTimestamp&&void 0!=e.maxTimestamp&&(d=!0,b=Math.min(b,e.minTimestamp),a=Math.max(a,e.maxTimestamp));d?(this.minTimestamp=b,this.maxTimestamp=a):this.minTimestamp=this.maxTimestamp=void 0},
-shiftWorldToZero:function(){if(void 0!==this.minTimestamp){var b=this.minTimestamp,a;for(a in this.processes)this.processes[a].shiftTimestampsForward(-b);for(var d in this.cpus)this.cpus[d].shiftTimestampsForward(-b);this.updateBounds()}},getAllThreads:function(){var b=[],a;for(a in this.processes){var d=this.processes[a],g;for(g in d.threads)b.push(d.threads[g])}return b},getAllCpus:function(){var b=[],a;for(a in this.cpus)b.push(this.cpus[a]);return b},getAllProcesses:function(){var b=[],a;for(a in this.processes)b.push(this.processes[a]);
-return b},getAllCounters:function(){var b=[],a;for(a in this.processes){var d=this.processes[a],g;for(g in d.counters)b.push(d.counters[g])}for(var e in this.cpus){a=this.cpus[e];for(var c in a.counters)b.push(a.counters[c])}return b},importOneTrace_:function(b,a){for(var d,g=0;g<y.length;++g)if(y[g].canImport(b)){d=y[g];break}if(!d)throw"Could not find an importer for the provided eventData.";d=new d(this,b,a);d.importEvents();return d},importEvents:function(b,a,d){void 0===a&&(a=!0);var g=[],b=
-this.importOneTrace_(b,!1);g.push(b);if(d)for(var e=0;e<d.length;++e)b=this.importOneTrace_(d[e],!0),g.push(b);for(e=0;e<g.length;++e)g[e].finalizeImport();for(e=0;e<g.length;++e)this.pruneEmptyThreads();this.updateBounds();a&&this.shiftWorldToZero();a&&(void 0!==this.minTimestamp&&void 0!==this.maxTimestamp)&&(a=0.15*(this.maxTimestamp-this.minTimestamp),this.minTimestamp-=a,this.maxTimestamp+=a)}};m.prototype={__proto__:Object.prototype,matchSlice:function(b){return 0==this.text_.length?!1:-1!=
-b.title.indexOf(this.text_)}};return{getPallette:function(){return v},getPalletteHighlightIdBoost:function(){return r},getColorIdByName:function(b){if("iowait"==b)return q;if("running"==b)return q+1;if("runnable"==b)return q+2;if("sleeping"==b)return q+3;throw"Unrecognized color "+b;},getStringHash:o,getStringColorId:function(b){if(void 0===u[b]){var a=o(b);u[b]=a%q}return u[b]},TimelineSlice:f,TimelineThreadSlice:c,TimelineAsyncSlice:a,TimelineThread:e,TimelineCounter:i,TimelineProcess:b,TimelineCpu:d,
-TimelineAsyncSliceGroup:j,TimelineModel:g,TimelineFilter:m}});cr.define("tracing",function(){function f(b){this.cpu=b}function c(){this.openSlices=[]}function a(b,a,d){this.isAdditionalImport_=d;this.model_=b;this.events_=a;this.clockSyncRecords_=[];this.cpuStates_={};this.kernelThreadStates_={};this.buildMapFromLinuxPidsToTimelineThreads();this.lineNumber=-1;this.threadStateByKPID_={}}f.prototype={__proto__:Object.prototype,switchRunningLinuxPid:function(b,a,d,e,c,q){if(void 0!==this.lastActivePid&&0!=this.lastActivePid){var j=d-this.lastActiveTs;name=(b=b.threadsByLinuxPid[this.lastActivePid])?
-b.userFriendlyName:this.lastActiveComm;this.cpu.slices.push(new tracing.TimelineSlice(name,tracing.getStringColorId(name),this.lastActiveTs,{comm:this.lastActiveComm,tid:this.lastActivePid,prio:this.lastActivePrio,stateWhenDescheduled:a},j))}this.lastActiveTs=d;this.lastActivePid=e;this.lastActiveComm=c;this.lastActivePrio=q}};TestExports={};var e=/^\s*(.+?)\s+\[(\d+)\]\s*([d.][N.][sh.][\d.])?\s*(\d+\.\d+):\s+(\S+):\s(.*)$/;TestExports.lineRE=e;var i=RegExp("prev_comm=(.+) prev_pid=(\\d+) prev_prio=(\\d+) prev_state=(\\S+) ==> next_comm=(.+) next_pid=(\\d+) next_prio=(\\d+)");
-TestExports.schedSwitchRE=i;var b=/comm=(.+) pid=(\d+) prio=(\d+) success=(\d+) target_cpu=(\d+)/;TestExports.schedWakeupRE=b;var d=/trace_event_clock_sync: parent_ts=(\d+\.?\d*)/;TestExports.traceEventClockSyncRE=d;var j=/work struct (.+): function (\S+)/,o=/work struct (.+)/;a.canImport=function(b){if(!("string"===typeof b||b instanceof String))return!1;if(/^# tracer:/.exec(b))return!0;var a=/^(.+)\n/.exec(b);a&&(b=a[1]);return e.exec(b)?!0:!1};a.prototype={__proto__:Object.prototype,buildMapFromLinuxPidsToTimelineThreads:function(){this.threadsByLinuxPid=
-{};this.model_.getAllThreads().forEach(function(b){this.threadsByLinuxPid[b.tid]=b}.bind(this))},getOrCreateCpuState:function(b){if(!this.cpuStates_[b]){var a=this.model_.getOrCreateCpu(b);this.cpuStates_[b]=new f(a)}return this.cpuStates_[b]},parsePid:function(b){b=/.+-(\d+)/.exec(b)[1];return b=parseInt(b)},parseThreadName:function(b){return/(.+)-\d+/.exec(b)[1]},getOrCreateKernelThread:function(b,a,d){this.kernelThreadStates_[b]||(void 0==a&&(a=this.parsePid(b)),void 0==d&&(d=a),d=this.model_.getOrCreateProcess(a).getOrCreateThread(d),
-d.name=b,this.kernelThreadStates_[b]={pid:a,thread:d,openSlice:void 0,openSliceTS:void 0},this.threadsByLinuxPid[a]=d);return this.kernelThreadStates_[b]},importEvents:function(){this.importCpuData();this.alignClocks()&&this.buildPerThreadCpuSlicesFromCpuState()},finalizeImport:function(){},buildPerThreadCpuSlicesFromCpuState:function(){for(var b in this.cpuStates_)for(var a=this.cpuStates_[b].cpu,d=0;d<a.slices.length;d++){var e=a.slices[d],c=this.threadsByLinuxPid[e.args.tid];c&&(c.tempCpuSlices||
-(c.tempCpuSlices=[]),e.index=d,c.tempCpuSlices.push(e))}var q=tracing.getColorIdByName("running"),j=tracing.getColorIdByName("runnable"),i=tracing.getColorIdByName("sleeping"),f=tracing.getColorIdByName("iowait");this.model_.getAllThreads().forEach(function(b){if(b.tempCpuSlices){var a=b.tempCpuSlices;delete b.tempCpuSlices;a.sort(function(b,a){var d=b.start-a.start;return 0==d?b.index-a.index:d});var d=[];if(a.length){var e=a[0];d.push(new tracing.TimelineSlice("Running",q,e.start,{},e.duration))}for(e=
-1;e<a.length;e++){var g=a[e-1],c=a[e],h=c.start-g.end;if("S"==g.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Sleeping",i,g.end,{},h));else if("R"==g.args.stateWhenDescheduled||"R+"==g.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Runnable",j,g.end,{},h));else if("D"==g.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Uninterruptible Sleep",f,g.end,{},h));else if("T"==g.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("__TASK_STOPPED",f,g.end,{},h));
-else if("t"==g.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("debug",f,g.end,{},h));else if("Z"==g.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Zombie",f,g.end,{},h));else if("X"==g.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Exit Dead",f,g.end,{},h));else if("x"==g.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Task Dead",f,g.end,{},h));else if("W"==g.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("WakeKill",f,g.end,{},h));else if("D|W"==
-g.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Uninterruptable Sleep | WakeKill",f,g.end,{},h));else throw"Unrecognized state: "+g.args.stateWhenDescheduled;d.push(new tracing.TimelineSlice("Running",q,c.start,{},c.duration))}b.cpuSlices=d}})},alignClocks:function(){if(0==this.clockSyncRecords_.length){if(!this.isAdditionalImport_)return;this.abortImport();return!1}var b=this.clockSyncRecords_[0];if(0==b.parentTS||b.parentTS==b.perfTS)return!0;var b=b.parentTS-b.perfTS,a;for(a in this.cpuStates_){for(var d=
-this.cpuStates_[a].cpu,e=0;e<d.slices.length;e++){var c=d.slices[e];c.start+=b;c.duration=c.duration}for(var q in d.counters){e=d.counters[q];for(c=0;c<e.timestamps.length;c++)e.timestamps[c]+=b}}for(var j in this.kernelThreadStates_){a=this.kernelThreadStates_[j].thread;for(e=0;e<a.subRows[0].length;e++)a.subRows[0][e].start+=b}return!0},abortImport:function(){if(this.pushedEventsToThreads)throw"Cannot abort, have alrady pushedCpuDataToThreads.";for(var b in this.cpuStates_)delete this.model_.cpus[b];
-for(var a in this.kernelThreadStates_){b=this.kernelThreadStates_[a].thread;var d=b.parent;delete d.threads[b.tid];delete this.model_.processes[d.pid]}this.model_.importErrors.push("Cannot import kernel trace without a clock sync.")},markPidRunnable:function(){},importError:function(b){this.model_.importErrors.push("Line "+(this.lineNumber+1)+": "+b)},malformedEvent:function(b){this.importError("Malformed "+b+" event")},processBegin:function(b,a,d,e,c,q){var j=tracing.getStringColorId(d),d=new tracing.TimelineThreadSlice(d,
-j,e,null);d.pid=c;d.tid=q;d.threadName=a;b.openSlices.push(d)},processEnd:function(b,a){if(0!=b.openSlices.length){var d=b.openSlices.pop();d.duration=a-d.start;var e=this.model_.getOrCreateProcess(d.pid).getOrCreateThread(d.tid);e.name||(e.name=d.threadName);this.threadsByLinuxPid[d.tid]=e;e.getSubrow(b.openSlices.length).push(d);b.openSlices.length&&b.openSlices[b.openSlices.length-1].subSlices.push(d)}},autoCloseOpenSlices:function(){this.model_.updateBounds();var b=[],a;for(a in this.threadStateByKPID_)for(var d=
-this.threadStateByKPID_[a],e=0;e<d.openSlices.length;e++){var c=d.openSlices[e];b.push(c.start);for(var q=0;q<c.subSlices.length;q++){var j=c.subSlices[q];b.push(j.start);j.duration&&b.push(j.end)}}b=this.model_.maxTimestamp?Math.max(this.model_.maxTimestamp,Math.max.apply(Math,b)):Math.max.apply(Math,b);for(a in this.threadStateByKPID_)for(d=this.threadStateByKPID_[a];0<d.openSlices.length;)c=d.openSlices.pop(),c.duration=b-c.start,c.didNotFinish=!0,this.model_.getOrCreateProcess(c.pid).getOrCreateThread(c.tid).getSubrow(d.openSlices.length).push(c),
-d.openSlices.length&&d.openSlices[d.openSlices.length-1].subSlices.push(c)},processCounter:function(b,a,d,e){b=this.model_.getOrCreateProcess(e).getOrCreateCounter("",b);0==b.numSeries&&(b.seriesNames.push("state"),b.seriesColors.push(tracing.getStringColorId(b.name+".state")));b.timestamps.push(a);b.samples.push(d)},importCpuData:function(){this.lines_=this.events_.split("\n");for(this.lineNumber=0;this.lineNumber<this.lines_.length;++this.lineNumber){var a=this.lines_[this.lineNumber];if(!(/^#/.exec(a)||
-0==a.length)){var f=e.exec(a);if(f){var m=f[1],a=f[4],h=f[5],l=f[6],q=this.getOrCreateCpuState(parseInt(f[2])),f=1E3*parseFloat(a);switch(h){case "sched_switch":a=i.exec(l);if(!a){this.malformedEvent(h);continue}h=a[4];l=a[5];m=parseInt(a[6]);a=parseInt(a[7]);q.switchRunningLinuxPid(this,h,f,m,l,a);break;case "sched_wakeup":a=b.exec(l);if(!a){this.malformedEvent(h);continue}l=a[1];h=parseInt(a[2]);a=parseInt(a[3]);this.markPidRunnable(f,h,l,a);break;case "power_start":a=/type=(\d+) state=(\d) cpu_id=(\d)+/.exec(l);
-if(!a){this.malformedEvent(h);continue}h=parseInt(a[3]);h=this.getOrCreateCpuState(h);if("1"==a[1])h=h.cpu.getOrCreateCounter("","C-State");else{this.importError("Don't understand power_start events of type "+a[1]);continue}0==h.numSeries&&(h.seriesNames.push("state"),h.seriesColors.push(tracing.getStringColorId(h.name+".state")));a=parseInt(a[2]);h.timestamps.push(f);h.samples.push(a);break;case "power_frequency":a=/type=(\d+) state=(\d+) cpu_id=(\d)+/.exec(l);if(!a){this.malformedEvent(h);continue}h=
-parseInt(a[3]);h=this.getOrCreateCpuState(h);h=h.cpu.getOrCreateCounter("","Power Frequency");0==h.numSeries&&(h.seriesNames.push("state"),h.seriesColors.push(tracing.getStringColorId(h.name+".state")));a=parseInt(a[2]);h.timestamps.push(f);h.samples.push(a);break;case "cpu_frequency":a=/state=(\d+) cpu_id=(\d)+/.exec(l);if(!a){this.malformedEvent(h);continue}h=parseInt(a[2]);h=this.getOrCreateCpuState(h);h=h.cpu.getOrCreateCounter("","Clock Frequency");0==h.numSeries&&(h.seriesNames.push("state"),
-h.seriesColors.push(tracing.getStringColorId(h.name+".state")));a=parseInt(a[1]);h.timestamps.push(f);h.samples.push(a);break;case "cpu_idle":a=/state=(\d+) cpu_id=(\d)+/.exec(l);if(!a){this.malformedEvent(h);continue}h=parseInt(a[2]);h=this.getOrCreateCpuState(h);h=h.cpu.getOrCreateCounter("","C-State");0==h.numSeries&&(h.seriesNames.push("state"),h.seriesColors.push(tracing.getStringColorId(h.name)));a=parseInt(a[1]);4294967295!=a?h.samples.push(a):h.samples.push(0);h.timestamps.push(f);break;case "workqueue_execute_start":a=
-j.exec(l);if(!a){this.malformedEvent(h);continue}h=this.getOrCreateKernelThread(m);h.openSliceTS=f;h.openSlice=a[2];break;case "workqueue_execute_end":a=o.exec(l);if(!a){this.malformedEvent(h);continue}h=this.getOrCreateKernelThread(m);h.openSlice&&(f=new tracing.TimelineSlice(h.openSlice,tracing.getStringColorId(h.openSlice),h.openSliceTS,{},f-h.openSliceTS),h.thread.subRows[0].push(f));h.openSlice=void 0;break;case "workqueue_queue_work":break;case "workqueue_activate_work":break;case "i915_gem_object_pwrite":a=
-/obj=(.+), offset=(\d+), len=(\d+)/.exec(l);if(!a){this.malformedEvent(h);continue}l=a[1];q=parseInt(a[2]);a=parseInt(a[3]);h=this.getOrCreateKernelThread("i915_gem",0,1);h.openSlice="pwrite:"+l;f=new tracing.TimelineSlice(h.openSlice,tracing.getStringColorId(h.openSlice),f,{obj:l,offset:q,len:a},0);h.thread.subRows[0].push(f);break;case "i915_flip_request":a=/plane=(\d+), obj=(.+)/.exec(l);if(!a){this.malformedEvent(h);continue}q=parseInt(a[1]);l=a[2];h=this.getOrCreateKernelThread("i915_flip",0,
-2);h.openSliceTS=f;h.openSlice="flip:"+l+"/"+q;break;case "i915_flip_complete":a=/plane=(\d+), obj=(.+)/.exec(l);if(!a){this.malformedEvent(h);continue}q=parseInt(a[1]);l=a[2];h=this.getOrCreateKernelThread("i915_flip",0,2);h.openSlice&&(f=new tracing.TimelineSlice(h.openSlice,tracing.getStringColorId(h.openSlice),h.openSliceTS,{obj:l,plane:q},f-h.openSliceTS),h.thread.subRows[0].push(f));h.openSlice=void 0;break;case "0":case "tracing_mark_write":if(a=d.exec(l))this.clockSyncRecords_.push({perfTS:f,
-parentTS:1E3*a[1]});else{q=this.parsePid(m);m=this.parseThreadName(m);a=q;a in this.threadStateByKPID_||(this.threadStateByKPID_[a]=new c);var r=this.threadStateByKPID_[a],a=l.split("|");switch(a[0]){case "B":h=parseInt(a[1]);l=a[2];this.processBegin(r,m,l,f,h,q);break;case "E":this.processEnd(r,f);break;case "C":h=parseInt(a[1]);l=a[2];a=parseInt(a[3]);this.processCounter(l,f,a,h);break;default:this.malformedEvent(h)}}break;default:console.log("unknown event "+h)}}else this.importError("Unrecognized line: "+
-a)}}}};tracing.TimelineModel.registerImporter(a);return{LinuxPerfImporter:a,_LinuxPerfImporterTestExports:TestExports}});cr.define("tracing",function(){function f(){this.openSlices=[]}function c(a,e){this.model_=a;"string"===typeof e||e instanceof String?("["==e[0]&&(n=e.length,"]"!=e[n-1]&&"\n"!=e[n-1]?e+="]":"]"!=e[n-2]&&"\n"==e[n-1]?e+="]":"]"!=e[n-3]&&("\r"==e[n-2]&&"\n"==e[n-1])&&(e+="]")),this.events_=JSON.parse(e)):this.events_=e;this.events_.traceEvents&&(this.events_=this.events_.traceEvents);this.threadStateByPTID_={};this.allAsyncEvents_=[]}c.canImport=function(a){return"string"===typeof a||a instanceof String?
-"{"==a[0]||"["==a[0]:a instanceof Array&&a.length&&a[0].ph?!0:a.traceEvents?a.traceEvents instanceof Array&&a.traceEvents[0].ph:!1};c.prototype={__proto__:Object.prototype,processBeginEvent:function(a,e,c){var b=tracing.getStringColorId(c.name),a={index:a,slice:new tracing.TimelineThreadSlice(c.name,b,c.ts/1E3,c.args)};c.uts&&(a.slice.startInUserTime=c.uts/1E3);"0"===c.args["ui-nest"]?this.model_.importErrors.push("ui-nest no longer supported."):e.openSlices.push(a)},processEndEvent:function(a,e){if("0"===
-e.args["ui-nest"])this.model_.importErrors.push("ui-nest no longer supported.");else if(0!=a.openSlices.length){var c=a.openSlices.pop().slice;c.duration=e.ts/1E3-c.start;e.uts&&(c.durationInUserTime=e.uts/1E3-c.startInUserTime);for(var b in e.args)c.args[b]=e.args[b];this.model_.getOrCreateProcess(e.pid).getOrCreateThread(e.tid).getSubrow(a.openSlices.length).push(c);a.openSlices.length&&a.openSlices[a.openSlices.length-1].slice.subSlices.push(c)}},processAsyncEvent:function(a,e,c){a=this.model_.getOrCreateProcess(c.pid).getOrCreateThread(c.tid);
-this.allAsyncEvents_.push({event:c,thread:a})},autoCloseOpenSlices:function(){this.model_.updateBounds();var a=[],e;for(e in this.threadStateByPTID_)for(var c=this.threadStateByPTID_[e],b=0;b<c.openSlices.length;b++){var d=c.openSlices[b];a.push(d.slice.start);for(var j=0;j<d.slice.subSlices.length;j++){var f=d.slice.subSlices[j];a.push(f.start);f.duration&&a.push(f.end)}}a=this.model_.maxTimestamp?Math.max(this.model_.maxTimestamp,Math.max.apply(Math,a)):Math.max.apply(Math,a);for(e in this.threadStateByPTID_)for(c=
-this.threadStateByPTID_[e];0<c.openSlices.length;)d=c.openSlices.pop(),d.slice.duration=a-d.slice.start,d.slice.didNotFinish=!0,b=this.events_[d.index],this.model_.getOrCreateProcess(b.pid).getOrCreateThread(b.tid).getSubrow(c.openSlices.length).push(d.slice),c.openSlices.length&&c.openSlices[c.openSlices.length-1].slice.subSlices.push(d.slice)},processCounterEvent:function(a){var e;e=void 0!==a.id?a.name+"["+a.id+"]":a.name;e=this.model_.getOrCreateProcess(a.pid).getOrCreateCounter(a.cat,e);if(0==
-e.numSeries){for(var c in a.args)e.seriesNames.push(c),e.seriesColors.push(tracing.getStringColorId(e.name+"."+c));if(0==e.numSeries){this.model_.importErrors.push("Expected counter "+a.name+" to have at least one argument to use as a value.");delete e.parent.counters[e.name];return}}e.timestamps.push(a.ts/1E3);for(var b=0;b<e.numSeries;b++)c=e.seriesNames[b],void 0===a.args[c]?e.samples.push(0):e.samples.push(a.args[c])},importEvents:function(){for(var a=this.events_,e=0;e<a.length;e++){var c=a[e],
-b=tracing.TimelineThread.getPTIDFromPidAndTid(c.pid,c.tid);b in this.threadStateByPTID_||(this.threadStateByPTID_[b]=new f);var d=this.threadStateByPTID_[b];"B"==c.ph?this.processBeginEvent(e,d,c):"E"==c.ph?this.processEndEvent(d,c):"S"==c.ph?this.processAsyncEvent(e,d,c):"F"==c.ph?this.processAsyncEvent(e,d,c):"T"==c.ph?this.processAsyncEvent(e,d,c):"I"==c.ph?(this.processBeginEvent(e,d,c),this.processEndEvent(d,c)):"C"==c.ph?this.processCounterEvent(c):"M"==c.ph?"thread_name"==c.name?this.model_.getOrCreateProcess(c.pid).getOrCreateThread(c.tid).name=
-c.args.name:this.model_.importErrors.push("Unrecognized metadata name: "+c.name):this.model_.importErrors.push("Unrecognized event phase: "+c.ph+"("+c.name+")")}a=!1;for(b in this.threadStateByPTID_)d=this.threadStateByPTID_[b],a|=0<d.openSlices.length;a&&this.autoCloseOpenSlices()},finalizeImport:function(){if(0!=this.allAsyncEvents_.length){this.allAsyncEvents_.sort(function(b,a){return b.event.ts-a.event.ts});for(var a={},c=this.allAsyncEvents_,f=0;f<c.length;f++){var b=c[f],d=b.event,j=d.name;
-if(void 0===j)this.model_.importErrors.push("Async events (ph: S, T or F) require an name parameter.");else{var o=d.id;if(void 0===o)this.model_.importErrors.push("Async events (ph: S, T or F) require an id parameter.");else if("S"==d.ph)void 0===a[j]&&(a[j]={}),a[j][o]?this.model_.importErrors.push("At "+d.ts+", an slice of the same id "+o+" was alrady open."):(a[j][o]=[],a[j][o].push(b));else if(void 0===a[j])this.model_.importErrors.push("At "+d.ts+", no slice named "+j+" was open.");else if(void 0===
-a[j][o])this.model_.importErrors.push("At "+d.ts+", no slice named "+j+" with id="+o+" was open.");else{var g=a[j][o];g.push(b);if("F"==d.ph){var k=new tracing.TimelineAsyncSlice(j,tracing.getStringColorId(j),g[0].event.ts/1E3);k.duration=d.ts/1E3-g[0].event.ts/1E3;k.startThread=g[0].thread;k.endThread=b.thread;k.id=o;k.args=g[0].event.args;k.subSlices=[];for(b=1;b<g.length;++b){var m=j;"T"==g[b-1].event.ph&&(m=j+":"+g[b-1].event.args.step);m=new tracing.TimelineAsyncSlice(m,tracing.getStringColorId(j+
-b),g[b-1].event.ts/1E3);m.duration=g[b].event.ts/1E3-g[b-1].event.ts/1E3;m.startThread=g[b-1].thread;m.endThread=g[b].thread;m.id=o;m.args=g[b-1].event.args;k.subSlices.push(m)}var g=k.subSlices[k.subSlices.length-1],h;for(h in d.args)g.args[h]=d.args[h];k.startThread.asyncSlices.push(k);delete a[j][o]}}}}}}};tracing.TimelineModel.registerImporter(c);return{TraceEventImporter:c}});cr.define("tracing",function(){function f(a,c,f){if(0==a.length)return 1;for(var b=0,d=a.length-1,j,o,g=-1;b<=d;)j=Math.floor((b+d)/2),o=c(a[j])-f,0>o?b=j+1:(0<o||(g=j),d=j-1);return-1!=g?g:b}function c(a,c,i,b,d,j){if(!(b>d)){var o=f(a,c,b);if(-1!=o&&(0<o&&c(a[o-1])+i(a[o-1])>=b&&j(a[o-1]),o!=a.length))for(i=a.length;o<i&&!(c(a[o])>=d);o++)j(a[o])}}return{findLowIndexInSortedArray:f,findLowIndexInSortedIntervals:function(a,c,i,b){var d=f(a,c,b);return 0==d?b>=c(a[0])&&b<c(a[0]+i(a[0]))?0:-1:d<=a.length&&
-b>=c(a[d-1])&&b<c(a[d-1])+i(a[d-1])?d-1:a.length},iterateOverIntersectingIntervals:c,getIntersectingIntervals:function(a,e,f,b,d){var j=[];c(a,e,f,b,d,function(b){j.push(b)});return j}}});cr.define("tracing",function(){function f(){var c=document.createElement("iframe");c.style.cssText="width:100%;height:0;border:0;visibility:hidden";document.body.appendChild(c);this._doc=c.contentDocument;this._window=c.contentWindow;this._doc.body.style.cssText="padding:0;margin:0;overflow:hidden";for(var c=document.querySelectorAll("link[rel=stylesheet]"),a=0;a<c.length;a++){var e=c[a],f=this._doc.createElement("link");f.rel="stylesheet";f.href=e.href;this._doc.head.appendChild(f)}}f.prototype=
-{__proto__:Object.prototype,measure:function(c){this._doc.body.appendChild(c);var a=this._window.getComputedStyle(c),e=parseInt(a.width,10),a=parseInt(a.height,10);this._doc.body.removeChild(c);return{width:e,height:a}}};return{MeasuringStick:f}});cr.define("tracing",function(){function f(b){this.parentEl_=b;this.scaleX_=1;this.gridTimebase_=this.panX_=0;this.gridStep_=1E3/60;this.hasCalledSetupFunction_=this.gridEnabled_=!1;this.onResizeBoundToThis_=this.onResize_.bind(this);this.checkForAttachInterval_=setInterval(this.checkForAttach_.bind(this),250)}function c(b,a){this.track=b;this.slice=a}function a(b,a,c){this.track=b;this.counter=a;this.sampleIndex=c}function e(){this.range_dirty_=!0;this.range_={};this.length_=0}f.prototype={__proto__:cr.EventTarget.prototype,
-setWhenPossible:function(b){this.pendingSetFunction_=b},get isAttachedToDocument_(){for(var b=this.parentEl_;b.parentNode;)b=b.parentNode;return b==this.parentEl_.ownerDocument},onResize_:function(){this.dispatchChangeEvent()},checkForAttach_:function(){if(this.isAttachedToDocument_&&0!=this.clientWidth){this.iframe_||(this.iframe_=document.createElement("iframe"),this.iframe_.style.cssText="position:absolute;width:100%;height:0;border:0;visibility:hidden;",this.parentEl_.appendChild(this.iframe_),
-this.iframe_.contentWindow.addEventListener("resize",this.onResizeBoundToThis_));var b=this.clientWidth+"x"+this.clientHeight;this.pendingSetFunction_&&(this.lastSize_=b,this.pendingSetFunction_(),this.pendingSetFunction_=void 0);window.clearInterval(this.checkForAttachInterval_);this.checkForAttachInterval_=void 0}},dispatchChangeEvent:function(){cr.dispatchSimpleEvent(this,"change")},detach:function(){this.checkForAttachInterval_&&(window.clearInterval(this.checkForAttachInterval_),this.checkForAttachInterval_=
-void 0);this.iframe_.removeEventListener("resize",this.onResizeBoundToThis_);this.parentEl_.removeChild(this.iframe_)},get scaleX(){return this.scaleX_},set scaleX(b){this.scaleX_!=b&&(this.scaleX_=b,this.dispatchChangeEvent())},get panX(){return this.panX_},set panX(b){this.panX_!=b&&(this.panX_=b,this.dispatchChangeEvent())},setPanAndScale:function(b,a){if(this.scaleX_!=a||this.panX_!=b)this.scaleX_=a,this.panX_=b,this.dispatchChangeEvent()},xWorldToView:function(b){return(b+this.panX_)*this.scaleX_},
-xWorldVectorToView:function(b){return b*this.scaleX_},xViewToWorld:function(b){return b/this.scaleX_-this.panX_},xViewVectorToWorld:function(b){return b/this.scaleX_},xPanWorldPosToViewPos:function(b,a,c){if("string"==typeof a)if("left"==a)a=0;else if("center"==a)a=c/2;else if("right"==a)a=c-1;else throw Error("unrecognized string for viewPos. left|center|right");this.panX=a/this.scaleX_-b},xPanWorldRangeIntoView:function(b,a,c){0>this.xWorldToView(b)?this.xPanWorldPosToViewPos(b,"left",c):this.xWorldToView(a)>
-c&&this.xPanWorldPosToViewPos(a,"right",c)},xSetWorldRange:function(b,a,c){this.setPanAndScale(-b,c/(a-b))},get gridEnabled(){return this.gridEnabled_},set gridEnabled(b){this.gridEnabled_!=b&&(this.gridEnabled_=b&&!0,this.dispatchChangeEvent())},get gridTimebase(){return this.gridTimebase_},set gridTimebase(b){this.gridTimebase_!=b&&(this.gridTimebase_=b,cr.dispatchSimpleEvent(this,"change"))},get gridStep(){return this.gridStep_},applyTransformToCanavs:function(b){b.transform(this.scaleX_,0,0,1,
-this.panX_*this.scaleX_,0)}};c.prototype={get selected(){return this.slice.selected},set selected(b){this.slice.selected=b}};a.prototype={get selected(){return!0==this.track.selectedSamples[this.sampleIndex]},set selected(b){this.track.selectedSamples[this.sampleIndex]=b?!0:!1;this.track.invalidate()}};e.prototype={__proto__:Object.prototype,get range(){if(this.range_dirty_){for(var b=Infinity,a=-b,c=0;c<this.length_;c++){var e=this[c];e.slice&&(b=Math.min(b,e.slice.start),a=Math.max(a,e.slice.end))}this.range_=
-{min:b,max:a};this.range_dirty_=!1}return this.range_},get duration(){return this.range.max-this.range.min},get length(){return this.length_},clear:function(){for(var b=0;b<this.length_;++b)delete this[b];this.length_=0;this.range_dirty_=!0},push_:function(b){this[this.length_++]=b;this.range_dirty_=!0;return b},addSlice:function(b,a){return this.push_(new c(b,a))},addCounterSample:function(b,d,c){return this.push_(new a(b,d,c))},subSelection:function(b,a){var a=a||1,c=new e;c.range_dirty_=!0;if(0>
-b||b+a>this.length_)throw"Index out of bounds";for(var f=b;f<b+a;f++)c.push_(this[f]);return c},getCounterSampleHits:function(){for(var b=new e,d=0;d<this.length_;d++)this[d]instanceof a&&b.push_(this[d]);return b},getSliceHits:function(){for(var b=new e,a=0;a<this.length_;a++)this[a]instanceof c&&b.push_(this[a]);return b},map:function(a){for(var d=0;d<this.length_;d++)a(this[d])},getShiftedSelection:function(a){for(var d=new e,c=0;c<this.length_;c++){var f=this[c];f.track.addItemNearToProvidedHitToSelection(f,
-a,d)}return 0==d.length?void 0:d}};var i=cr.ui.define("div");i.prototype={__proto__:HTMLDivElement.prototype,model_:null,decorate:function(){this.classList.add("timeline");this.viewport_=new f(this);this.viewportTrack=new tracing.TimelineViewportTrack;this.tracks_=this.ownerDocument.createElement("div");this.appendChild(this.tracks_);this.dragBox_=this.ownerDocument.createElement("div");this.dragBox_.className="timeline-drag-box";this.appendChild(this.dragBox_);this.hideDragBox_();this.bindEventListener_(document,
-"keypress",this.onKeypress_,this);this.bindEventListener_(document,"keydown",this.onKeydown_,this);this.bindEventListener_(document,"mousedown",this.onMouseDown_,this);this.bindEventListener_(document,"mousemove",this.onMouseMove_,this);this.bindEventListener_(document,"mouseup",this.onMouseUp_,this);this.bindEventListener_(document,"dblclick",this.onDblClick_,this);this.lastMouseViewPos_={x:0,y:0};this.selection_=new e},bindEventListener_:function(a,d,c,e){this.boundListeners_||(this.boundListeners_=
-[]);c=c.bind(e);this.boundListeners_.push({object:a,event:d,boundFunc:c});a.addEventListener(d,c)},detach:function(){for(var a=0;a<this.tracks_.children.length;a++)this.tracks_.children[a].detach();for(a=0;a<this.boundListeners_.length;a++){var d=this.boundListeners_[a];d.object.removeEventListener(d.event,d.boundFunc)}this.boundListeners_=void 0;this.viewport_.detach()},get viewport(){return this.viewport_},get model(){return this.model_},set model(a){if(!a)throw Error("Model cannot be null");if(this.model)throw Error("Cannot set model twice.");
-this.model_=a;var d=[];a.getAllThreads().forEach(function(a){d.push(a.userFriendlyName)});a.getAllCounters().forEach(function(a){d.push(a.name)});a.getAllCpus().forEach(function(a){d.push("CPU "+a.cpuNumber)});var c=0,e=new tracing.MeasuringStick,f=document.createElement("div");f.style.position="fixed";f.className="timeline-canvas-based-track-title";d.forEach(function(a){f.textContent=a+":__";a=e.measure(f).width;300<a&&(a=300);a>c&&(c=a)});for(var c=c+"px",i=0;i<this.tracks_.children.length;i++)this.tracks_.children[i].detach();
-this.tracks_.textContent="";this.viewportTrack.headingWidth=c;this.viewportTrack.viewport=this.viewport_;i=a.getAllCpus();i.sort(tracing.TimelineCpu.compare);i.forEach(function(a){var b=new tracing.TimelineCpuTrack;b.heading="CPU "+a.cpuNumber+":";b.headingWidth=c;b.viewport=this.viewport_;b.cpu=a;this.tracks_.appendChild(b);for(var d in a.counters){var e=a.counters[d],b=new tracing.TimelineCounterTrack;b.heading="CPU "+a.cpuNumber+" "+e.name+":";b.headingWidth=c;b.viewport=this.viewport_;b.counter=
-e;this.tracks_.appendChild(b)}}.bind(this));a=a.getAllProcesses();a.sort(tracing.TimelineProcess.compare);a.forEach(function(a){var b=[],d;for(d in a.counters)b.push(a.counters[d]);b.sort(tracing.TimelineCounter.compare);b.forEach(function(a){var b=new tracing.TimelineCounterTrack;b.heading=a.name+":";b.headingWidth=c;b.viewport=this.viewport_;b.counter=a;this.tracks_.appendChild(b)}.bind(this));b=[];for(d in a.threads)b.push(a.threads[d]);b.sort(tracing.TimelineThread.compare);b.forEach(function(a){var b=
-new tracing.TimelineThreadTrack;b.heading=a.userFriendlyName+":";b.tooltip=a.userFriendlyDetails;b.headingWidth=c;b.viewport=this.viewport_;b.thread=a;this.tracks_.appendChild(b)}.bind(this))}.bind(this));this.viewport_.setWhenPossible(function(){this.viewport_.xSetWorldRange(this.model_.minTimestamp,this.model_.maxTimestamp,this.firstCanvas.width)}.bind(this))},addAllObjectsMatchingFilterToSelection:function(a,d){for(var c=0;c<this.tracks_.children.length;++c)this.tracks_.children[c].addAllObjectsMatchingFilterToSelection(a,
-d)},get focusElement(){return this.focusElement_?this.focusElement_:this.parentElement},set focusElement(a){this.focusElement_=a},get listenToKeys_(){return!this.viewport_.isAttachedToDocument_?!1:!this.focusElement_?!0:0<=this.focusElement.tabIndex?document.activeElement==this.focusElement:!0},onKeypress_:function(a){var d=this.viewport_;if(this.firstCanvas&&this.listenToKeys_){var c=this.firstCanvas.clientWidth;switch(a.keyCode){case 101:a=d.xViewToWorld(this.lastMouseViewPos_.x);d.xPanWorldPosToViewPos(a,
-"center",c);break;case 119:this.zoomBy_(1.5);break;case 115:this.zoomBy_(1/1.5);break;case 103:this.onGridToggle_(!0);break;case 71:this.onGridToggle_(!1);break;case 87:this.zoomBy_(10);break;case 83:this.zoomBy_(0.1);break;case 97:d.panX+=d.xViewVectorToWorld(0.1*c);break;case 100:d.panX-=d.xViewVectorToWorld(0.1*c);break;case 65:d.panX+=d.xViewVectorToWorld(0.5*c);break;case 68:d.panX-=d.xViewVectorToWorld(0.5*c)}}},onKeydown_:function(a){if(this.listenToKeys_){var d;switch(a.keyCode){case 37:if(d=
-this.selection.getShiftedSelection(-1))this.setSelectionAndMakeVisible(d),a.preventDefault();break;case 39:if(d=this.selection.getShiftedSelection(1))this.setSelectionAndMakeVisible(d),a.preventDefault();break;case 9:-1==this.focusElement.tabIndex&&(a.shiftKey?this.selectPrevious_(a):this.selectNext_(a),a.preventDefault())}}},zoomBy_:function(a){if(this.firstCanvas){var d=this.viewport_,c=this.firstCanvas.clientWidth,e=this.lastMouseViewPos_.x,f=d.xViewToWorld(e);d.scaleX*=a;d.xPanWorldPosToViewPos(f,
-e,c)}},get keyHelp(){var a="Keyboard shortcuts:\n w/s     : Zoom in/out    (with shift: go faster)\n a/d     : Pan left/right\n e       : Center on mouse\n g/G     : Shows grid at the start/end of the selected task\n",a=this.focusElement.tabIndex?a+" <-      : Select previous event on current timeline\n ->      : Select next event on current timeline\n":a+" <-,^TAB : Select previous event on current timeline\n ->, TAB : Select next event on current timeline\n";return a+"\nDbl-click to zoom in; Shift dbl-click to zoom out\n"},
-get selection(){return this.selection_},set selection(a){if(!(a instanceof e))throw"Expected TimelineSelection";var d;for(d=0;d<this.selection_.length;d++)this.selection_[d].selected=!1;this.selection_=a;cr.dispatchSimpleEvent(this,"selectionChange");for(d=0;d<this.selection_.length;d++)this.selection_[d].selected=!0;this.viewport_.dispatchChangeEvent()},setSelectionAndMakeVisible:function(a,d){if(!(a instanceof e))throw"Expected TimelineSelection";this.selection=a;var c=this.selection.range,f=this.viewport_.xWorldVectorToView(c.max-
-c.min);d&&50>f?(f=c.min+0.5*(c.max-c.min),c=5*(c.max-c.min),this.viewport_.xSetWorldRange(f-0.5*c,f+0.5*c,this.firstCanvas.width)):this.viewport_.xPanWorldRangeIntoView(c.min,c.max,this.firstCanvas.width)},get firstCanvas(){return this.tracks_.firstChild?this.tracks_.firstChild.firstCanvas:void 0},hideDragBox_:function(){this.dragBox_.style.left="-1000px";this.dragBox_.style.top="-1000px";this.dragBox_.style.width=0;this.dragBox_.style.height=0},setDragBoxPosition_:function(a,c){var e=Math.min(a.clientX,
-c.clientX),f=Math.max(a.clientX,c.clientX),g=Math.min(a.clientY,c.clientY),i=Math.max(a.clientY,c.clientY);this.dragBox_.style.left=e+"px";this.dragBox_.style.top=g+"px";this.dragBox_.style.width=f-e+"px";this.dragBox_.style.height=i-g+"px";g=this.firstCanvas;e=this.viewport_.xViewToWorld(e-g.offsetLeft);f=this.viewport_.xViewToWorld(f-g.offsetLeft);this.dragBox_.textContent=Math.round(100*(f-e))/100+"ms";g=new cr.Event("selectionChanging");g.loWX=e;g.hiWX=f;this.dispatchEvent(g)},onGridToggle_:function(a){var a=
-a?this.selection_.range.min:this.selection_.range.max,c=Math.ceil((a-this.model_.minTimestamp)/this.viewport_.gridStep_);this.viewport_.gridTimebase=a-(c+1)*this.viewport_.gridStep_;this.viewport_.gridEnabled=!0},onMouseDown_:function(a){var c=this.firstCanvas,e=this.tracks_.getClientRects()[0];e&&(a.clientX>=e.left&&a.clientX<e.right&&a.clientY>=e.top&&a.clientY<e.bottom&&a.x>=c.offsetLeft)&&(this.viewport_.xViewToWorld(a.clientX-c.offsetLeft),this.dragBeginEvent_=a,a.preventDefault(),0<=this.focusElement.tabIndex&&
-this.focusElement.focus())},onMouseMove_:function(a){if(this.firstCanvas){var c=this.firstCanvas;this.lastMouseViewPos_={x:a.clientX-c.offsetLeft,y:a.clientY-c.offsetTop};this.dragBeginEvent_&&this.setDragBoxPosition_(this.dragBeginEvent_,a)}},onMouseUp_:function(a){var c;if(this.dragBeginEvent_){this.hideDragBox_();var f=this.dragBeginEvent_;this.dragBeginEvent_=null;var i=Math.min(f.clientX,a.clientX);c=Math.max(f.clientX,a.clientX);var g=Math.min(f.clientY,a.clientY),a=Math.max(f.clientY,a.clientY),
-f=this.firstCanvas,i=this.viewport_.xViewToWorld(i-f.offsetLeft),f=this.viewport_.xViewToWorld(c-f.offsetLeft),k=new e;for(c=0;c<this.tracks_.children.length;c++){var m=this.tracks_.children[c],h=m.getBoundingClientRect(),l=Math.max(g,h.top),h=Math.min(a,h.bottom);l<=h&&m.addIntersectingItemsInRangeToSelection(i,f,g,a,k)}this.selection=k}},onDblClick_:function(a){if(!(a.x<this.firstCanvas.offsetLeft)){var c=4;a.shiftKey&&(c=1/c);this.zoomBy_(c);a.preventDefault()}}};cr.defineProperty(i,"model",cr.PropertyKind.JS);
-return{Timeline:i,TimelineSelectionSliceHit:c,TimelineSelectionCounterSampleHit:a,TimelineSelection:e,TimelineViewport:f}});cr.define("tracing",function(){function f(a){return Math.round(1E3*a)/1E3}function c(a,b){b=b||0;"string"!=typeof a&&(a=""+a);if(a.length>=b)return"";for(var c="",e=0;e<b-a.length;e++)c+=" ";return c}function a(a,b){return a+c(a,b)}function e(a,b){return c(a,b)+a}function i(b){var c="",i=b.getSliceHits(),g=b.getCounterSampleHits();if(1==i.length){var b=14,k=i[0].slice,c="Selected item:\n"+(a("Title",b)+": "+k.title+"\n"),c=c+(a("Start",b)+": "+f(k.start)+" ms\n"),c=c+(a("Duration",b)+": "+f(k.duration)+
-" ms\n");k.durationInUserTime&&(c+=a("Duration (U)",b)+": "+f(k.durationInUserTime)+" ms\n");var m=0,h;for(h in k.args)m+=1;if(0<m)for(h in c+=a("Args",b)+":\n",k.args)m=k.args[h],c+=a(" "+h,b)+": "+m+"\n"}else if(1<i.length){var b=55,c="Slices:\n",l=i.range.min,q=i.range.max;i.map(function(a){return a.slice.title});var r={};for(h=0;h<i.length;h++)k=i[h].slice,r[k.title]||(r[k.title]={slices:[]}),r[k.title].slices.push(k);k=0;for(m in r){var v=r[m],u=0;for(h=0;h<v.slices.length;h++)u+=v.slices[h].duration;
-k+=u;c+=" "+a(m,b)+": "+e(f(u)+"ms",12)+"   "+e(""+v.slices.length,5)+" occurrences\n"}c+=a("*Totals",b)+" : "+e(f(k)+"ms",12)+"   "+e(""+i.length,5)+" occurrences\n";c=c+"\n"+(a("Selection start",b)+" : "+e(f(l)+"ms",12)+"\n");c+=a("Selection extent",b)+" : "+e(f(q-l)+"ms",12)+"\n"}if(1==g.length){c="Selected counter:\n";b=55;g=g[0];i=g.counter;g=g.sampleIndex;m=[];for(h=0;h<i.numSeries;++h)m.push(i.samples[i.numSeries*g+h]);c+=a("Title",b)+": "+i.name+"\n";c+=a("Timestamp",b)+": "+f(i.timestamps[g])+
-" ms\n";c=1<i.numSeries?c+(a("Values",b)+": "+m.join("\n")+"\n"):c+(a("Value",b)+": "+m.join("\n")+"\n")}else 1<g.length&&0==i.length&&(c+="Analysis of multiple counters not yet implemented. Pick a single counter.");return c}var b=cr.ui.define("div");b.prototype={__proto__:HTMLDivElement.prototype,decorate:function(){this.className="timeline-analysis"},set selection(a){this.textContent=i(a)}};return{TimelineAnalysisView:b}});cr.define("tracing",function(){function f(a,b){var c=document.createElement("div");c.classList.add("timeline-track-button");c.classList.add("timeline-track-close-button");c.textContent=String.fromCharCode(215);c.addEventListener("click",function(){a.style.display="None"});a.appendChild(c);if(b){var d=document.createElement("div");d.classList.add("timeline-track-button");d.classList.add("timeline-track-collapse-button");d.textContent="\u2212";var e=!1;d.addEventListener("click",function(){e=!e;a.collapsedDidChange(e);
-d.textContent=e?"+":"\u2212"});a.appendChild(d)}}function c(a,b){this.string=a;this.width=b}function a(){}var e=tracing.getPallette(),i=tracing.getPalletteHighlightIdBoost(),b={},d={},j=cr.ui.define("div");j.prototype={__proto__:HTMLDivElement.prototype,decorate:function(){this.tracks_=[]},detach:function(){for(var a=0;a<this.tracks_.length;a++)this.tracks_[a].detach()},get viewport(){return this.viewport_},set viewport(a){this.viewport_=a;for(var b=0;b<this.tracks_.length;b++)this.tracks_[b].viewport=
-a;this.updateChildTracks_()},get firstCanvas(){if(this.tracks_.length)return this.tracks_[0].firstCanvas},addIntersectingItemsToSelection:function(a,b,c){for(var d=0;d<this.tracks_.length;d++){var e=this.tracks_[d].getBoundingClientRect();b>=e.top&&b<e.bottom&&this.tracks_[d].addIntersectingItemsToSelection(a,b,c)}return!1},addIntersectingItemsInRangeToSelection:function(a,b,c,d,e){for(var f=0;f<this.tracks_.length;f++){var g=this.tracks_[f].getBoundingClientRect(),h=Math.max(c,g.top),g=Math.min(d,
-g.bottom);h<=g&&this.tracks_[f].addIntersectingItemsInRangeToSelection(a,b,c,d,e)}},addAllObjectsMatchingFilterToSelection:function(a,b){for(var c=0;c<this.tracks_.length;c++)this.tracks_[c].addAllObjectsMatchingFilterToSelection(a,b)}};var o=cr.ui.define(j);o.prototype={__proto__:j.prototype,decorate:function(){this.classList.add("timeline-thread-track")},get thread(){return this.thread_},set thread(a){this.thread_=a;this.updateChildTracks_()},get tooltip(){return this.tooltip_},set tooltip(a){this.tooltip_=
-a;this.updateChildTracks_()},get heading(){return this.heading_},set heading(a){this.heading_=a;this.updateChildTracks_()},get headingWidth(){return this.headingWidth_},set headingWidth(a){this.headingWidth_=a;this.updateChildTracks_()},addTrack_:function(a){var b=new k;b.heading="";b.slices=a;b.headingWidth=this.headingWidth_;b.viewport=this.viewport_;this.tracks_.push(b);this.appendChild(b);return b},updateChildTracks_:function(){this.detach();this.textContent="";this.tracks_=[];if(this.thread_){if(this.thread_.cpuSlices){var a=
+function onLoad(){reload()}function reload(){if(linuxPerfData){var g=new tracing.TimelineModel;g.importEvents("[]",!0,[linuxPerfData]);var e=document.querySelector(".view");cr.ui.decorate(e,tracing.TimelineView);e.model=g;e.tabIndex=1;e.timeline.focusElement=e}}document.addEventListener("DOMContentLoaded",onLoad);var global=this;
+this.cr=function(){function g(a,b,c,f){var e=new cr.Event(b+"Change");e.propertyName=b;e.newValue=c;e.oldValue=f;a.dispatchEvent(e)}function e(a){return a.replace(/([A-Z])/g,"-$1").toLowerCase()}function c(b,c){switch(c){case a.JS:var f=b+"_";return function(){return this[f]};case a.ATTR:var h=e(b);return function(){return this.getAttribute(h)};case a.BOOL_ATTR:return h=e(b),function(){return this.hasAttribute(h)}}}function f(b,c,f){switch(c){case a.JS:var h=b+"_";return function(a){var c=this[h];
+a!==c&&(this[h]=a,f&&f.call(this,a,c),g(this,b,a,c))};case a.ATTR:var k=e(b);return function(a){var c=this[k];a!==c&&(void 0==a?this.removeAttribute(k):this.setAttribute(k,a),f&&f.call(this,a,c),g(this,b,a,c))};case a.BOOL_ATTR:return k=e(b),function(a){var c=this[k];a!==c&&(a?this.setAttribute(k,b):this.removeAttribute(k),f&&f.call(this,a,c),g(this,b,a,c))}}}function h(a,b,c){var f=cr.doc.createEvent("Event");f.initEvent(a,!!b,!!c);f.__proto__=global.Event.prototype;return f}var a={JS:"js",ATTR:"attr",
+BOOL_ATTR:"boolAttr"},b=1;return{addSingletonGetter:function(a){a.getInstance=function(){return a.instance_||(a.instance_=new a)}},createUid:function(){return b++},define:function(a,b){var c;c=a.split(".");for(var f=global,e;c.length&&(e=c.shift());)f=e in f?f[e]:f[e]={};c=f;var f=b(),h;for(h in f)(e=Object.getOwnPropertyDescriptor(f,h))&&Object.defineProperty(c,h,e)},defineProperty:function(b,e,h,g){"function"==typeof b&&(b=b.prototype);h=h||a.JS;b.__lookupGetter__(e)||b.__defineGetter__(e,c(e,h));
+b.__lookupSetter__(e)||b.__defineSetter__(e,f(e,h,g))},dispatchPropertyChange:g,dispatchSimpleEvent:function(a,b,c,f){b=new cr.Event(b,c,f);return a.dispatchEvent(b)},Event:h,getUid:function(a){return a.hasOwnProperty("uid")?a.uid:a.uid=b++},initialize:function(){if(global.document)h.prototype={__proto__:global.Event.prototype},cr.isMac=/Mac/.test(navigator.platform),cr.isWindows=/Win/.test(navigator.platform),cr.isChromeOS=/CrOS/.test(navigator.userAgent),cr.isLinux=/Linux/.test(navigator.userAgent),
+cr.isGTK=/GTK/.test(chrome.toolkit),cr.isViews=/views/.test(chrome.toolkit),cr.isTouchOptimized=!!chrome.touchOptimized,cr.isTouchOptimized&&doc.documentElement.setAttribute("touch-optimized","");else{var a=cr;Object.defineProperty(global,"cr",{get:function(){Object.defineProperty(global,"cr",{value:a});a.initialize();return a},configurable:!0})}},PropertyKind:a,get doc(){return document}}}();cr.initialize();cr.define("cr",function(){function g(){}g.prototype={addEventListener:function(e,c){this.listeners_||(this.listeners_=Object.create(null));if(e in this.listeners_){var f=this.listeners_[e];0>f.indexOf(c)&&f.push(c)}else this.listeners_[e]=[c]},removeEventListener:function(e,c){if(this.listeners_&&e in this.listeners_){var f=this.listeners_[e],h=f.indexOf(c);0<=h&&(1==f.length?delete this.listeners_[e]:f.splice(h,1))}},dispatchEvent:function(e){if(!this.listeners_)return!0;var c=this;e.__defineGetter__("target",
+function(){return c});e.preventDefault=function(){this.returnValue=!1};var f=e.type,h=0;if(f in this.listeners_)for(var f=this.listeners_[f].concat(),a=0,b;b=f[a];a++)h=b.handleEvent?h|!1===b.handleEvent.call(b,e):h|!1===b.call(this,e);return!h&&e.returnValue}};return{EventTarget:g}});cr.define("cr.ui",function(){function g(e,c){return(c&&c.ownerDocument?c.ownerDocument:cr.doc).createElement(e)}return{decorate:function(e,c){var f;f="string"==typeof e?cr.doc.querySelectorAll(e):[e];for(var h=0,a;a=f[h];h++)a instanceof c||c.decorate(a)},define:function(e){function c(a){var b=f(h,a);c.decorate(b);for(var d in a)b[d]=a[d];return b}var f,h;"function"==typeof e?(f=e,h=""):(f=g,h=e);c.decorate=function(a){a.__proto__=c.prototype;a.decorate()};return c},limitInputWidth:function(e,c,f){function h(){if(e.scrollWidth>
+j)e.style.width=j+"px";else{e.style.width=0;var a=e.scrollWidth;e.style.width=a<f?f+"px":a+"px"}}e.style.width="10px";var a=e.ownerDocument.defaultView,b=a.getComputedStyle(e),a=a.getComputedStyle(c),d="rtl"==b.direction,m=e.getBoundingClientRect(),g=c.getBoundingClientRect(),m=d?g.right-m.right:m.left-g.left,b=parseInt(b.borderLeftWidth,10)+parseInt(b.paddingLeft,10)+parseInt(b.paddingRight,10)+parseInt(b.borderRightWidth,10),a=d?parseInt(a.paddingLeft,10):parseInt(a.paddingRight,10),j=c.clientWidth-
+m-b-a;e.addEventListener("input",h);h()}}});cr.define("cr.ui",function(){function g(c){this.classList_=c.documentElement.classList;var f=this;c.addEventListener("keydown",function(c){9==c.keyCode&&(f.visible=!0)},!0);c.addEventListener("mousedown",function(){f.visible=!1},!0)}g.prototype={set visible(c){c?this.classList_.add("focus-outline-visible"):this.classList_.remove("focus-outline-visible")},get visible(){this.classList_.contains("focus-outline-visible")}};var e=[];g.forDocument=function(c){for(var f=0;f<e.length;f++)if(c==e[f][0])return e[f][1];
+f=new g(c);e.push([c,f]);return f};return{FocusOutlineManager:g}});cr.define("cr.ui",function(){function g(){for(var b={TABBOX:e,TABS:c,TAB:f,TABPANELS:h,TABPANEL:a},d,m=0;d=this.children[m];m++){var g=b[d.tagName];g&&cr.ui.decorate(d,g)}}var e=cr.ui.define("tabbox");e.prototype={__proto__:HTMLElement.prototype,decorate:function(){g.call(this);this.addEventListener("selectedChange",this.handleSelectedChange_,!0);this.selectedIndex=0},handleSelectedChange_:function(a){var d=a.target;a.newValue&&(d.parentElement&&d.parentElement.parentElement)==this&&(this.selectedIndex=
+Array.prototype.indexOf.call(d.parentElement.children,d))},selectedIndex_:-1};cr.defineProperty(e,"selectedIndex",cr.PropertyKind.JS_PROP,function(a){for(var d,c,f=0;d=this.children[f];f++)for(var e=0;c=d.children[e];e++)c.selected=e==a});var c=cr.ui.define("tabs");c.prototype={__proto__:HTMLElement.prototype,decorate:function(){g.call(this);this.tabIndex=0;this.addEventListener("keydown",this.handleKeyDown_.bind(this));this.focusOutlineManager_=cr.ui.FocusOutlineManager.forDocument(this.ownerDocument)},
+handleKeyDown_:function(a){var d=0;switch(a.keyIdentifier){case "Left":case "Up":d=-1;break;case "Right":case "Down":d=1}d&&("rtl"==this.ownerDocument.defaultView.getComputedStyle(this).direction&&(d*=-1),a=this.children.length,this.parentElement.selectedIndex=(this.parentElement.selectedIndex+d+a)%a,this.focusOutlineManager_.visible=!0)}};var f=cr.ui.define("tab");f.prototype={__proto__:HTMLElement.prototype,decorate:function(){var a=this;this.addEventListener(cr.isMac?"click":"mousedown",function(){a.selected=
+!0})}};cr.defineProperty(f,"selected",cr.PropertyKind.BOOL_ATTR);var h=cr.ui.define("tabpanels");h.prototype={__proto__:HTMLElement.prototype,decorate:g};var a=cr.ui.define("tabpanel");a.prototype={__proto__:HTMLElement.prototype,decorate:function(){}};cr.defineProperty(a,"selected",cr.PropertyKind.BOOL_ATTR);return{TabBox:e,Tabs:c,Tab:f,TabPanels:h,TabPanel:a}});global=this;function $(g){return document.getElementById(g)}function chromeSend(g,e,c,f){var h=global[c];global[c]=function(){global[c]=h;var a=Array.prototype.slice.call(arguments);return f.apply(global,a)};chrome.send(g,e)}function url(g){g=g.replace(/(\(|\)|\,|\s|\'|\"|\\)/g,"\\$1");/\\\\$/.test(g)&&(g+=" ");return'url("'+g+'")'}function parseQueryParams(g){for(var e={},g=unescape(g.search.substring(1)).split("&"),c=0;c<g.length;c++){var f=g[c].split("=");e[f[0]]=f[1]}return e}
+function findAncestorByClass(g,e){return findAncestor(g,function(c){return c.classList?c.classList.contains(e):null})}function findAncestor(g,e){for(var c=!1;null!=g&&!(c=e(g));)g=g.parentNode;return c?g:null}function swapDomNodes(g,e){var c=g.nextSibling;if(c==e)swapDomNodes(e,g);else{var f=g.parentNode;e.parentNode.replaceChild(g,e);f.insertBefore(e,c)}}
+function disableTextSelectAndDrag(){document.onselectstart=function(g){g.preventDefault()};document.ondragstart=function(g){g.preventDefault()}}function isRTL(){return"rtl"==document.documentElement.dir}function assert(g,e){if(!g){var c="Assertion failed";e&&(c=c+": "+e);throw Error(c);}}function getRequiredElement(g){var e=$(g);assert(e,"Missing required element: "+g);return e}
+document.addEventListener("click",function(g){if(g.returnValue){var e=g.target;if(e.nodeType==Node.ELEMENT_NODE&&e.webkitMatchesSelector("A, A *")){for(;"A"!=e.tagName;)e=e.parentElement;if(("file:"==e.protocol||"about:"==e.protocol)&&(0==g.button||1==g.button))chrome.send("navigateToUrl",[e.href,e.target,g.button,g.altKey,g.ctrlKey,g.metaKey,g.shiftKey]),g.preventDefault()}}});function appendParam(g,e,c){e=encodeURIComponent(e)+"="+encodeURIComponent(c);return-1==g.indexOf("?")?g+"?"+e:g+"&"+e};cr.define("tracing",function(){var g=cr.ui.define("div");g.prototype={__proto__:HTMLDivElement.prototype,decorate:function(){this.classList.add("overlay-root");this.visible=!1;this.contentHost=this.ownerDocument.createElement("div");this.contentHost.classList.add("content-host");this.tabCatcher=this.ownerDocument.createElement("span");this.tabCatcher.tabIndex=0;this.appendChild(this.contentHost);this.onKeydownBoundToThis_=this.onKeydown_.bind(this);this.onFocusInBoundToThis_=this.onFocusIn_.bind(this);
+this.addEventListener("mousedown",this.onMousedown_.bind(this))},showOverlay:function(c){c.oldParent_=c.parentNode;this.contentHost.appendChild(c);this.contentHost.appendChild(this.tabCatcher);this.ownerDocument.body.classList.add("disabled-by-overlay");this.visible=!0;c.tabIndex=0;var f=c.querySelector("button, input, list, select, a");f||(f=c);f.focus();this.ownerDocument.addEventListener("focusin",this.onFocusInBoundToThis_,!0);c.addEventListener("keydown",this.onKeydownBoundToThis_)},onMousedown_:function(c){c.target==
+this&&c.preventDefault()},onFocusIn_:function(c){c.target==this.tabCatcher&&window.setTimeout(this.focusOverlay_.bind(this),0)},focusOverlay_:function(){this.contentHost.firstChild.focus()},onKeydown_:function(c){9==c.keyCode&&(c.shiftKey&&c.target==this.contentHost.firstChild)&&c.preventDefault()},hideOverlay:function(c){this.visible=!1;this.ownerDocument.body.classList.remove("disabled-by-overlay");this.lastFocusOut_=void 0;c.parentNode.removeChild(this.tabCatcher);c.oldParent_?(c.oldParent_.appendChild(c),
+delete c.oldParent_):this.contentHost.removeChild(c);c.removeEventListener("keydown",this.onKeydownBoundToThis_);this.ownerDocument.removeEventListener("focusin",this.onFocusInBoundToThis_)}};cr.defineProperty(g,"visible",cr.PropertyKind.BOOL_ATTR);var e=cr.ui.define("div");e.prototype={__proto__:HTMLDivElement.prototype,decorate:function(){if(!this.ownerDocument.querySelector(".overlay-root")){var c=this.ownerDocument.createElement("div");cr.ui.decorate(c,g);this.ownerDocument.body.appendChild(c)}this.classList.add("overlay");
+this.visible=!1},onVisibleChanged_:function(){var c=this.ownerDocument.querySelector(".overlay-root");this.visible?c.showOverlay(this):c.hideOverlay(this)}};cr.defineProperty(e,"visible",cr.PropertyKind.BOOL_ATTR,e.prototype.onVisibleChanged_);return{Overlay:e}});cr.define("tracing",function(){function g(){this.overlay_=document.createElement("div");this.overlay_.className="tracing-overlay";cr.ui.decorate(this.overlay_,tracing.Overlay);this.statusDiv_=document.createElement("div");this.overlay_.appendChild(this.statusDiv_);this.bufferPercentDiv_=document.createElement("div");this.overlay_.appendChild(this.bufferPercentDiv_);this.stopButton_=document.createElement("button");this.stopButton_.onclick=this.endTracing.bind(this);this.stopButton_.textContent="Stop tracing";
+this.overlay_.appendChild(this.stopButton_);this.traceEvents_=[];this.systemTraceEvents_=[];this.onKeydownBoundToThis_=this.onKeydown_.bind(this);this.onKeypressBoundToThis_=this.onKeypress_.bind(this);chrome.send("tracingControllerInitialized")}g.prototype={__proto__:cr.EventTarget.prototype,gpuInfo_:void 0,clientInfo_:void 0,tracingEnabled_:!1,tracingEnding_:!1,systemTraceDataFilename_:void 0,onRequestBufferPercentFullComplete:function(e){this.overlay_.visible&&(window.setTimeout(this.beginRequestBufferPercentFull_.bind(this),
+250),this.bufferPercentDiv_.textContent="Buffer usage: "+Math.round(100*e)+"%")},beginRequestBufferPercentFull_:function(){chrome.send("beginRequestBufferPercentFull")},beginTracing:function(e){if(this.tracingEnabled_)throw Error("Tracing already begun.");this.stopButton_.hidden=!1;this.statusDiv_.textContent="Tracing active.";this.tracingEnabled_=this.overlay_.visible=!0;console.log("Beginning to trace...");this.statusDiv_.textContent="Tracing active.";this.traceEvents_=[];this.systemTraceEvents_=
+[];chrome.send("beginTracing",[e||!1]);this.beginRequestBufferPercentFull_();e=new cr.Event("traceBegun");e.events=this.traceEvents_;this.dispatchEvent(e);e=new cr.Event("traceEventsChanged");e.numEvents=this.traceEvents_.length;this.dispatchEvent(e);window.addEventListener("keypress",this.onKeypressBoundToThis_);window.addEventListener("keydown",this.onKeydownBoundToThis_)},onKeydown_:function(e){27==e.keyCode&&this.endTracing()},onKeypress_:function(e){"Enter"==e.keyIdentifier&&this.endTracing()},
+onClientInfoUpdate:function(e){this.clientInfo_=e},onGpuInfoUpdate:function(e){this.gpuInfo_=e},get isTracingEnabled(){return this.tracingEnabled_},get traceEvents(){return this.traceEvents_},onTraceDataCollected:function(e){this.statusDiv_.textContent="Processing trace...";this.traceEvents_.push.apply(this.traceEvents_,e)},endTracing:function(){if(!this.tracingEnabled_)throw Error("Tracing not begun.");this.tracingEnding_||(this.tracingEnding_=!0,this.statusDiv_.textContent="Ending trace...",console.log("Finishing trace"),
+this.statusDiv_.textContent="Downloading trace data...",this.stopButton_.hidden=!0,window.setTimeout(function(){chrome.send("endTracingAsync")},100))},onEndTracingComplete:function(){window.removeEventListener("keydown",this.onKeydownBoundToThis_);window.removeEventListener("keypress",this.onKeypressBoundToThis_);this.tracingEnding_=this.tracingEnabled_=this.overlay_.visible=!1;console.log("onEndTracingComplete p1 with "+this.traceEvents_.length+" events.");var e=new cr.Event("traceEnded");e.events=
+this.traceEvents_;this.dispatchEvent(e)},onSystemTraceDataCollected:function(e){console.log("onSystemTraceDataCollected with "+e.length+" chars of data.");this.systemTraceEvents_=e},get systemTraceEvents(){return this.systemTraceEvents_},beginLoadTraceFile:function(){chrome.send("loadTraceFile")},onLoadTraceFileComplete:function(e){e.traceEvents?this.traceEvents_=e.traceEvents:e.length?this.traceEvents_=e:console.log("Expected an array when loading the trace file");e.systemTraceEvents?this.systemTraceEvents_=
+e.systemTraceEvents:e.length?this.systemTraceEvents_=e:console.log("Expected an array when loading the trace file");e=new cr.Event("loadTraceFileComplete");e.events=this.traceEvents_;this.dispatchEvent(e)},onLoadTraceFileCanceled:function(){cr.dispatchSimpleEvent(this,"loadTraceFileCanceled")},beginSaveTraceFile:function(){chrome.send("saveTraceFile",[JSON.stringify({traceEvents:this.traceEvents_,systemTraceEvents:this.systemTraceEvents_,clientInfo:this.clientInfo_,gpuInfo:this.gpuInfo_})])},onSaveTraceFileComplete:function(){cr.dispatchSimpleEvent(this,
+"saveTraceFileComplete")},onSaveTraceFileCanceled:function(){cr.dispatchSimpleEvent(this,"saveTraceFileCanceled")},selfTest:function(){this.beginTracing();window.setTimeout(this.endTracing.bind(This),500)}};return{TracingController:g}});cr.define("tracing",function(){function g(a,b,d,c,f){this.title=a;this.start=d;this.colorId=b;this.args=c;this.didNotFinish=!1;void 0!==f&&(this.duration=f)}function e(a,b,d,c,f){g.call(this,a,b,d,c,f);this.subSlices=[]}function c(a,b,d,c){g.call(this,a,b,d,c)}function f(a,b){if(!a)throw"Parent must be provided.";this.parent=a;this.tid=b;this.subRows=[[]];this.asyncSlices=new d(this.ptid)}function h(a,b,d){this.parent=a;this.id=b;this.name=d;this.seriesNames=[];this.seriesColors=[];this.timestamps=
+[];this.samples=[]}function a(a){this.pid=a;this.threads={};this.counters={}}function b(a){this.cpuNumber=a;this.slices=[];this.counters={}}function d(a){this.name=a;this.slices=[]}function m(a){for(var b=0,d=0;d<a.length;++d)b=(b+37*b+11*a.charCodeAt(d))%4294967295;return b}function i(a,b){this.cpus={};this.processes={};this.importErrors=[];this.asyncSliceGroups={};a&&this.importEvents(a,b)}function j(){}function k(a){this.text_=a}g.prototype={selected:!1,duration:void 0,get end(){return this.start+
+this.duration}};e.prototype={__proto__:g.prototype};c.prototype={__proto__:g.prototype,id:void 0,startThread:void 0,endThread:void 0,subSlices:void 0};var l={};f.getPTIDFromPidAndTid=function(a,b){l[a]||(l[a]={});l[a][b]||(l[a][b]=a+":"+b);return l[a][b]};f.prototype={name:void 0,get ptid(){return f.getPTIDFromPidAndTid(this.tid,this.parent.pid)},getSubrow:function(a){for(;a>=this.subRows.length;)this.subRows.push([]);return this.subRows[a]},shiftSubRow_:function(a,b){for(var d=0;d<a.length;d++){var c=
+a[d];c.start+=b}},shiftTimestampsForward:function(a){this.cpuSlices&&this.shiftSubRow_(this.cpuSlices,a);for(var b=0;b<this.subRows.length;b++)this.shiftSubRow_(this.subRows[b],a);this.asyncSlices.shiftTimestampsForward(a)},updateBounds:function(){var a=[],b;0!=this.subRows[0].length&&(b=this.subRows[0],a.push(b[0].start),a.push(b[b.length-1].end));this.asyncSlices.slices.length&&(this.asyncSlices.updateBounds(),a.push(this.asyncSlices.minTimestamp),a.push(this.asyncSlices.maxTimestamp));a.length?
+(this.minTimestamp=Math.min.apply(Math,a),this.maxTimestamp=Math.max.apply(Math,a)):this.maxTimestamp=this.minTimestamp=void 0},get userFriendlyName(){return this.parent.pid+": "+(this.name||this.tid)},get userFriendlyDetails(){return"pid: "+this.parent.pid+", tid: "+this.tid+(this.name?", name: "+this.name:"")}};f.compare=function(b,d){if(b.parent.pid!=d.parent.pid)return a.compare(b.parent,d.parent.pid);if(b.name&&d.name){var c=b.name.localeCompare(d.name);return 0==c?b.tid-d.tid:c}return b.name?
+-1:d.name?1:b.tid-d.tid};h.prototype={__proto__:Object.prototype,get numSeries(){return this.seriesNames.length},get numSamples(){return this.timestamps.length},shiftTimestampsForward:function(a){for(var b=0;b<this.timestamps.length;b++)this.timestamps[b]+=a},updateBounds:function(){if(this.seriesNames.length!=this.seriesColors.length)throw"seriesNames.length must match seriesColors.length";if(this.numSeries*this.numSamples!=this.samples.length)throw"samples.length must be a multiple of numSamples.";
+this.totals=[];if(0==this.samples.length)this.maxTimestamp=this.minTimestamp=void 0,this.maxTotal=0;else{this.minTimestamp=this.timestamps[0];this.maxTimestamp=this.timestamps[this.timestamps.length-1];for(var a=this.numSeries,b=-Infinity,d=0;d<this.timestamps.length;d++){for(var c=0,f=0;f<a;f++)c+=this.samples[d*a+f],this.totals.push(c);c>b&&(b=c)}this.maxTotal=b}}};h.compare=function(b,d){if(b.parent.pid!=d.parent.pid)return a.compare(b.parent,d.parent.pid);var c=b.name.localeCompare(d.name);return 0==
+c?b.tid-d.tid:c};a.prototype={get numThreads(){var a=0,b;for(b in this.threads)a++;return a},shiftTimestampsForward:function(a){for(var b in this.threads)this.threads[b].shiftTimestampsForward(a);for(var d in this.counters)this.counters[d].shiftTimestampsForward(a)},getOrCreateThread:function(a){this.threads[a]||(this.threads[a]=new f(this,a));return this.threads[a]},getOrCreateCounter:function(a,b){var d=a+"."+b;this.counters[d]||(this.counters[d]=new h(this,d,b));return this.counters[d]}};a.compare=
+function(a,b){return a.pid-b.pid};b.prototype={getOrCreateCounter:function(a,b){var d;d=a.length?a+"."+b:b;this.counters[d]||(this.counters[d]=new h(this,d,b));return this.counters[d]},shiftTimestampsForward:function(a){for(var b=0;b<this.slices.length;b++)this.slices[b].start+=a;for(var d in this.counters)this.counters[d].shiftTimestampsForward(a)},updateBounds:function(){this.slices.length?(this.minTimestamp=this.slices[0].start,this.maxTimestamp=this.slices[this.slices.length-1].end):this.maxTimestamp=
+this.minTimestamp=void 0}};b.compare=function(a,b){return a.cpuNumber-b.cpuNumber};d.prototype={__proto__:Object.prototype,push:function(a){this.slices.push(a)},get length(){return this.slices.length},subRows_:void 0,sortSlices_:function(){this.slices.sort(function(a,b){return a.start-b.start})},shiftTimestampsForward:function(a){for(var b=0;b<this.slices.length;b++){var d=this.slices[b];d.start+=a;for(var c=0;c<d.subSlices.length;c++)d.subSlices[c].start+=a}},updateBounds:function(){this.sortSlices_();
+this.slices.length?(this.minTimestamp=this.slices[0].start,this.maxTimestamp=this.slices[this.slices.length-1].end):this.maxTimestamp=this.minTimestamp=void 0;this.subRows_=void 0},get subRows(){this.subRows_||this.rebuildSubRows_();return this.subRows_},rebuildSubRows_:function(){this.sortSlices_();for(var a=[],b=0;b<this.slices.length;b++){for(var d=this.slices[b],c=!1,f=0;f<a.length;f++){var e=a[f];if(d.start>=e[e.length-1].end){c=!0;if(void 0===d.subSlices||1>d.subSlices.length)throw"TimelineAsyncEvent missing subSlices: "+
+d.name;for(f=0;f<d.subSlices.length;f++)e.push(d.subSlices[f]);break}}if(!c&&(e=[],void 0!==d.subSlices)){for(f=0;f<d.subSlices.length;f++)e.push(d.subSlices[f]);a.push(e)}}this.subRows_=a},computeSubGroups:function(){for(var a={},b=0;b<this.slices.length;++b){var c=this.slices[b],f=c.startThread.ptid;a[f]||(a[f]=new d(this.name));a[f].slices.push(c)}var b=[],e;for(e in a)c=a[e],c.updateBounds(),b.push(c);return b}};h.compare=function(b,d){if(b.parent.pid!=d.parent.pid)return a.compare(b.parent,d.parent.pid);
+var c=b.name.localeCompare(d.name);return 0==c?b.tid-d.tid:c};var o=[{r:138,g:113,b:152},{r:175,g:112,b:133},{r:127,g:135,b:225},{r:93,g:81,b:137},{r:116,g:143,b:119},{r:178,g:214,b:122},{r:87,g:109,b:147},{r:119,g:155,b:95},{r:114,g:180,b:160},{r:132,g:85,b:103},{r:157,g:210,b:150},{r:148,g:94,b:86},{r:164,g:108,b:138},{r:139,g:191,b:150},{r:110,g:99,b:145},{r:80,g:129,b:109},{r:125,g:140,b:149},{r:93,g:124,b:132},{r:140,g:85,b:140},{r:104,g:163,b:162},{r:132,g:141,b:178},{r:131,g:105,b:147},{r:135,
+g:183,b:98},{r:152,g:134,b:177},{r:141,g:188,b:141},{r:133,g:160,b:210},{r:126,g:186,b:148},{r:112,g:198,b:205},{r:180,g:122,b:195},{r:203,g:144,b:152},{r:182,g:125,b:143},{r:126,g:200,b:148},{r:133,g:160,b:210},{r:240,g:240,b:240}],q=o.length-4,u=o.length,v=o.concat(o.map(function(a){var b;b=240<=a.r&&240<=a.g&&240<=a.b?-0.2:0.45;return{r:Math.min(255,a.r+Math.floor(a.r*b)),g:Math.min(255,a.g+Math.floor(a.g*b)),b:Math.min(255,a.b+Math.floor(a.b*b))}})).map(function(a){return"rgb("+a.r+","+a.g+","+
+a.b+")"}),t={},y=[];i.registerImporter=function(a){y.push(a)};j.canImport=function(a){return a instanceof Array&&0==a.length?!0:"string"===typeof a||a instanceof String?0==a.length:!1};j.prototype={__proto__:Object.prototype,importEvents:function(){},finalizeImport:function(){}};i.registerImporter(j);i.prototype={__proto__:cr.EventTarget.prototype,get numProcesses(){var a=0,b;for(b in this.processes)a++;return a},getOrCreateCpu:function(a){this.cpus[a]||(this.cpus[a]=new b(a));return this.cpus[a]},
+getOrCreateProcess:function(b){this.processes[b]||(this.processes[b]=new a(b));return this.processes[b]},pruneEmptyThreads:function(){for(var a in this.processes){var b=this.processes[a],d={},c;for(c in b.threads){for(var f=b.threads[c],e=!1,q=0;q<f.subRows.length;q++)e|=0<f.subRows[q].length;if(e||0<f.asyncSlices.length)d[c]=f}b.threads=d}},updateBounds:function(){for(var a=Infinity,b=-a,d=!1,c=this.getAllThreads(),f=0;f<c.length;f++){var e=c[f];e.updateBounds();void 0!=e.minTimestamp&&void 0!=e.maxTimestamp&&
+(a=Math.min(a,e.minTimestamp),b=Math.max(b,e.maxTimestamp),d=!0)}c=this.getAllCounters();for(f=0;f<c.length;f++)e=c[f],e.updateBounds(),void 0!=e.minTimestamp&&void 0!=e.maxTimestamp&&(d=!0,a=Math.min(a,e.minTimestamp),b=Math.max(b,e.maxTimestamp));for(var q in this.cpus)f=this.cpus[q],f.updateBounds(),void 0!=f.minTimestamp&&void 0!=f.maxTimestamp&&(d=!0,a=Math.min(a,f.minTimestamp),b=Math.max(b,f.maxTimestamp));d?(this.minTimestamp=a,this.maxTimestamp=b):this.minTimestamp=this.maxTimestamp=void 0},
+shiftWorldToZero:function(){if(void 0!==this.minTimestamp){var a=this.minTimestamp,b;for(b in this.processes)this.processes[b].shiftTimestampsForward(-a);for(var d in this.cpus)this.cpus[d].shiftTimestampsForward(-a);this.updateBounds()}},getAllThreads:function(){var a=[],b;for(b in this.processes){var d=this.processes[b],c;for(c in d.threads)a.push(d.threads[c])}return a},getAllCpus:function(){var a=[],b;for(b in this.cpus)a.push(this.cpus[b]);return a},getAllProcesses:function(){var a=[],b;for(b in this.processes)a.push(this.processes[b]);
+return a},getAllCounters:function(){var a=[],b;for(b in this.processes){var d=this.processes[b],c;for(c in d.counters)a.push(d.counters[c])}for(var f in this.cpus){b=this.cpus[f];for(var e in b.counters)a.push(b.counters[e])}return a},importOneTrace_:function(a,b){for(var d,c=0;c<y.length;++c)if(y[c].canImport(a)){d=y[c];break}if(!d)throw"Could not find an importer for the provided eventData.";d=new d(this,a,b);d.importEvents();return d},importEvents:function(a,b,d){void 0===b&&(b=!0);var c=[],a=
+this.importOneTrace_(a,!1);c.push(a);if(d)for(var f=0;f<d.length;++f)a=this.importOneTrace_(d[f],!0),c.push(a);for(f=0;f<c.length;++f)c[f].finalizeImport();for(f=0;f<c.length;++f)this.pruneEmptyThreads();this.updateBounds();b&&this.shiftWorldToZero();b&&(void 0!==this.minTimestamp&&void 0!==this.maxTimestamp)&&(b=0.15*(this.maxTimestamp-this.minTimestamp),this.minTimestamp-=b,this.maxTimestamp+=b)}};k.prototype={__proto__:Object.prototype,matchSlice:function(a){return 0==this.text_.length?!1:-1!=
+a.title.indexOf(this.text_)}};return{getPallette:function(){return v},getPalletteHighlightIdBoost:function(){return u},getColorIdByName:function(a){if("iowait"==a)return q;if("running"==a)return q+1;if("runnable"==a)return q+2;if("sleeping"==a)return q+3;throw"Unrecognized color "+a;},getStringHash:m,getStringColorId:function(a){if(void 0===t[a]){var b=m(a);t[a]=b%q}return t[a]},TimelineSlice:g,TimelineThreadSlice:e,TimelineAsyncSlice:c,TimelineThread:f,TimelineCounter:h,TimelineProcess:a,TimelineCpu:b,
+TimelineAsyncSliceGroup:d,TimelineModel:i,TimelineFilter:k}});cr.define("tracing",function(){function g(a){this.cpu=a}function e(){this.openSlices=[]}function c(a,b,d){this.isAdditionalImport_=d;this.model_=a;this.events_=b;this.clockSyncRecords_=[];this.cpuStates_={};this.kernelThreadStates_={};this.buildMapFromLinuxPidsToTimelineThreads();this.lineNumber=-1;this.threadStateByKPID_={}}g.prototype={__proto__:Object.prototype,switchRunningLinuxPid:function(a,b,d,c,f,e){if(void 0!==this.lastActivePid&&0!=this.lastActivePid){var h=d-this.lastActiveTs;name=(a=a.threadsByLinuxPid[this.lastActivePid])?
+a.userFriendlyName:this.lastActiveComm;this.cpu.slices.push(new tracing.TimelineSlice(name,tracing.getStringColorId(name),this.lastActiveTs,{comm:this.lastActiveComm,tid:this.lastActivePid,prio:this.lastActivePrio,stateWhenDescheduled:b},h))}this.lastActiveTs=d;this.lastActivePid=c;this.lastActiveComm=f;this.lastActivePrio=e}};TestExports={};var f=/^\s*(.+?)\s+\[(\d+)\]\s*([d.][N.][sh.][\d.])?\s*(\d+\.\d+):\s+(\S+):\s(.*)$/;TestExports.lineRE=f;var h=/trace_event_clock_sync: parent_ts=(\d+\.?\d*)/;
+TestExports.traceEventClockSyncRE=h;c.canImport=function(a){if(!("string"===typeof a||a instanceof String))return!1;if(/^# tracer:/.exec(a))return!0;var b=/^(.+)\n/.exec(a);b&&(a=b[1]);return f.exec(a)?!0:!1};c.prototype={__proto__:Object.prototype,buildMapFromLinuxPidsToTimelineThreads:function(){this.threadsByLinuxPid={};this.model_.getAllThreads().forEach(function(a){this.threadsByLinuxPid[a.tid]=a}.bind(this))},getOrCreateCpuState:function(a){if(!this.cpuStates_[a]){var b=this.model_.getOrCreateCpu(a);
+this.cpuStates_[a]=new g(b)}return this.cpuStates_[a]},parsePid:function(a){a=/.+-(\d+)/.exec(a)[1];return a=parseInt(a)},parseThreadName:function(a){return/(.+)-\d+/.exec(a)[1]},getOrCreateKernelThread:function(a,b,d){this.kernelThreadStates_[a]||(void 0==b&&(b=this.parsePid(a)),void 0==d&&(d=b),d=this.model_.getOrCreateProcess(b).getOrCreateThread(d),d.name=a,this.kernelThreadStates_[a]={pid:b,thread:d,openSlice:void 0,openSliceTS:void 0},this.threadsByLinuxPid[b]=d);return this.kernelThreadStates_[a]},
+importEvents:function(){this.importCpuData();this.alignClocks()&&this.buildPerThreadCpuSlicesFromCpuState()},finalizeImport:function(){},buildPerThreadCpuSlicesFromCpuState:function(){for(var a in this.cpuStates_)for(var b=this.cpuStates_[a].cpu,d=0;d<b.slices.length;d++){var c=b.slices[d],f=this.threadsByLinuxPid[c.args.tid];f&&(f.tempCpuSlices||(f.tempCpuSlices=[]),c.index=d,f.tempCpuSlices.push(c))}var e=tracing.getColorIdByName("running"),h=tracing.getColorIdByName("runnable"),g=tracing.getColorIdByName("sleeping"),
+o=tracing.getColorIdByName("iowait");this.model_.getAllThreads().forEach(function(a){if(a.tempCpuSlices){var b=a.tempCpuSlices;delete a.tempCpuSlices;b.sort(function(a,b){var d=a.start-b.start;return 0==d?a.index-b.index:d});var d=[];if(b.length){var c=b[0];d.push(new tracing.TimelineSlice("Running",e,c.start,{},c.duration))}for(c=1;c<b.length;c++){var f=b[c-1],m=b[c],i=m.start-f.end;if("S"==f.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Sleeping",g,f.end,{},i));else if("R"==f.args.stateWhenDescheduled||
+"R+"==f.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Runnable",h,f.end,{},i));else if("D"==f.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Uninterruptible Sleep",o,f.end,{},i));else if("T"==f.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("__TASK_STOPPED",o,f.end,{},i));else if("t"==f.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("debug",o,f.end,{},i));else if("Z"==f.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Zombie",o,f.end,{},
+i));else if("X"==f.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Exit Dead",o,f.end,{},i));else if("x"==f.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Task Dead",o,f.end,{},i));else if("W"==f.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("WakeKill",o,f.end,{},i));else if("D|W"==f.args.stateWhenDescheduled)d.push(new tracing.TimelineSlice("Uninterruptable Sleep | WakeKill",o,f.end,{},i));else throw"Unrecognized state: "+f.args.stateWhenDescheduled;d.push(new tracing.TimelineSlice("Running",
+e,m.start,{},m.duration))}a.cpuSlices=d}})},alignClocks:function(){if(0==this.clockSyncRecords_.length){if(!this.isAdditionalImport_)return;this.abortImport();return!1}var a=this.clockSyncRecords_[0];if(0==a.parentTS||a.parentTS==a.perfTS)return!0;var a=a.parentTS-a.perfTS,b;for(b in this.cpuStates_){for(var d=this.cpuStates_[b].cpu,c=0;c<d.slices.length;c++){var f=d.slices[c];f.start+=a;f.duration=f.duration}for(var e in d.counters){c=d.counters[e];for(f=0;f<c.timestamps.length;f++)c.timestamps[f]+=
+a}}for(var h in this.kernelThreadStates_){b=this.kernelThreadStates_[h].thread;for(c=0;c<b.subRows[0].length;c++)b.subRows[0][c].start+=a}return!0},abortImport:function(){if(this.pushedEventsToThreads)throw"Cannot abort, have alrady pushedCpuDataToThreads.";for(var a in this.cpuStates_)delete this.model_.cpus[a];for(var b in this.kernelThreadStates_){a=this.kernelThreadStates_[b].thread;var d=a.parent;delete d.threads[a.tid];delete this.model_.processes[d.pid]}this.model_.importErrors.push("Cannot import kernel trace without a clock sync.")},
+markPidRunnable:function(){},importError:function(a){this.model_.importErrors.push("Line "+(this.lineNumber+1)+": "+a)},malformedEvent:function(a){this.importError("Malformed "+a+" event")},openSlice:function(a,b,d){a.openSliceTS=d;a.openSlice=b},closeSlice:function(a,b,d){a.openSlice&&(b=new tracing.TimelineSlice(a.openSlice,tracing.getStringColorId(a.openSlice),a.openSliceTS,d,b-a.openSliceTS),a.thread.subRows[0].push(b),a.openSlice=void 0)},getThreadState:function(a){return this.threadStateByKPID_[this.parsePid(a)]},
+getOrCreateThreadState:function(a,b){var d=this.parsePid(a),c=this.threadStateByKPID_[d];c||(c=new e,c.threadName=this.parseThreadName(a),c.tid=d,c.pid=b,c.thread=this.model_.getOrCreateProcess(b).getOrCreateThread(d),c.thread.name||(c.thread.name=c.threadName),this.threadStateByKPID_[d]=c);return c},processBegin:function(a,b,d,c){a=this.getOrCreateThreadState(a,c);c=tracing.getStringColorId(b);b=new tracing.TimelineThreadSlice(b,c,d,null);a.openSlices.push(b)},processEnd:function(a,b){var d=this.getThreadState(a);
+if(d&&0!=d.openSlices.length){var c=d.openSlices.pop();c.duration=b-c.start;d.thread.getSubrow(d.openSlices.length).push(c);d.openSlices.length&&d.openSlices[d.openSlices.length-1].subSlices.push(c)}},autoCloseOpenSlices:function(){this.model_.updateBounds();var a=[],b;for(b in this.threadStateByKPID_)for(var d=this.threadStateByKPID_[b],c=0;c<d.openSlices.length;c++){var f=d.openSlices[c];a.push(f.start);for(var e=0;e<f.subSlices.length;e++){var h=f.subSlices[e];a.push(h.start);h.duration&&a.push(h.end)}}a=
+this.model_.maxTimestamp?Math.max(this.model_.maxTimestamp,Math.max.apply(Math,a)):Math.max.apply(Math,a);for(b in this.threadStateByKPID_)for(d=this.threadStateByKPID_[b];0<d.openSlices.length;)f=d.openSlices.pop(),f.duration=a-f.start,f.didNotFinish=!0,d.thread.getSubrow(d.openSlices.length).push(f),d.openSlices.length&&d.openSlices[d.openSlices.length-1].subSlices.push(f)},processCounter:function(a,b,d,c){a=this.model_.getOrCreateProcess(c).getOrCreateCounter("",a);0==a.numSeries&&(a.seriesNames.push("state"),
+a.seriesColors.push(tracing.getStringColorId(a.name+".state")));a.timestamps.push(b);a.samples.push(d)},importCpuData:function(){this.lines_=this.events_.split("\n");for(this.lineNumber=0;this.lineNumber<this.lines_.length;++this.lineNumber){var a=this.lines_[this.lineNumber];if(!(/^#/.exec(a)||0==a.length)){var b=f.exec(a);if(b){var a=b[1],d=b[2],c=b[4],e=b[5],b=b[6],h=this.eventDefinitions[e];if(h){var g;if(h.format){if(g=h.format.exec(b),!g){this.malformedEvent(e);continue}}else g={};g.timestamp=
+1E3*parseFloat(c);g.name=e;g.info=b;g.taskId=a;g.cpuState=this.getOrCreateCpuState(parseInt(d));h.handler&&h.handler(this,g)}else console.log("unknown event "+e)}else this.importError("Unrecognized line: "+a)}}},eventDefinitions:{sched_switch:{format:RegExp("prev_comm=(.+) prev_pid=(\\d+) prev_prio=(\\d+) prev_state=(\\S+) ==> next_comm=(.+) next_pid=(\\d+) next_prio=(\\d+)"),handler:function(a,b){var d=b[4],c=b[5],f=parseInt(b[6]),e=parseInt(b[7]);b.cpuState.switchRunningLinuxPid(a,d,b.timestamp,
+f,c,e)}},sched_wakeup:{format:/comm=(.+) pid=(\d+) prio=(\d+) success=(\d+) target_cpu=(\d+)/,handler:function(a,b){var d=b[1],c=parseInt(b[2]),f=parseInt(b[3]);a.markPidRunnable(b.timestamp,c,d,f)}},power_start:{format:/type=(\d+) state=(\d) cpu_id=(\d)+/,handler:function(a,b){var d=parseInt(b[3]),d=a.getOrCreateCpuState(d);if("1"==b[1]){d=d.cpu.getOrCreateCounter("","C-State");0==d.numSeries&&(d.seriesNames.push("state"),d.seriesColors.push(tracing.getStringColorId(d.name+".state")));var c=parseInt(b[2]);
+d.timestamps.push(b.timestamp);d.samples.push(c)}else a.importError("Don't understand power_start events of type "+b[1])}},power_frequency:{format:/type=(\d+) state=(\d+) cpu_id=(\d)+/,handler:function(a,b){var d=parseInt(b[3]),d=a.getOrCreateCpuState(d).cpu.getOrCreateCounter("","Power Frequency");0==d.numSeries&&(d.seriesNames.push("state"),d.seriesColors.push(tracing.getStringColorId(d.name+".state")));var c=parseInt(b[2]);d.timestamps.push(b.timestamp);d.samples.push(c)}},cpu_frequency:{format:/state=(\d+) cpu_id=(\d)+/,
+handler:function(a,b){var d=parseInt(b[2]),d=a.getOrCreateCpuState(d).cpu.getOrCreateCounter("","Clock Frequency");0==d.numSeries&&(d.seriesNames.push("state"),d.seriesColors.push(tracing.getStringColorId(d.name+".state")));var c=parseInt(b[1]);d.timestamps.push(b.timestamp);d.samples.push(c)}},cpu_idle:{format:/state=(\d+) cpu_id=(\d)+/,handler:function(a,b){var d=parseInt(b[2]),d=a.getOrCreateCpuState(d).cpu.getOrCreateCounter("","C-State");0==d.numSeries&&(d.seriesNames.push("state"),d.seriesColors.push(tracing.getStringColorId(d.name)));
+var c=parseInt(b[1]);4294967295!=c?d.samples.push(c):d.samples.push(0);d.timestamps.push(b.timestamp)}},workqueue_execute_start:{format:/work struct (.+): function (\S+)/,handler:function(a,b){var d=a.getOrCreateKernelThread(b.taskId);a.openSlice(d,b[2],b.timestamp)}},workqueue_execute_end:{format:/work struct (.+)/,handler:function(a,b){var d=a.getOrCreateKernelThread(b.taskId);a.closeSlice(d,b.timestamp,{})}},workqueue_queue_work:{},workqueue_activate_work:{},i915_gem_object_pwrite:{format:/obj=(.+), offset=(\d+), len=(\d+)/,
+handler:function(a,b){var d=b[1],c=parseInt(b[2]),f=parseInt(b[3]),e=a.getOrCreateKernelThread("i915_gem",0,1);a.openSlice(e,"pwrite:"+d,b.timestamp);a.closeSlice(e,b.timestamp,{obj:d,offset:c,len:f})}},i915_flip_request:{format:/plane=(\d+), obj=(.+)/,handler:function(a,b){var d=parseInt(b[1]),c=b[2],f=a.getOrCreateKernelThread("i915_flip",0,2);a.openSlice(f,"flip:"+c+"/"+d,b.timestamp)}},i915_flip_complete:{format:/plane=(\d+), obj=(.+)/,handler:function(a,b){var d=parseInt(b[1]),c=b[2],f=a.getOrCreateKernelThread("i915_flip",
+0,2);a.closeSlice(f,b.timestamp,{obj:c,plane:d})}},tracing_mark_write:{handler:function(a,b){var d=h.exec(b.info);if(d)a.clockSyncRecords_.push({perfTS:b.timestamp,parentTS:1E3*d[1]});else switch(d=b.info.split("|"),d[0]){case "B":var c=parseInt(d[1]),f=d[2];a.processBegin(b.taskId,f,b.timestamp,c);break;case "E":a.processEnd(b.taskId,b.timestamp);break;case "C":c=parseInt(d[1]);f=d[2];d=parseInt(d[3]);a.processCounter(f,b.timestamp,d,c);break;default:a.malformedEvent(b.name)}}}}};c.prototype.eventDefinitions["0"]=
+c.prototype.eventDefinitions.tracing_mark_write;TestExports.eventDefinitions=c.prototype.eventDefinitions;tracing.TimelineModel.registerImporter(c);return{LinuxPerfImporter:c,_LinuxPerfImporterTestExports:TestExports}});cr.define("tracing",function(){function g(){this.openSlices=[]}function e(c,f){this.model_=c;"string"===typeof f||f instanceof String?("["==f[0]&&(n=f.length,"]"!=f[n-1]&&"\n"!=f[n-1]?f+="]":"]"!=f[n-2]&&"\n"==f[n-1]?f+="]":"]"!=f[n-3]&&("\r"==f[n-2]&&"\n"==f[n-1])&&(f+="]")),this.events_=JSON.parse(f)):this.events_=f;this.events_.traceEvents&&(this.events_=this.events_.traceEvents);this.threadStateByPTID_={};this.allAsyncEvents_=[]}e.canImport=function(c){return"string"===typeof c||c instanceof String?
+"{"==c[0]||"["==c[0]:c instanceof Array&&c.length&&c[0].ph?!0:c.traceEvents?c.traceEvents instanceof Array&&c.traceEvents[0].ph:!1};e.prototype={__proto__:Object.prototype,processBeginEvent:function(c,f,e){var a=tracing.getStringColorId(e.name),c={index:c,slice:new tracing.TimelineThreadSlice(e.name,a,e.ts/1E3,e.args)};e.uts&&(c.slice.startInUserTime=e.uts/1E3);"0"===e.args["ui-nest"]?this.model_.importErrors.push("ui-nest no longer supported."):f.openSlices.push(c)},processEndEvent:function(c,f){if("0"===
+f.args["ui-nest"])this.model_.importErrors.push("ui-nest no longer supported.");else if(0!=c.openSlices.length){var e=c.openSlices.pop().slice;e.duration=f.ts/1E3-e.start;f.uts&&(e.durationInUserTime=f.uts/1E3-e.startInUserTime);for(var a in f.args)e.args[a]=f.args[a];this.model_.getOrCreateProcess(f.pid).getOrCreateThread(f.tid).getSubrow(c.openSlices.length).push(e);c.openSlices.length&&c.openSlices[c.openSlices.length-1].slice.subSlices.push(e)}},processAsyncEvent:function(c,f,e){c=this.model_.getOrCreateProcess(e.pid).getOrCreateThread(e.tid);
+this.allAsyncEvents_.push({event:e,thread:c})},autoCloseOpenSlices:function(){this.model_.updateBounds();var c=[],f;for(f in this.threadStateByPTID_)for(var e=this.threadStateByPTID_[f],a=0;a<e.openSlices.length;a++){var b=e.openSlices[a];c.push(b.slice.start);for(var d=0;d<b.slice.subSlices.length;d++){var g=b.slice.subSlices[d];c.push(g.start);g.duration&&c.push(g.end)}}c=this.model_.maxTimestamp?Math.max(this.model_.maxTimestamp,Math.max.apply(Math,c)):Math.max.apply(Math,c);for(f in this.threadStateByPTID_)for(e=
+this.threadStateByPTID_[f];0<e.openSlices.length;)b=e.openSlices.pop(),b.slice.duration=c-b.slice.start,b.slice.didNotFinish=!0,a=this.events_[b.index],this.model_.getOrCreateProcess(a.pid).getOrCreateThread(a.tid).getSubrow(e.openSlices.length).push(b.slice),e.openSlices.length&&e.openSlices[e.openSlices.length-1].slice.subSlices.push(b.slice)},processCounterEvent:function(c){var f;f=void 0!==c.id?c.name+"["+c.id+"]":c.name;f=this.model_.getOrCreateProcess(c.pid).getOrCreateCounter(c.cat,f);if(0==
+f.numSeries){for(var e in c.args)f.seriesNames.push(e),f.seriesColors.push(tracing.getStringColorId(f.name+"."+e));if(0==f.numSeries){this.model_.importErrors.push("Expected counter "+c.name+" to have at least one argument to use as a value.");delete f.parent.counters[f.name];return}}f.timestamps.push(c.ts/1E3);for(var a=0;a<f.numSeries;a++)e=f.seriesNames[a],void 0===c.args[e]?f.samples.push(0):f.samples.push(c.args[e])},importEvents:function(){for(var c=this.events_,f=0;f<c.length;f++){var e=c[f],
+a=tracing.TimelineThread.getPTIDFromPidAndTid(e.pid,e.tid);a in this.threadStateByPTID_||(this.threadStateByPTID_[a]=new g);var b=this.threadStateByPTID_[a];"B"==e.ph?this.processBeginEvent(f,b,e):"E"==e.ph?this.processEndEvent(b,e):"S"==e.ph?this.processAsyncEvent(f,b,e):"F"==e.ph?this.processAsyncEvent(f,b,e):"T"==e.ph?this.processAsyncEvent(f,b,e):"I"==e.ph?(this.processBeginEvent(f,b,e),this.processEndEvent(b,e)):"C"==e.ph?this.processCounterEvent(e):"M"==e.ph?"thread_name"==e.name?this.model_.getOrCreateProcess(e.pid).getOrCreateThread(e.tid).name=
+e.args.name:this.model_.importErrors.push("Unrecognized metadata name: "+e.name):this.model_.importErrors.push("Unrecognized event phase: "+e.ph+"("+e.name+")")}c=!1;for(a in this.threadStateByPTID_)b=this.threadStateByPTID_[a],c|=0<b.openSlices.length;c&&this.autoCloseOpenSlices()},finalizeImport:function(){if(0!=this.allAsyncEvents_.length){this.allAsyncEvents_.sort(function(a,b){return a.event.ts-b.event.ts});for(var c={},f=this.allAsyncEvents_,e=0;e<f.length;e++){var a=f[e],b=a.event,d=b.name;
+if(void 0===d)this.model_.importErrors.push("Async events (ph: S, T or F) require an name parameter.");else{var g=b.id;if(void 0===g)this.model_.importErrors.push("Async events (ph: S, T or F) require an id parameter.");else if("S"==b.ph)void 0===c[d]&&(c[d]={}),c[d][g]?this.model_.importErrors.push("At "+b.ts+", an slice of the same id "+g+" was alrady open."):(c[d][g]=[],c[d][g].push(a));else if(void 0===c[d])this.model_.importErrors.push("At "+b.ts+", no slice named "+d+" was open.");else if(void 0===
+c[d][g])this.model_.importErrors.push("At "+b.ts+", no slice named "+d+" with id="+g+" was open.");else{var i=c[d][g];i.push(a);if("F"==b.ph){var j=new tracing.TimelineAsyncSlice(d,tracing.getStringColorId(d),i[0].event.ts/1E3);j.duration=b.ts/1E3-i[0].event.ts/1E3;j.startThread=i[0].thread;j.endThread=a.thread;j.id=g;j.args=i[0].event.args;j.subSlices=[];for(a=1;a<i.length;++a){var k=d;"T"==i[a-1].event.ph&&(k=d+":"+i[a-1].event.args.step);k=new tracing.TimelineAsyncSlice(k,tracing.getStringColorId(d+
+a),i[a-1].event.ts/1E3);k.duration=i[a].event.ts/1E3-i[a-1].event.ts/1E3;k.startThread=i[a-1].thread;k.endThread=i[a].thread;k.id=g;k.args=i[a-1].event.args;j.subSlices.push(k)}var i=j.subSlices[j.subSlices.length-1],l;for(l in b.args)i.args[l]=b.args[l];j.startThread.asyncSlices.push(j);delete c[d][g]}}}}}}};tracing.TimelineModel.registerImporter(e);return{TraceEventImporter:e}});cr.define("tracing",function(){function g(c,f,e){if(0==c.length)return 1;for(var a=0,b=c.length-1,d,g,i=-1;a<=b;)d=Math.floor((a+b)/2),g=f(c[d])-e,0>g?a=d+1:(0<g||(i=d),b=d-1);return-1!=i?i:a}function e(c,f,e,a,b,d){if(!(a>b)){var m=g(c,f,a);if(-1!=m&&(0<m&&f(c[m-1])+e(c[m-1])>=a&&d(c[m-1]),m!=c.length))for(e=c.length;m<e&&!(f(c[m])>=b);m++)d(c[m])}}return{findLowIndexInSortedArray:g,findLowIndexInSortedIntervals:function(c,f,e,a){var b=g(c,f,a);return 0==b?a>=f(c[0])&&a<f(c[0]+e(c[0]))?0:-1:b<=c.length&&
+a>=f(c[b-1])&&a<f(c[b-1])+e(c[b-1])?b-1:c.length},iterateOverIntersectingIntervals:e,getIntersectingIntervals:function(c,f,g,a,b){var d=[];e(c,f,g,a,b,function(a){d.push(a)});return d}}});cr.define("tracing",function(){function g(){var e=document.createElement("iframe");e.style.cssText="width:100%;height:0;border:0;visibility:hidden";document.body.appendChild(e);this._doc=e.contentDocument;this._window=e.contentWindow;this._doc.body.style.cssText="padding:0;margin:0;overflow:hidden";for(var e=document.querySelectorAll("link[rel=stylesheet]"),c=0;c<e.length;c++){var f=e[c],g=this._doc.createElement("link");g.rel="stylesheet";g.href=f.href;this._doc.head.appendChild(g)}}g.prototype=
+{__proto__:Object.prototype,measure:function(e){this._doc.body.appendChild(e);var c=this._window.getComputedStyle(e),f=parseInt(c.width,10),c=parseInt(c.height,10);this._doc.body.removeChild(e);return{width:f,height:c}}};return{MeasuringStick:g}});cr.define("tracing",function(){function g(a){this.parentEl_=a;this.scaleX_=1;this.gridTimebase_=this.panX_=0;this.gridStep_=1E3/60;this.hasCalledSetupFunction_=this.gridEnabled_=!1;this.onResizeBoundToThis_=this.onResize_.bind(this);this.checkForAttachInterval_=setInterval(this.checkForAttach_.bind(this),250)}function e(a,b){this.track=a;this.slice=b}function c(a,b,d){this.track=a;this.counter=b;this.sampleIndex=d}function f(){this.range_dirty_=!0;this.range_={};this.length_=0}g.prototype={__proto__:cr.EventTarget.prototype,
+setWhenPossible:function(a){this.pendingSetFunction_=a},get isAttachedToDocument_(){for(var a=this.parentEl_;a.parentNode;)a=a.parentNode;return a==this.parentEl_.ownerDocument},onResize_:function(){this.dispatchChangeEvent()},checkForAttach_:function(){if(this.isAttachedToDocument_&&0!=this.clientWidth){this.iframe_||(this.iframe_=document.createElement("iframe"),this.iframe_.style.cssText="position:absolute;width:100%;height:0;border:0;visibility:hidden;",this.parentEl_.appendChild(this.iframe_),
+this.iframe_.contentWindow.addEventListener("resize",this.onResizeBoundToThis_));var a=this.clientWidth+"x"+this.clientHeight;this.pendingSetFunction_&&(this.lastSize_=a,this.pendingSetFunction_(),this.pendingSetFunction_=void 0);window.clearInterval(this.checkForAttachInterval_);this.checkForAttachInterval_=void 0}},dispatchChangeEvent:function(){cr.dispatchSimpleEvent(this,"change")},detach:function(){this.checkForAttachInterval_&&(window.clearInterval(this.checkForAttachInterval_),this.checkForAttachInterval_=
+void 0);this.iframe_.removeEventListener("resize",this.onResizeBoundToThis_);this.parentEl_.removeChild(this.iframe_)},get scaleX(){return this.scaleX_},set scaleX(a){this.scaleX_!=a&&(this.scaleX_=a,this.dispatchChangeEvent())},get panX(){return this.panX_},set panX(a){this.panX_!=a&&(this.panX_=a,this.dispatchChangeEvent())},setPanAndScale:function(a,b){if(this.scaleX_!=b||this.panX_!=a)this.scaleX_=b,this.panX_=a,this.dispatchChangeEvent()},xWorldToView:function(a){return(a+this.panX_)*this.scaleX_},
+xWorldVectorToView:function(a){return a*this.scaleX_},xViewToWorld:function(a){return a/this.scaleX_-this.panX_},xViewVectorToWorld:function(a){return a/this.scaleX_},xPanWorldPosToViewPos:function(a,b,d){if("string"==typeof b)if("left"==b)b=0;else if("center"==b)b=d/2;else if("right"==b)b=d-1;else throw Error("unrecognized string for viewPos. left|center|right");this.panX=b/this.scaleX_-a},xPanWorldRangeIntoView:function(a,b,d){0>this.xWorldToView(a)?this.xPanWorldPosToViewPos(a,"left",d):this.xWorldToView(b)>
+d&&this.xPanWorldPosToViewPos(b,"right",d)},xSetWorldRange:function(a,b,d){this.setPanAndScale(-a,d/(b-a))},get gridEnabled(){return this.gridEnabled_},set gridEnabled(a){this.gridEnabled_!=a&&(this.gridEnabled_=a&&!0,this.dispatchChangeEvent())},get gridTimebase(){return this.gridTimebase_},set gridTimebase(a){this.gridTimebase_!=a&&(this.gridTimebase_=a,cr.dispatchSimpleEvent(this,"change"))},get gridStep(){return this.gridStep_},applyTransformToCanavs:function(a){a.transform(this.scaleX_,0,0,1,
+this.panX_*this.scaleX_,0)}};e.prototype={get selected(){return this.slice.selected},set selected(a){this.slice.selected=a}};c.prototype={get selected(){return!0==this.track.selectedSamples[this.sampleIndex]},set selected(a){this.track.selectedSamples[this.sampleIndex]=a?!0:!1;this.track.invalidate()}};f.prototype={__proto__:Object.prototype,get range(){if(this.range_dirty_){for(var a=Infinity,b=-a,d=0;d<this.length_;d++){var c=this[d];c.slice&&(a=Math.min(a,c.slice.start),b=Math.max(b,c.slice.end))}this.range_=
+{min:a,max:b};this.range_dirty_=!1}return this.range_},get duration(){return this.range.max-this.range.min},get length(){return this.length_},clear:function(){for(var a=0;a<this.length_;++a)delete this[a];this.length_=0;this.range_dirty_=!0},push_:function(a){this[this.length_++]=a;this.range_dirty_=!0;return a},addSlice:function(a,b){return this.push_(new e(a,b))},addCounterSample:function(a,b,d){return this.push_(new c(a,b,d))},subSelection:function(a,b){var b=b||1,d=new f;d.range_dirty_=!0;if(0>
+a||a+b>this.length_)throw"Index out of bounds";for(var c=a;c<a+b;c++)d.push_(this[c]);return d},getCounterSampleHits:function(){for(var a=new f,b=0;b<this.length_;b++)this[b]instanceof c&&a.push_(this[b]);return a},getSliceHits:function(){for(var a=new f,b=0;b<this.length_;b++)this[b]instanceof e&&a.push_(this[b]);return a},map:function(a){for(var b=0;b<this.length_;b++)a(this[b])},getShiftedSelection:function(a){for(var b=new f,d=0;d<this.length_;d++){var c=this[d];c.track.addItemNearToProvidedHitToSelection(c,
+a,b)}return 0==b.length?void 0:b}};var h=cr.ui.define("div");h.prototype={__proto__:HTMLDivElement.prototype,model_:null,decorate:function(){this.classList.add("timeline");this.viewport_=new g(this);this.viewportTrack=new tracing.TimelineViewportTrack;this.tracks_=this.ownerDocument.createElement("div");this.appendChild(this.tracks_);this.dragBox_=this.ownerDocument.createElement("div");this.dragBox_.className="timeline-drag-box";this.appendChild(this.dragBox_);this.hideDragBox_();this.bindEventListener_(document,
+"keypress",this.onKeypress_,this);this.bindEventListener_(document,"keydown",this.onKeydown_,this);this.bindEventListener_(document,"mousedown",this.onMouseDown_,this);this.bindEventListener_(document,"mousemove",this.onMouseMove_,this);this.bindEventListener_(document,"mouseup",this.onMouseUp_,this);this.bindEventListener_(document,"dblclick",this.onDblClick_,this);this.lastMouseViewPos_={x:0,y:0};this.selection_=new f},bindEventListener_:function(a,b,d,c){this.boundListeners_||(this.boundListeners_=
+[]);d=d.bind(c);this.boundListeners_.push({object:a,event:b,boundFunc:d});a.addEventListener(b,d)},detach:function(){for(var a=0;a<this.tracks_.children.length;a++)this.tracks_.children[a].detach();for(a=0;a<this.boundListeners_.length;a++){var b=this.boundListeners_[a];b.object.removeEventListener(b.event,b.boundFunc)}this.boundListeners_=void 0;this.viewport_.detach()},get viewport(){return this.viewport_},get model(){return this.model_},set model(a){if(!a)throw Error("Model cannot be null");if(this.model)throw Error("Cannot set model twice.");
+this.model_=a;var b=[];a.getAllThreads().forEach(function(a){b.push(a.userFriendlyName)});a.getAllCounters().forEach(function(a){b.push(a.name)});a.getAllCpus().forEach(function(a){b.push("CPU "+a.cpuNumber)});var d=0,c=new tracing.MeasuringStick,f=document.createElement("div");f.style.position="fixed";f.className="timeline-canvas-based-track-title";b.forEach(function(a){f.textContent=a+":__";a=c.measure(f).width;300<a&&(a=300);a>d&&(d=a)});for(var d=d+"px",e=0;e<this.tracks_.children.length;e++)this.tracks_.children[e].detach();
+this.tracks_.textContent="";this.viewportTrack.headingWidth=d;this.viewportTrack.viewport=this.viewport_;e=a.getAllCpus();e.sort(tracing.TimelineCpu.compare);e.forEach(function(a){var b=new tracing.TimelineCpuTrack;b.heading="CPU "+a.cpuNumber+":";b.headingWidth=d;b.viewport=this.viewport_;b.cpu=a;this.tracks_.appendChild(b);for(var c in a.counters){var f=a.counters[c],b=new tracing.TimelineCounterTrack;b.heading="CPU "+a.cpuNumber+" "+f.name+":";b.headingWidth=d;b.viewport=this.viewport_;b.counter=
+f;this.tracks_.appendChild(b)}}.bind(this));a=a.getAllProcesses();a.sort(tracing.TimelineProcess.compare);a.forEach(function(a){var b=[],c;for(c in a.counters)b.push(a.counters[c]);b.sort(tracing.TimelineCounter.compare);b.forEach(function(a){var b=new tracing.TimelineCounterTrack;b.heading=a.name+":";b.headingWidth=d;b.viewport=this.viewport_;b.counter=a;this.tracks_.appendChild(b)}.bind(this));b=[];for(c in a.threads)b.push(a.threads[c]);b.sort(tracing.TimelineThread.compare);b.forEach(function(a){var b=
+new tracing.TimelineThreadTrack;b.heading=a.userFriendlyName+":";b.tooltip=a.userFriendlyDetails;b.headingWidth=d;b.viewport=this.viewport_;b.thread=a;this.tracks_.appendChild(b)}.bind(this))}.bind(this));this.viewport_.setWhenPossible(function(){this.viewport_.xSetWorldRange(this.model_.minTimestamp,this.model_.maxTimestamp,this.firstCanvas.width)}.bind(this))},addAllObjectsMatchingFilterToSelection:function(a,b){for(var d=0;d<this.tracks_.children.length;++d)this.tracks_.children[d].addAllObjectsMatchingFilterToSelection(a,
+b)},get focusElement(){return this.focusElement_?this.focusElement_:this.parentElement},set focusElement(a){this.focusElement_=a},get listenToKeys_(){return!this.viewport_.isAttachedToDocument_?!1:!this.focusElement_?!0:0<=this.focusElement.tabIndex?document.activeElement==this.focusElement:!0},onKeypress_:function(a){var b=this.viewport_;if(this.firstCanvas&&this.listenToKeys_){var d=this.firstCanvas.clientWidth;switch(a.keyCode){case 101:a=b.xViewToWorld(this.lastMouseViewPos_.x);b.xPanWorldPosToViewPos(a,
+"center",d);break;case 119:this.zoomBy_(1.5);break;case 115:this.zoomBy_(1/1.5);break;case 103:this.onGridToggle_(!0);break;case 71:this.onGridToggle_(!1);break;case 87:this.zoomBy_(10);break;case 83:this.zoomBy_(0.1);break;case 97:b.panX+=b.xViewVectorToWorld(0.1*d);break;case 100:b.panX-=b.xViewVectorToWorld(0.1*d);break;case 65:b.panX+=b.xViewVectorToWorld(0.5*d);break;case 68:b.panX-=b.xViewVectorToWorld(0.5*d)}}},onKeydown_:function(a){if(this.listenToKeys_){var b;switch(a.keyCode){case 37:if(b=
+this.selection.getShiftedSelection(-1))this.setSelectionAndMakeVisible(b),a.preventDefault();break;case 39:if(b=this.selection.getShiftedSelection(1))this.setSelectionAndMakeVisible(b),a.preventDefault();break;case 9:-1==this.focusElement.tabIndex&&(a.shiftKey?this.selectPrevious_(a):this.selectNext_(a),a.preventDefault())}}},zoomBy_:function(a){if(this.firstCanvas){var b=this.viewport_,d=this.firstCanvas.clientWidth,c=this.lastMouseViewPos_.x,f=b.xViewToWorld(c);b.scaleX*=a;b.xPanWorldPosToViewPos(f,
+c,d)}},get keyHelp(){var a="Keyboard shortcuts:\n w/s     : Zoom in/out    (with shift: go faster)\n a/d     : Pan left/right\n e       : Center on mouse\n g/G     : Shows grid at the start/end of the selected task\n",a=this.focusElement.tabIndex?a+" <-      : Select previous event on current timeline\n ->      : Select next event on current timeline\n":a+" <-,^TAB : Select previous event on current timeline\n ->, TAB : Select next event on current timeline\n";return a+"\nDbl-click to zoom in; Shift dbl-click to zoom out\n"},
+get selection(){return this.selection_},set selection(a){if(!(a instanceof f))throw"Expected TimelineSelection";var b;for(b=0;b<this.selection_.length;b++)this.selection_[b].selected=!1;this.selection_=a;cr.dispatchSimpleEvent(this,"selectionChange");for(b=0;b<this.selection_.length;b++)this.selection_[b].selected=!0;this.viewport_.dispatchChangeEvent()},setSelectionAndMakeVisible:function(a,b){if(!(a instanceof f))throw"Expected TimelineSelection";this.selection=a;var d=this.selection.range,c=this.viewport_.xWorldVectorToView(d.max-
+d.min);b&&50>c?(c=d.min+0.5*(d.max-d.min),d=5*(d.max-d.min),this.viewport_.xSetWorldRange(c-0.5*d,c+0.5*d,this.firstCanvas.width)):this.viewport_.xPanWorldRangeIntoView(d.min,d.max,this.firstCanvas.width)},get firstCanvas(){return this.tracks_.firstChild?this.tracks_.firstChild.firstCanvas:void 0},hideDragBox_:function(){this.dragBox_.style.left="-1000px";this.dragBox_.style.top="-1000px";this.dragBox_.style.width=0;this.dragBox_.style.height=0},setDragBoxPosition_:function(a,b){var c=Math.min(a.clientX,
+b.clientX),f=Math.max(a.clientX,b.clientX),e=Math.min(a.clientY,b.clientY),g=Math.max(a.clientY,b.clientY);this.dragBox_.style.left=c+"px";this.dragBox_.style.top=e+"px";this.dragBox_.style.width=f-c+"px";this.dragBox_.style.height=g-e+"px";e=this.firstCanvas;c=this.viewport_.xViewToWorld(c-e.offsetLeft);f=this.viewport_.xViewToWorld(f-e.offsetLeft);this.dragBox_.textContent=Math.round(100*(f-c))/100+"ms";e=new cr.Event("selectionChanging");e.loWX=c;e.hiWX=f;this.dispatchEvent(e)},onGridToggle_:function(a){var a=
+a?this.selection_.range.min:this.selection_.range.max,b=Math.ceil((a-this.model_.minTimestamp)/this.viewport_.gridStep_);this.viewport_.gridTimebase=a-(b+1)*this.viewport_.gridStep_;this.viewport_.gridEnabled=!0},onMouseDown_:function(a){var b=this.firstCanvas,c=this.tracks_.getClientRects()[0];c&&(a.clientX>=c.left&&a.clientX<c.right&&a.clientY>=c.top&&a.clientY<c.bottom&&a.x>=b.offsetLeft)&&(this.viewport_.xViewToWorld(a.clientX-b.offsetLeft),this.dragBeginEvent_=a,a.preventDefault(),0<=this.focusElement.tabIndex&&
+this.focusElement.focus())},onMouseMove_:function(a){if(this.firstCanvas){var b=this.firstCanvas;this.lastMouseViewPos_={x:a.clientX-b.offsetLeft,y:a.clientY-b.offsetTop};this.dragBeginEvent_&&this.setDragBoxPosition_(this.dragBeginEvent_,a)}},onMouseUp_:function(a){var b;if(this.dragBeginEvent_){this.hideDragBox_();var c=this.dragBeginEvent_;this.dragBeginEvent_=null;var e=Math.min(c.clientX,a.clientX);b=Math.max(c.clientX,a.clientX);var g=Math.min(c.clientY,a.clientY),a=Math.max(c.clientY,a.clientY),
+c=this.firstCanvas,e=this.viewport_.xViewToWorld(e-c.offsetLeft),c=this.viewport_.xViewToWorld(b-c.offsetLeft),h=new f;for(b=0;b<this.tracks_.children.length;b++){var k=this.tracks_.children[b],l=k.getBoundingClientRect(),o=Math.max(g,l.top),l=Math.min(a,l.bottom);o<=l&&k.addIntersectingItemsInRangeToSelection(e,c,g,a,h)}this.selection=h}},onDblClick_:function(a){if(!(a.x<this.firstCanvas.offsetLeft)){var b=4;a.shiftKey&&(b=1/b);this.zoomBy_(b);a.preventDefault()}}};cr.defineProperty(h,"model",cr.PropertyKind.JS);
+return{Timeline:h,TimelineSelectionSliceHit:e,TimelineSelectionCounterSampleHit:c,TimelineSelection:f,TimelineViewport:g}});cr.define("tracing",function(){function g(a){return Math.round(1E3*a)/1E3}function e(a,c){c=c||0;"string"!=typeof a&&(a=""+a);if(a.length>=c)return"";for(var f="",e=0;e<c-a.length;e++)f+=" ";return f}function c(a,c){return a+e(a,c)}function f(a,c){return e(a,c)+a}function h(a){var d="",e=a.getSliceHits(),h=a.getCounterSampleHits();if(1==e.length){var a=14,j=e[0].slice,d="Selected item:\n"+(c("Title",a)+": "+j.title+"\n"),d=d+(c("Start",a)+": "+g(j.start)+" ms\n"),d=d+(c("Duration",a)+": "+g(j.duration)+
+" ms\n");j.durationInUserTime&&(d+=c("Duration (U)",a)+": "+g(j.durationInUserTime)+" ms\n");var k=0,l;for(l in j.args)k+=1;if(0<k)for(l in d+=c("Args",a)+":\n",j.args)k=j.args[l],d+=c(" "+l,a)+": "+k+"\n"}else if(1<e.length){var a=55,d="Slices:\n",o=e.range.min,q=e.range.max;e.map(function(a){return a.slice.title});var u={};for(l=0;l<e.length;l++)j=e[l].slice,u[j.title]||(u[j.title]={slices:[]}),u[j.title].slices.push(j);j=0;for(k in u){var v=u[k],t=0;for(l=0;l<v.slices.length;l++)t+=v.slices[l].duration;
+j+=t;d+=" "+c(k,a)+": "+f(g(t)+"ms",12)+"   "+f(""+v.slices.length,5)+" occurrences\n"}d+=c("*Totals",a)+" : "+f(g(j)+"ms",12)+"   "+f(""+e.length,5)+" occurrences\n";d=d+"\n"+(c("Selection start",a)+" : "+f(g(o)+"ms",12)+"\n");d+=c("Selection extent",a)+" : "+f(g(q-o)+"ms",12)+"\n"}if(1==h.length){d="Selected counter:\n";a=55;h=h[0];e=h.counter;h=h.sampleIndex;k=[];for(l=0;l<e.numSeries;++l)k.push(e.samples[e.numSeries*h+l]);d+=c("Title",a)+": "+e.name+"\n";d+=c("Timestamp",a)+": "+g(e.timestamps[h])+
+" ms\n";d=1<e.numSeries?d+(c("Values",a)+": "+k.join("\n")+"\n"):d+(c("Value",a)+": "+k.join("\n")+"\n")}else 1<h.length&&0==e.length&&(d+="Analysis of multiple counters not yet implemented. Pick a single counter.");return d}var a=cr.ui.define("div");a.prototype={__proto__:HTMLDivElement.prototype,decorate:function(){this.className="timeline-analysis"},set selection(a){this.textContent=h(a)}};return{TimelineAnalysisView:a}});cr.define("tracing",function(){function g(a,b){var c=document.createElement("div");c.classList.add("timeline-track-button");c.classList.add("timeline-track-close-button");c.textContent=String.fromCharCode(215);c.addEventListener("click",function(){a.style.display="None"});a.appendChild(c);if(b){var d=document.createElement("div");d.classList.add("timeline-track-button");d.classList.add("timeline-track-collapse-button");d.textContent="\u2212";var f=!1;d.addEventListener("click",function(){f=!f;a.collapsedDidChange(f);
+d.textContent=f?"+":"\u2212"});a.appendChild(d)}}function e(a,b){this.string=a;this.width=b}function c(){}var f=tracing.getPallette(),h=tracing.getPalletteHighlightIdBoost(),a={},b={},d=cr.ui.define("div");d.prototype={__proto__:HTMLDivElement.prototype,decorate:function(){this.tracks_=[]},detach:function(){for(var a=0;a<this.tracks_.length;a++)this.tracks_[a].detach()},get viewport(){return this.viewport_},set viewport(a){this.viewport_=a;for(var b=0;b<this.tracks_.length;b++)this.tracks_[b].viewport=
+a;this.updateChildTracks_()},get firstCanvas(){if(this.tracks_.length)return this.tracks_[0].firstCanvas},addIntersectingItemsToSelection:function(a,b,c){for(var d=0;d<this.tracks_.length;d++){var f=this.tracks_[d].getBoundingClientRect();b>=f.top&&b<f.bottom&&this.tracks_[d].addIntersectingItemsToSelection(a,b,c)}return!1},addIntersectingItemsInRangeToSelection:function(a,b,c,d,f){for(var e=0;e<this.tracks_.length;e++){var g=this.tracks_[e].getBoundingClientRect(),h=Math.max(c,g.top),g=Math.min(d,
+g.bottom);h<=g&&this.tracks_[e].addIntersectingItemsInRangeToSelection(a,b,c,d,f)}},addAllObjectsMatchingFilterToSelection:function(a,b){for(var c=0;c<this.tracks_.length;c++)this.tracks_[c].addAllObjectsMatchingFilterToSelection(a,b)}};var m=cr.ui.define(d);m.prototype={__proto__:d.prototype,decorate:function(){this.classList.add("timeline-thread-track")},get thread(){return this.thread_},set thread(a){this.thread_=a;this.updateChildTracks_()},get tooltip(){return this.tooltip_},set tooltip(a){this.tooltip_=
+a;this.updateChildTracks_()},get heading(){return this.heading_},set heading(a){this.heading_=a;this.updateChildTracks_()},get headingWidth(){return this.headingWidth_},set headingWidth(a){this.headingWidth_=a;this.updateChildTracks_()},addTrack_:function(a){var b=new j;b.heading="";b.slices=a;b.headingWidth=this.headingWidth_;b.viewport=this.viewport_;this.tracks_.push(b);this.appendChild(b);return b},updateChildTracks_:function(){this.detach();this.textContent="";this.tracks_=[];if(this.thread_){if(this.thread_.cpuSlices){var a=
 this.addTrack_(this.thread_.cpuSlices);a.height="4px";a.decorateHit=function(a){a.thread=this.thread_}}if(this.thread_.asyncSlices.length)for(var b=this.thread_.asyncSlices.subRows,c=0;c<b.length;c++)a=this.addTrack_(b[c]),a.decorateHit=function(){},a.asyncStyle=!0;for(c=0;c<this.thread_.subRows.length;c++)a=this.addTrack_(this.thread_.subRows[c]),a.decorateHit=function(a){a.thread=this.thread_};0<this.tracks_.length&&(this.thread_.cpuSlices?(this.tracks_[1].heading=this.heading_,this.tracks_[1].tooltip=
-this.tooltip_):(this.tracks_[0].heading=this.heading_,this.tracks_[0].tooltip=this.tooltip_))}f(this,4<=this.tracks_.length)},collapsedDidChange:function(a){if(a)for(var a=parseInt(this.tracks_[0].height),b=0;b<this.tracks_.length;++b)2<a?this.tracks_[b].height=Math.floor(a)+"px":this.tracks_[b].style.display="None",a*=0.5;else for(b=0;b<this.tracks_.length;++b)this.tracks_[b].height=this.tracks_[0].height,this.tracks_[b].style.display=""}};var g=cr.ui.define(j);g.prototype={__proto__:j.prototype,
+this.tooltip_):(this.tracks_[0].heading=this.heading_,this.tracks_[0].tooltip=this.tooltip_))}g(this,4<=this.tracks_.length)},collapsedDidChange:function(a){if(a)for(var a=parseInt(this.tracks_[0].height),b=0;b<this.tracks_.length;++b)2<a?this.tracks_[b].height=Math.floor(a)+"px":this.tracks_[b].style.display="None",a*=0.5;else for(b=0;b<this.tracks_.length;++b)this.tracks_[b].height=this.tracks_[0].height,this.tracks_[b].style.display=""}};var i=cr.ui.define(d);i.prototype={__proto__:d.prototype,
 decorate:function(){this.classList.add("timeline-thread-track")},get cpu(){return this.cpu_},set cpu(a){this.cpu_=a;this.updateChildTracks_()},get tooltip(){return this.tooltip_},set tooltip(a){this.tooltip_=a;this.updateChildTracks_()},get heading(){return this.heading_},set heading(a){this.heading_=a;this.updateChildTracks_()},get headingWidth(){return this.headingWidth_},set headingWidth(a){this.headingWidth_=a;this.updateChildTracks_()},updateChildTracks_:function(){this.detach();this.textContent=
-"";this.tracks_=[];if(this.cpu_){var a=new k;a.slices=this.cpu_.slices;a.headingWidth=this.headingWidth_;a.viewport=this.viewport_;this.tracks_.push(a);this.appendChild(a);this.tracks_[0].heading=this.heading_;this.tracks_[0].tooltip=this.tooltip_}f(this,!1)}};j=cr.ui.define("div");j.prototype={__proto__:HTMLDivElement.prototype,decorate:function(){this.className="timeline-canvas-based-track";this.slices_=null;this.headingDiv_=document.createElement("div");this.headingDiv_.className="timeline-canvas-based-track-title";
+"";this.tracks_=[];if(this.cpu_){var a=new j;a.slices=this.cpu_.slices;a.headingWidth=this.headingWidth_;a.viewport=this.viewport_;this.tracks_.push(a);this.appendChild(a);this.tracks_[0].heading=this.heading_;this.tracks_[0].tooltip=this.tooltip_}g(this,!1)}};d=cr.ui.define("div");d.prototype={__proto__:HTMLDivElement.prototype,decorate:function(){this.className="timeline-canvas-based-track";this.slices_=null;this.headingDiv_=document.createElement("div");this.headingDiv_.className="timeline-canvas-based-track-title";
 this.headingDiv_.onselectstart=function(){return!1};this.appendChild(this.headingDiv_);this.canvasContainer_=document.createElement("div");this.canvasContainer_.className="timeline-canvas-based-track-canvas-container";this.appendChild(this.canvasContainer_);this.canvas_=document.createElement("canvas");this.canvas_.className="timeline-canvas-based-track-canvas";this.canvasContainer_.appendChild(this.canvas_);this.ctx_=this.canvas_.getContext("2d")},detach:function(){this.viewport_&&this.viewport_.removeEventListener("change",
 this.viewportChangeBoundToThis_)},set headingWidth(a){this.headingDiv_.style.width=a},get heading(){return this.headingDiv_.textContent},set heading(a){this.headingDiv_.textContent=a},set tooltip(a){this.headingDiv_.title=a},get viewport(){return this.viewport_},set viewport(a){(this.viewport_=a)&&this.viewport_.removeEventListener("change",this.viewportChangeBoundToThis_);if(this.viewport_=a)this.viewportChangeBoundToThis_=this.viewportChange_.bind(this),this.viewport_.addEventListener("change",
-this.viewportChangeBoundToThis_);this.invalidate()},viewportChange_:function(){this.invalidate()},invalidate:function(){this.rafPending_||(webkitRequestAnimationFrame(function(){this.rafPending_=!1;if(this.viewport_){var a=window.getComputedStyle(this.canvasContainer_),b=parseInt(a.width),a=parseInt(a.height);this.canvas_.width!=b&&(this.canvas_.width=b);this.canvas_.height!=a&&(this.canvas_.height=a);this.redraw()}}.bind(this),this),this.rafPending_=!0)},get firstCanvas(){return this.canvas_}};a.prototype=
-{get:function(a,b,e,f,g){var h=d[e];h||(h={},d[e]=h);f=h[b];f||(h[b]={},f=h[b]);h=f[g];if(void 0===h){for(h=!1;a.labelWidthWorld(e,b)>g;)e=e.substring(0,0.75*e.length),h=!0;h&&3<e.length&&(e=e.substring(0,e.length-3)+"...");h=new c(e,a.labelWidth(e));f[g]=h}return h}};var k=cr.ui.define(j);k.prototype={__proto__:j.prototype,SHOULD_ELIDE_TEXT:!0,decorate:function(){this.classList.add("timeline-slice-track");this.elidedTitleCache=new a;this.asyncStyle_=!1},decorateHit:function(){},get asyncStyle(){return this.asyncStyle_},
-set asyncStyle(a){this.asyncStyle_=!!a;this.invalidate()},get slices(){return this.slices_},set slices(a){this.slices_=a;this.invalidate()},get height(){return window.getComputedStyle(this).height},set height(a){this.style.height=a;this.invalidate()},labelWidth:function(a){var c=b[a];c||(c=this.ctx_.measureText(a).width,b[a]=c);return c+2},labelWidthWorld:function(a,b){return this.labelWidth(a)*b},redraw:function(){var a=this.ctx_,b=this.canvas_.width,c=this.canvas_.height;a.clearRect(0,0,b,c);var d=
-this.viewport_,f=d.xViewVectorToWorld(1),g=d.xViewToWorld(0),b=d.xViewToWorld(b);if(d.gridEnabled){var h=d.gridTimebase;for(a.beginPath();h<b;){if(h>=g){var j=d.xWorldToView(h);a.moveTo(j,0);a.lineTo(j,c)}h+=d.gridStep}a.strokeStyle="rgba(255,0,0,0.25)";a.stroke()}a.save();d.applyTransformToCanavs(a);this.asyncStyle_&&(a.globalAlpha=0.25);var k=new tracing.FastRectRenderer(a,g,2*f,2*f,b,e);k.setYandH(0,c);g=this.slices_;for(b=0;b<g.length;++b){var j=g[b],h=j.start,l=Math.max(j.duration,0.001),m=j.selected?
-j.colorId+i:j.colorId;l<f&&(l=f);0<j.duration?k.fillRect(h,l,m):0.001<f?k.fillRect(h,f,m):(a.fillStyle=e[m],a.beginPath(),a.moveTo(h-4*f,c),a.lineTo(h,0),a.lineTo(h+4*f,c),a.closePath(),a.fill())}k.flush();a.restore();if(8<c){a.textAlign="center";a.textBaseline="top";a.font="10px sans-serif";a.strokeStyle="rgb(0,0,0)";a.fillStyle="rgb(0,0,0)";c=20*f;h=this.SHOULD_ELIDE_TEXT;for(b=0;b<g.length;++b)if(j=g[b],j.duration>c&&(k=j.title,j.didNotFinish&&(k+=" (Did Not Finish)"),l=this.labelWidth(k),h&&this.labelWidthWorld(k,
-f)>j.duration&&(l=this.elidedTitleCache.get(this,f,k,l,j.duration),k=l.string,l=l.width),l*f<j.duration))j=d.xWorldToView(j.start+0.5*j.duration),a.fillText(k,j,2.5,l)}},addIntersectingItemsToSelection:function(a,b,c){var d=this.getBoundingClientRect();if(b<d.top||b>=d.bottom)return!1;a=tracing.findLowIndexInSortedIntervals(this.slices_,function(a){return a.start},function(a){return a.duration},a);return 0<=a&&a<this.slices_.length?(this.decorateHit(c.addSlice(this,this.slices_[a])),!0):!1},addIntersectingItemsInRangeToSelection:function(a,
-b,c,d,e){function f(a){a=e.addSlice(h,a);h.decorateHit(a)}var g=this.getBoundingClientRect(),c=Math.max(c,g.top),d=Math.min(d,g.bottom);if(!(c>d)){var h=this;tracing.iterateOverIntersectingIntervals(this.slices_,function(a){return a.start},function(a){return a.duration},a,b,f)}},indexOfSlice_:function(a){for(var b=tracing.findLowIndexInSortedArray(this.slices_,function(a){return a.start},a.start);b<this.slices_.length&&a.start==this.slices_[b].start&&a.colorId!=this.slices_[b].colorId;)b++;return b<
-this.slices_.length?b:void 0},addItemNearToProvidedHitToSelection:function(a,b,c){if(!a.slice)return!1;a=this.indexOfSlice_(a.slice);if(void 0===a)return!1;b=a+b;if(0>b||b>=this.slices_.length)return!1;a=c.addSlice(this,this.slices_[b]);this.decorateHit(a);return!0},addAllObjectsMatchingFilterToSelection:function(a,b){for(var c=0;c<this.slices_.length;++c)a.matchSlice(this.slices_[c])&&this.decorateHit(b.addSlice(this,this.slices_[c]))}};var m=cr.ui.define(j),h=Math.log(10);m.prototype={__proto__:j.prototype,
-decorate:function(){this.classList.add("timeline-viewport-track");this.strings_secs_=[];this.strings_msecs_=[]},redraw:function(){var a=this.ctx_,b=this.canvas_.width,c=this.canvas_.height;a.clearRect(0,0,b,c);var d=this.viewport_;d.xViewVectorToWorld(1);for(var e=d.xViewToWorld(0),f=d.xViewToWorld(b),g=d.xViewVectorToWorld(150),i=Math.pow(10,Math.ceil(Math.log(g)/h)),j=[10,5,2,1],g=0;g<j.length;++g)if(!(150>d.xWorldVectorToView(i/j[g]))){majorMarkDistanceWorld=i/j[g-1];break}i=void 0;100>majorMarkDistanceWorld?
-(unit="ms",unitDivisor=1,i=this.strings_msecs_):(unit="s",unitDivisor=1E3,i=this.strings_secs_);j=d.xWorldVectorToView(majorMarkDistanceWorld/5);g=Math.floor(e/majorMarkDistanceWorld)*majorMarkDistanceWorld;e=Math.floor(0.25*c);a.fillStyle="rgb(0, 0, 0)";a.strokeStyle="rgb(0, 0, 0)";a.textAlign="left";a.textBaseline="top";a.font="9px sans-serif";for(var k=g;k<f;k+=majorMarkDistanceWorld){var l=Math.floor(d.xWorldToView(k)),g=Math.floor(1E5*(k/unitDivisor))/1E5;i[g]||(i[g]=g+" "+unit);a.fillText(i[g],
-l+2,0);a.beginPath();a.moveTo(l,0);a.lineTo(l,b);for(g=1;5>g;++g){var m=Math.floor(l+j*g);a.moveTo(m,c-e);a.lineTo(m,c)}a.stroke()}},addIntersectingItemsToSelection:function(){},addIntersectingItemsInRangeToSelection:function(){},addAllObjectsMatchingFilterToSelection:function(){}};var l=cr.ui.define(j);l.prototype={__proto__:j.prototype,decorate:function(){this.classList.add("timeline-counter-track");f(this,!1);this.selectedSamples_={}},decorateHit:function(){},get counter(){return this.counter_},
-set counter(a){this.counter_=a;this.invalidate()},get selectedSamples(){return this.selectedSamples_},redraw:function(){var a=this.counter_,b=this.ctx_,c=this.canvas_.width,d=this.canvas_.height;b.clearRect(0,0,c,d);var f=this.viewport_,g=f.xViewVectorToWorld(1),h=f.xViewToWorld(0),c=f.xViewToWorld(c),i=f.xViewVectorToWorld(1);b.save();f.applyTransformToCanavs(b);for(var f=a.numSeries,j=a.numSamples,k=tracing.findLowIndexInSortedArray(a.timestamps,function(){},h),l=d/a.maxTotal,m=a.numSeries-1;0<=
-m;m--){b.fillStyle=e[a.seriesColors[m]];b.beginPath();for(var o=k-1,w=0<=o?a.timestamps[o]-i:-1,x=d,A=!1;;){var s=o+1;if(s>=j){b.lineTo(w,x);b.lineTo(w+8*g,x);b.lineTo(w+8*g,d);break}var t=a.timestamps[s],o=a.totals[s*f+m],z=d-l*o;if(t>c){b.lineTo(t,x);b.lineTo(t,d);break}t-w<i?o=s:(A||(b.moveTo(h,d),A=!0),b.lineTo(t,x),b.lineTo(t,z),o=s,w=t,x=z)}b.closePath();b.fill()}b.fillStyle="rgba(255, 0, 0, 1)";for(s in this.selectedSamples_)if(this.selectedSamples_[s]){t=a.timestamps[s];for(m=a.numSeries-
-1;0<=m;m--)o=a.totals[s*f+m],z=d-l*o,b.fillRect(t-g,z-1,3*g,3)}b.restore()},addIntersectingItemsToSelection:function(a,b,c){var d=this.getBoundingClientRect();if(b<d.top||b>=d.bottom)return!1;b=this.counter_;if(a<this.counter_.timestamps[0])return!1;d=tracing.findLowIndexInSortedArray(b.timestamps,function(a){return a},a);if(0>d||d>=b.timestamps.length)return!1;0<d&&a>this.counter_.timestamps[d-1]&&d--;this.getBoundingClientRect();this.decorateHit(c.addCounterSample(this,this.counter,d));return!0},
+this.viewportChangeBoundToThis_);this.invalidate()},viewportChange_:function(){this.invalidate()},invalidate:function(){this.rafPending_||(webkitRequestAnimationFrame(function(){this.rafPending_=!1;if(this.viewport_){var a=window.getComputedStyle(this.canvasContainer_),b=parseInt(a.width),a=parseInt(a.height);this.canvas_.width!=b&&(this.canvas_.width=b);this.canvas_.height!=a&&(this.canvas_.height=a);this.redraw()}}.bind(this),this),this.rafPending_=!0)},get firstCanvas(){return this.canvas_}};c.prototype=
+{get:function(a,c,d,f,g){var h=b[d];h||(h={},b[d]=h);f=h[c];f||(h[c]={},f=h[c]);h=f[g];if(void 0===h){for(h=!1;a.labelWidthWorld(d,c)>g;)d=d.substring(0,0.75*d.length),h=!0;h&&3<d.length&&(d=d.substring(0,d.length-3)+"...");h=new e(d,a.labelWidth(d));f[g]=h}return h}};var j=cr.ui.define(d);j.prototype={__proto__:d.prototype,SHOULD_ELIDE_TEXT:!0,decorate:function(){this.classList.add("timeline-slice-track");this.elidedTitleCache=new c;this.asyncStyle_=!1},decorateHit:function(){},get asyncStyle(){return this.asyncStyle_},
+set asyncStyle(a){this.asyncStyle_=!!a;this.invalidate()},get slices(){return this.slices_},set slices(a){this.slices_=a;this.invalidate()},get height(){return window.getComputedStyle(this).height},set height(a){this.style.height=a;this.invalidate()},labelWidth:function(b){var c=a[b];c||(c=this.ctx_.measureText(b).width,a[b]=c);return c+2},labelWidthWorld:function(a,b){return this.labelWidth(a)*b},redraw:function(){var a=this.ctx_,b=this.canvas_.width,c=this.canvas_.height;a.clearRect(0,0,b,c);var d=
+this.viewport_,e=d.xViewVectorToWorld(1),g=d.xViewToWorld(0),b=d.xViewToWorld(b);if(d.gridEnabled){var j=d.gridTimebase;for(a.beginPath();j<b;){if(j>=g){var i=d.xWorldToView(j);a.moveTo(i,0);a.lineTo(i,c)}j+=d.gridStep}a.strokeStyle="rgba(255,0,0,0.25)";a.stroke()}a.save();d.applyTransformToCanavs(a);this.asyncStyle_&&(a.globalAlpha=0.25);var k=new tracing.FastRectRenderer(a,g,2*e,2*e,b,f);k.setYandH(0,c);g=this.slices_;for(b=0;b<g.length;++b){var i=g[b],j=i.start,l=Math.max(i.duration,0.001),m=i.selected?
+i.colorId+h:i.colorId;l<e&&(l=e);0<i.duration?k.fillRect(j,l,m):0.001<e?k.fillRect(j,e,m):(a.fillStyle=f[m],a.beginPath(),a.moveTo(j-4*e,c),a.lineTo(j,0),a.lineTo(j+4*e,c),a.closePath(),a.fill())}k.flush();a.restore();if(8<c){a.textAlign="center";a.textBaseline="top";a.font="10px sans-serif";a.strokeStyle="rgb(0,0,0)";a.fillStyle="rgb(0,0,0)";c=20*e;j=this.SHOULD_ELIDE_TEXT;for(b=0;b<g.length;++b)if(i=g[b],i.duration>c&&(k=i.title,i.didNotFinish&&(k+=" (Did Not Finish)"),l=this.labelWidth(k),j&&this.labelWidthWorld(k,
+e)>i.duration&&(l=this.elidedTitleCache.get(this,e,k,l,i.duration),k=l.string,l=l.width),l*e<i.duration))i=d.xWorldToView(i.start+0.5*i.duration),a.fillText(k,i,2.5,l)}},addIntersectingItemsToSelection:function(a,b,c){var d=this.getBoundingClientRect();if(b<d.top||b>=d.bottom)return!1;a=tracing.findLowIndexInSortedIntervals(this.slices_,function(a){return a.start},function(a){return a.duration},a);return 0<=a&&a<this.slices_.length?(this.decorateHit(c.addSlice(this,this.slices_[a])),!0):!1},addIntersectingItemsInRangeToSelection:function(a,
+b,c,d,f){function e(a){a=f.addSlice(h,a);h.decorateHit(a)}var g=this.getBoundingClientRect(),c=Math.max(c,g.top),d=Math.min(d,g.bottom);if(!(c>d)){var h=this;tracing.iterateOverIntersectingIntervals(this.slices_,function(a){return a.start},function(a){return a.duration},a,b,e)}},indexOfSlice_:function(a){for(var b=tracing.findLowIndexInSortedArray(this.slices_,function(a){return a.start},a.start);b<this.slices_.length&&a.start==this.slices_[b].start&&a.colorId!=this.slices_[b].colorId;)b++;return b<
+this.slices_.length?b:void 0},addItemNearToProvidedHitToSelection:function(a,b,c){if(!a.slice)return!1;a=this.indexOfSlice_(a.slice);if(void 0===a)return!1;b=a+b;if(0>b||b>=this.slices_.length)return!1;a=c.addSlice(this,this.slices_[b]);this.decorateHit(a);return!0},addAllObjectsMatchingFilterToSelection:function(a,b){for(var c=0;c<this.slices_.length;++c)a.matchSlice(this.slices_[c])&&this.decorateHit(b.addSlice(this,this.slices_[c]))}};var k=cr.ui.define(d),l=Math.log(10);k.prototype={__proto__:d.prototype,
+decorate:function(){this.classList.add("timeline-viewport-track");this.strings_secs_=[];this.strings_msecs_=[]},redraw:function(){var a=this.ctx_,b=this.canvas_.width,c=this.canvas_.height;a.clearRect(0,0,b,c);var d=this.viewport_;d.xViewVectorToWorld(1);for(var f=d.xViewToWorld(0),e=d.xViewToWorld(b),g=d.xViewVectorToWorld(150),h=Math.pow(10,Math.ceil(Math.log(g)/l)),i=[10,5,2,1],g=0;g<i.length;++g)if(!(150>d.xWorldVectorToView(h/i[g]))){majorMarkDistanceWorld=h/i[g-1];break}h=void 0;100>majorMarkDistanceWorld?
+(unit="ms",unitDivisor=1,h=this.strings_msecs_):(unit="s",unitDivisor=1E3,h=this.strings_secs_);i=d.xWorldVectorToView(majorMarkDistanceWorld/5);g=Math.floor(f/majorMarkDistanceWorld)*majorMarkDistanceWorld;f=Math.floor(0.25*c);a.fillStyle="rgb(0, 0, 0)";a.strokeStyle="rgb(0, 0, 0)";a.textAlign="left";a.textBaseline="top";a.font="9px sans-serif";for(var j=g;j<e;j+=majorMarkDistanceWorld){var k=Math.floor(d.xWorldToView(j)),g=Math.floor(1E5*(j/unitDivisor))/1E5;h[g]||(h[g]=g+" "+unit);a.fillText(h[g],
+k+2,0);a.beginPath();a.moveTo(k,0);a.lineTo(k,b);for(g=1;5>g;++g){var m=Math.floor(k+i*g);a.moveTo(m,c-f);a.lineTo(m,c)}a.stroke()}},addIntersectingItemsToSelection:function(){},addIntersectingItemsInRangeToSelection:function(){},addAllObjectsMatchingFilterToSelection:function(){}};var o=cr.ui.define(d);o.prototype={__proto__:d.prototype,decorate:function(){this.classList.add("timeline-counter-track");g(this,!1);this.selectedSamples_={}},decorateHit:function(){},get counter(){return this.counter_},
+set counter(a){this.counter_=a;this.invalidate()},get selectedSamples(){return this.selectedSamples_},redraw:function(){var a=this.counter_,b=this.ctx_,c=this.canvas_.width,d=this.canvas_.height;b.clearRect(0,0,c,d);var e=this.viewport_,g=e.xViewVectorToWorld(1),h=e.xViewToWorld(0),c=e.xViewToWorld(c),i=e.xViewVectorToWorld(1);b.save();e.applyTransformToCanavs(b);for(var e=a.numSeries,j=a.numSamples,k=tracing.findLowIndexInSortedArray(a.timestamps,function(){},h),l=d/a.maxTotal,m=a.numSeries-1;0<=
+m;m--){b.fillStyle=f[a.seriesColors[m]];b.beginPath();for(var o=k-1,w=0<=o?a.timestamps[o]-i:-1,x=d,A=!1;;){var r=o+1;if(r>=j){b.lineTo(w,x);b.lineTo(w+8*g,x);b.lineTo(w+8*g,d);break}var s=a.timestamps[r],o=a.totals[r*e+m],z=d-l*o;if(s>c){b.lineTo(s,x);b.lineTo(s,d);break}s-w<i?o=r:(A||(b.moveTo(h,d),A=!0),b.lineTo(s,x),b.lineTo(s,z),o=r,w=s,x=z)}b.closePath();b.fill()}b.fillStyle="rgba(255, 0, 0, 1)";for(r in this.selectedSamples_)if(this.selectedSamples_[r]){s=a.timestamps[r];for(m=a.numSeries-
+1;0<=m;m--)o=a.totals[r*e+m],z=d-l*o,b.fillRect(s-g,z-1,3*g,3)}b.restore()},addIntersectingItemsToSelection:function(a,b,c){var d=this.getBoundingClientRect();if(b<d.top||b>=d.bottom)return!1;b=this.counter_;if(a<this.counter_.timestamps[0])return!1;d=tracing.findLowIndexInSortedArray(b.timestamps,function(a){return a},a);if(0>d||d>=b.timestamps.length)return!1;0<d&&a>this.counter_.timestamps[d-1]&&d--;this.getBoundingClientRect();this.decorateHit(c.addCounterSample(this,this.counter,d));return!0},
 addIntersectingItemsInRangeToSelection:function(a,b,c,d,e){var f=this.getBoundingClientRect(),c=Math.max(c,f.top),d=Math.min(d,f.bottom);if(!(c>d)){d=this.counter_;c=tracing.findLowIndexInSortedArray(d.timestamps,function(a){return a},a);f=tracing.findLowIndexInSortedArray(d.timestamps,function(a){return a},b);0<c&&a>d.timestamps[c-1]&&c--;0<f&&b>d.timestamps[f-1]&&f--;for(a=c;a<=f;a++)a>=d.timestamps.length||this.decorateHit(e.addCounterSample(this,this.counter,a))}},addAllObjectsMatchingFilterToSelection:function(){}};
-return{TimelineCounterTrack:l,TimelineSliceTrack:k,TimelineThreadTrack:o,TimelineViewportTrack:m,TimelineCpuTrack:g}});cr.define("tracing",function(){function f(c,a,e,f,b,d){this.ctx_=c;this.vpLeft_=a;this.minRectSize_=e;this.maxMergeDist_=f;this.vpRight_=b;this.pallette_=d}f.prototype={y_:0,h_:0,merging_:!1,mergeStartX_:0,mergeCurRight_:0,setYandH:function(c,a){this.flush();this.y_=c;this.h_=a},fillRect:function(c,a,e){var f=c+a;f<this.vpLeft_||c>this.vpRight_||(a<this.minRectSize_?(f-this.mergeStartX_>this.maxMergeDist_&&this.flush(),this.merging_?(this.mergeCurRight_=f,this.mergedColorId=Math.max(this.mergedColorId,
-e)):(this.merging_=!0,this.mergeStartX_=c,this.mergeCurRight_=f,this.mergedColorId=e)):(this.merging_&&this.flush(),this.ctx_.fillStyle=this.pallette_[e],this.ctx_.fillRect(c,this.y_,a,this.h_)))},flush:function(){this.merging_&&(this.ctx_.fillStyle=this.pallette_[this.mergedColorId],this.ctx_.fillRect(this.mergeStartX_,this.y_,this.mergeCurRight_-this.mergeStartX_,this.h_),this.merging_=!1)}};return{FastRectRenderer:f}});cr.define("tracing",function(){var f=cr.ui.define(cr.ui.TabPanel);f.prototype={__proto__:cr.ui.TabPanel.prototype,traceEvents_:[],systemTraceEvents_:[],decorate:function(){cr.ui.TabPanel.prototype.decorate.apply(this);this.classList.add("profiling-view");this.recordBn_=document.createElement("button");this.recordBn_.className="record";this.recordBn_.textContent="Record";this.recordBn_.addEventListener("click",this.onRecord_.bind(this));this.saveBn_=document.createElement("button");this.saveBn_.textContent=
-"Save";this.saveBn_.addEventListener("click",this.onSave_.bind(this));this.loadBn_=document.createElement("button");this.loadBn_.textContent="Load";this.loadBn_.addEventListener("click",this.onLoad_.bind(this));if(cr.isChromeOS){this.systemTracingBn_=document.createElement("input");this.systemTracingBn_.type="checkbox";this.systemTracingBn_.checked=!0;var c=document.createElement("div");c.className="label";c.textContent="System events";c.appendChild(this.systemTracingBn_)}this.timelineView_=new tracing.TimelineView;
-this.timelineView_.leftControls.appendChild(this.recordBn_);this.timelineView_.leftControls.appendChild(this.saveBn_);this.timelineView_.leftControls.appendChild(this.loadBn_);cr.isChromeOS&&this.timelineView_.leftControls.appendChild(this.systemTracingBn_);this.appendChild(this.timelineView_);document.addEventListener("keypress",this.onKeypress_.bind(this));this.refresh_()},didSetTracingController_:function(c,a){if(a)throw"Can only set tracing controller once.";this.tracingController_.addEventListener("traceEnded",
-this.onRecordDone_.bind(this));this.tracingController_.addEventListener("loadTraceFileComplete",this.onLoadTraceFileComplete_.bind(this));this.tracingController_.addEventListener("saveTraceFileComplete",this.onSaveTraceFileComplete_.bind(this));this.tracingController_.addEventListener("loadTraceFileCanceled",this.onLoadTraceFileCanceled_.bind(this));this.tracingController_.addEventListener("saveTraceFileCanceled",this.onSaveTraceFileCanceled_.bind(this));this.refresh_()},refresh_:function(){if(this.tracingController_){var c=
-this.tracingController_.traceEvents,a=c&&c.length;this.saveBn_.disabled=!a;a&&(a=new tracing.TimelineModel,a.importEvents(c,!0,[this.tracingController_.systemTraceEvents]),this.timelineView_.model=a)}},onKeypress_:function(c){if(114==c.keyCode&&!this.tracingController_.isTracingEnabled)this.onRecord_()},get timelineView(){return this.timelineView_},onRecord_:function(){this.tracingController_.beginTracing(this.systemTracingBn_?this.systemTracingBn_.checked:!1)},onRecordDone_:function(){this.refresh_()},
-onSave_:function(){this.overlayEl_=new tracing.Overlay;this.overlayEl_.className="profiling-overlay";var c=document.createElement("div");c.className="label";c.textContent="Saving...";this.overlayEl_.appendChild(c);this.overlayEl_.visible=!0;this.tracingController_.beginSaveTraceFile()},onSaveTraceFileComplete_:function(){this.overlayEl_.visible=!1;this.overlayEl_=void 0},onSaveTraceFileCanceled_:function(){this.overlayEl_.visible=!1;this.overlayEl_=void 0},onLoad_:function(){this.overlayEl_=new tracing.Overlay;
-this.overlayEl_.className="profiling-overlay";var c=document.createElement("div");c.className="label";c.textContent="Loading...";this.overlayEl_.appendChild(c);this.overlayEl_.visible=!0;this.tracingController_.beginLoadTraceFile()},onLoadTraceFileComplete_:function(){this.overlayEl_.visible=!1;this.overlayEl_=void 0;this.refresh_()},onLoadTraceFileCanceled_:function(){this.overlayEl_.visible=!1;this.overlayEl_=void 0}};cr.defineProperty(f,"tracingController",cr.PropertyKind.JS,f.prototype.didSetTracingController_);
-return{ProfilingView:f}});cr.define("tracing",function(){function f(){this.model_=this.timeline_=void 0;this.filterText_="";this.filterHits_=new tracing.TimelineSelection;this.filterHitsDirty_=!0;this.currentHitIndex_=0}var c=cr.ui.define("div");c.prototype={__proto__:tracing.Overlay.prototype,decorate:function(){tracing.Overlay.prototype.decorate.call(this);this.className="timeline-find-control";this.hitCountEl_=document.createElement("div");this.hitCountEl_.className="hit-count-label";this.hitCountEl_.textContent="1 of 7";
-var a=document.createElement("div");a.className="timeline-button find-previous";a.textContent="\u2190";a.addEventListener("click",function(){this.controller.findPrevious();this.updateHitCountEl_()}.bind(this));var c=document.createElement("div");c.className="timeline-button find-next";c.textContent="\u2192";c.addEventListener("click",function(){this.controller.findNext();this.updateHitCountEl_()}.bind(this));this.filterEl_=document.createElement("input");this.filterEl_.type="input";this.filterEl_.addEventListener("input",
-function(){this.controller.filterText=this.filterEl_.value;this.updateHitCountEl_()}.bind(this));this.filterEl_.addEventListener("keydown",function(a){13==a.keyCode?c.click():27==a.keyCode&&(this.filterEl_.blur(),this.updateHitCountEl_())}.bind(this));this.filterEl_.addEventListener("blur",function(){this.updateHitCountEl_()}.bind(this));this.filterEl_.addEventListener("focus",function(){this.updateHitCountEl_()}.bind(this));this.appendChild(this.filterEl_);this.appendChild(a);this.appendChild(c);
-this.appendChild(this.hitCountEl_);this.updateHitCountEl_()},get controller(){return this.controller_},set controller(a){this.controller_=a;this.updateHitCountEl_()},focus:function(){this.filterEl_.selectionStart=0;this.filterEl_.selectionEnd=this.filterEl_.value.length;this.filterEl_.focus()},updateHitCountEl_:function(){if(!this.controller||document.activeElement!=this.filterEl_)this.hitCountEl_.textContent="";else{var a=this.controller.currentHitIndex,c=this.controller.filterHits.length;this.hitCountEl_.textContent=
-0==c?"0 of 0":a+1+" of "+c}}};f.prototype={__proto__:Object.prototype,get timeline(){return this.timeline_},set timeline(a){this.timeline_=a;this.filterHitsDirty_=!0},get filterText(){return this.filterText_},set filterText(a){a!=this.filterText_&&(this.filterText_=a,this.filterHitsDirty_=!0,this.findNext())},get filterHits(){if(this.filterHitsDirty_)if(this.filterHitsDirty_=!1,this.timeline_){var a=new tracing.TimelineFilter(this.filterText);this.filterHits_.clear();this.timeline.addAllObjectsMatchingFilterToSelection(a,
-this.filterHits_);this.currentHitIndex_=this.filterHits_.length-1}else this.filterHits_.clear(),this.currentHitIndex_=0;return this.filterHits_},get currentHitIndex(){return this.currentHitIndex_},find_:function(a){if(this.timeline){var c=this.filterHits.length;this.currentHitIndex_+=a;0>this.currentHitIndex_&&(this.currentHitIndex_=c-1);this.currentHitIndex_>=c&&(this.currentHitIndex_=0);0>this.currentHitIndex_||this.currentHitIndex_>=c?this.timeline.selection=new tracing.TimelineSelection:(a=0==
-this.currentHitIndex_,this.timeline.setSelectionAndMakeVisible(this.filterHits.subSelection(this.currentHitIndex_),a))}},findNext:function(){this.find_(1)},findPrevious:function(){this.find_(-1)}};var a=cr.ui.define("div");a.prototype={__proto__:HTMLDivElement.prototype,decorate:function(){this.classList.add("timeline-view");this.titleEl_=document.createElement("div");this.titleEl_.textContent="Tracing: ";this.controlDiv_=document.createElement("div");this.controlDiv_.className="control";this.leftControlsEl_=
-document.createElement("div");this.leftControlsEl_.className="controls";this.rightControlsEl_=document.createElement("div");this.rightControlsEl_.className="controls";var a=document.createElement("div");a.className="spacer";this.timelineContainer_=document.createElement("div");this.timelineContainer_.className="timeline-container";var i=document.createElement("div");i.className="analysis-container";this.analysisEl_=new tracing.TimelineAnalysisView;this.findCtl_=new c;this.findCtl_.controller=new f;
-this.rightControls.appendChild(this.findCtl_);this.controlDiv_.appendChild(this.titleEl_);this.controlDiv_.appendChild(this.leftControlsEl_);this.controlDiv_.appendChild(a);this.controlDiv_.appendChild(this.rightControlsEl_);this.appendChild(this.controlDiv_);this.appendChild(this.timelineContainer_);i.appendChild(this.analysisEl_);this.appendChild(i);this.rightControls.appendChild(this.createHelpButton_());this.onSelectionChangedBoundToThis_=this.onSelectionChanged_.bind(this);document.addEventListener("keypress",
-this.onKeypress_.bind(this),!0)},createHelpButton_:function(){function a(b){if(c.visible&&(27==b.keyCode||63==b.keyCode))b.preventDefault(),document.removeEventListener("keydown",a),c.visible=!1}var c=new tracing.Overlay;c.classList.add("timeline-view-help-overlay");var b=document.createElement("div");b.className="timeline-button timeline-view-help-button";b.textContent="?";var d=document.createElement("div");d.style.whiteSpace="pre";d.style.fontFamily="monospace";b.addEventListener("click",function(){c.visible=
-!0;d.textContent=this.timeline_.keyHelp;document.addEventListener("keydown",a,!0)}.bind(this));c.appendChild(d);return b},get leftControls(){return this.leftControlsEl_},get rightControls(){return this.rightControlsEl_},get title(){return this.titleEl_.textContent.substring(this.titleEl_.textContent.length-2)},set title(a){this.titleEl_.textContent=a+":"},set traceData(a){this.model=new tracing.TimelineModel(a)},get model(){return this.timelineModel_},set model(a){this.timelineModel_=a;this.timelineContainer_.textContent=
+return{TimelineCounterTrack:o,TimelineSliceTrack:j,TimelineThreadTrack:m,TimelineViewportTrack:k,TimelineCpuTrack:i}});cr.define("tracing",function(){function g(e,c,f,g,a,b){this.ctx_=e;this.vpLeft_=c;this.minRectSize_=f;this.maxMergeDist_=g;this.vpRight_=a;this.pallette_=b}g.prototype={y_:0,h_:0,merging_:!1,mergeStartX_:0,mergeCurRight_:0,setYandH:function(e,c){this.flush();this.y_=e;this.h_=c},fillRect:function(e,c,f){var g=e+c;g<this.vpLeft_||e>this.vpRight_||(c<this.minRectSize_?(g-this.mergeStartX_>this.maxMergeDist_&&this.flush(),this.merging_?(this.mergeCurRight_=g,this.mergedColorId=Math.max(this.mergedColorId,
+f)):(this.merging_=!0,this.mergeStartX_=e,this.mergeCurRight_=g,this.mergedColorId=f)):(this.merging_&&this.flush(),this.ctx_.fillStyle=this.pallette_[f],this.ctx_.fillRect(e,this.y_,c,this.h_)))},flush:function(){this.merging_&&(this.ctx_.fillStyle=this.pallette_[this.mergedColorId],this.ctx_.fillRect(this.mergeStartX_,this.y_,this.mergeCurRight_-this.mergeStartX_,this.h_),this.merging_=!1)}};return{FastRectRenderer:g}});cr.define("tracing",function(){var g=cr.ui.define(cr.ui.TabPanel);g.prototype={__proto__:cr.ui.TabPanel.prototype,traceEvents_:[],systemTraceEvents_:[],decorate:function(){cr.ui.TabPanel.prototype.decorate.apply(this);this.classList.add("profiling-view");this.recordBn_=document.createElement("button");this.recordBn_.className="record";this.recordBn_.textContent="Record";this.recordBn_.addEventListener("click",this.onRecord_.bind(this));this.saveBn_=document.createElement("button");this.saveBn_.textContent=
+"Save";this.saveBn_.addEventListener("click",this.onSave_.bind(this));this.loadBn_=document.createElement("button");this.loadBn_.textContent="Load";this.loadBn_.addEventListener("click",this.onLoad_.bind(this));if(cr.isChromeOS){this.systemTracingBn_=document.createElement("input");this.systemTracingBn_.type="checkbox";this.systemTracingBn_.checked=!0;var e=document.createElement("div");e.className="label";e.textContent="System events";e.appendChild(this.systemTracingBn_)}this.timelineView_=new tracing.TimelineView;
+this.timelineView_.leftControls.appendChild(this.recordBn_);this.timelineView_.leftControls.appendChild(this.saveBn_);this.timelineView_.leftControls.appendChild(this.loadBn_);cr.isChromeOS&&this.timelineView_.leftControls.appendChild(this.systemTracingBn_);this.appendChild(this.timelineView_);document.addEventListener("keypress",this.onKeypress_.bind(this));this.refresh_()},didSetTracingController_:function(e,c){if(c)throw"Can only set tracing controller once.";this.tracingController_.addEventListener("traceEnded",
+this.onRecordDone_.bind(this));this.tracingController_.addEventListener("loadTraceFileComplete",this.onLoadTraceFileComplete_.bind(this));this.tracingController_.addEventListener("saveTraceFileComplete",this.onSaveTraceFileComplete_.bind(this));this.tracingController_.addEventListener("loadTraceFileCanceled",this.onLoadTraceFileCanceled_.bind(this));this.tracingController_.addEventListener("saveTraceFileCanceled",this.onSaveTraceFileCanceled_.bind(this));this.refresh_()},refresh_:function(){if(this.tracingController_){var e=
+this.tracingController_.traceEvents,c=e&&e.length;this.saveBn_.disabled=!c;c&&(c=new tracing.TimelineModel,c.importEvents(e,!0,[this.tracingController_.systemTraceEvents]),this.timelineView_.model=c)}},onKeypress_:function(e){if(114==e.keyCode&&!this.tracingController_.isTracingEnabled)this.onRecord_()},get timelineView(){return this.timelineView_},onRecord_:function(){this.tracingController_.beginTracing(this.systemTracingBn_?this.systemTracingBn_.checked:!1)},onRecordDone_:function(){this.refresh_()},
+onSave_:function(){this.overlayEl_=new tracing.Overlay;this.overlayEl_.className="profiling-overlay";var e=document.createElement("div");e.className="label";e.textContent="Saving...";this.overlayEl_.appendChild(e);this.overlayEl_.visible=!0;this.tracingController_.beginSaveTraceFile()},onSaveTraceFileComplete_:function(){this.overlayEl_.visible=!1;this.overlayEl_=void 0},onSaveTraceFileCanceled_:function(){this.overlayEl_.visible=!1;this.overlayEl_=void 0},onLoad_:function(){this.overlayEl_=new tracing.Overlay;
+this.overlayEl_.className="profiling-overlay";var e=document.createElement("div");e.className="label";e.textContent="Loading...";this.overlayEl_.appendChild(e);this.overlayEl_.visible=!0;this.tracingController_.beginLoadTraceFile()},onLoadTraceFileComplete_:function(){this.overlayEl_.visible=!1;this.overlayEl_=void 0;this.refresh_()},onLoadTraceFileCanceled_:function(){this.overlayEl_.visible=!1;this.overlayEl_=void 0}};cr.defineProperty(g,"tracingController",cr.PropertyKind.JS,g.prototype.didSetTracingController_);
+return{ProfilingView:g}});cr.define("tracing",function(){function g(){this.model_=this.timeline_=void 0;this.filterText_="";this.filterHits_=new tracing.TimelineSelection;this.filterHitsDirty_=!0;this.currentHitIndex_=0}var e=cr.ui.define("div");e.prototype={__proto__:tracing.Overlay.prototype,decorate:function(){tracing.Overlay.prototype.decorate.call(this);this.className="timeline-find-control";this.hitCountEl_=document.createElement("div");this.hitCountEl_.className="hit-count-label";this.hitCountEl_.textContent="1 of 7";
+var c=document.createElement("div");c.className="timeline-button find-previous";c.textContent="\u2190";c.addEventListener("click",function(){this.controller.findPrevious();this.updateHitCountEl_()}.bind(this));var e=document.createElement("div");e.className="timeline-button find-next";e.textContent="\u2192";e.addEventListener("click",function(){this.controller.findNext();this.updateHitCountEl_()}.bind(this));this.filterEl_=document.createElement("input");this.filterEl_.type="input";this.filterEl_.addEventListener("input",
+function(){this.controller.filterText=this.filterEl_.value;this.updateHitCountEl_()}.bind(this));this.filterEl_.addEventListener("keydown",function(a){13==a.keyCode?e.click():27==a.keyCode&&(this.filterEl_.blur(),this.updateHitCountEl_())}.bind(this));this.filterEl_.addEventListener("blur",function(){this.updateHitCountEl_()}.bind(this));this.filterEl_.addEventListener("focus",function(){this.updateHitCountEl_()}.bind(this));this.appendChild(this.filterEl_);this.appendChild(c);this.appendChild(e);
+this.appendChild(this.hitCountEl_);this.updateHitCountEl_()},get controller(){return this.controller_},set controller(c){this.controller_=c;this.updateHitCountEl_()},focus:function(){this.filterEl_.selectionStart=0;this.filterEl_.selectionEnd=this.filterEl_.value.length;this.filterEl_.focus()},updateHitCountEl_:function(){if(!this.controller||document.activeElement!=this.filterEl_)this.hitCountEl_.textContent="";else{var c=this.controller.currentHitIndex,e=this.controller.filterHits.length;this.hitCountEl_.textContent=
+0==e?"0 of 0":c+1+" of "+e}}};g.prototype={__proto__:Object.prototype,get timeline(){return this.timeline_},set timeline(c){this.timeline_=c;this.filterHitsDirty_=!0},get filterText(){return this.filterText_},set filterText(c){c!=this.filterText_&&(this.filterText_=c,this.filterHitsDirty_=!0,this.findNext())},get filterHits(){if(this.filterHitsDirty_)if(this.filterHitsDirty_=!1,this.timeline_){var c=new tracing.TimelineFilter(this.filterText);this.filterHits_.clear();this.timeline.addAllObjectsMatchingFilterToSelection(c,
+this.filterHits_);this.currentHitIndex_=this.filterHits_.length-1}else this.filterHits_.clear(),this.currentHitIndex_=0;return this.filterHits_},get currentHitIndex(){return this.currentHitIndex_},find_:function(c){if(this.timeline){var e=this.filterHits.length;this.currentHitIndex_+=c;0>this.currentHitIndex_&&(this.currentHitIndex_=e-1);this.currentHitIndex_>=e&&(this.currentHitIndex_=0);0>this.currentHitIndex_||this.currentHitIndex_>=e?this.timeline.selection=new tracing.TimelineSelection:(c=0==
+this.currentHitIndex_,this.timeline.setSelectionAndMakeVisible(this.filterHits.subSelection(this.currentHitIndex_),c))}},findNext:function(){this.find_(1)},findPrevious:function(){this.find_(-1)}};var c=cr.ui.define("div");c.prototype={__proto__:HTMLDivElement.prototype,decorate:function(){this.classList.add("timeline-view");this.titleEl_=document.createElement("div");this.titleEl_.textContent="Tracing: ";this.controlDiv_=document.createElement("div");this.controlDiv_.className="control";this.leftControlsEl_=
+document.createElement("div");this.leftControlsEl_.className="controls";this.rightControlsEl_=document.createElement("div");this.rightControlsEl_.className="controls";var c=document.createElement("div");c.className="spacer";this.timelineContainer_=document.createElement("div");this.timelineContainer_.className="timeline-container";var h=document.createElement("div");h.className="analysis-container";this.analysisEl_=new tracing.TimelineAnalysisView;this.findCtl_=new e;this.findCtl_.controller=new g;
+this.rightControls.appendChild(this.findCtl_);this.controlDiv_.appendChild(this.titleEl_);this.controlDiv_.appendChild(this.leftControlsEl_);this.controlDiv_.appendChild(c);this.controlDiv_.appendChild(this.rightControlsEl_);this.appendChild(this.controlDiv_);this.appendChild(this.timelineContainer_);h.appendChild(this.analysisEl_);this.appendChild(h);this.rightControls.appendChild(this.createHelpButton_());this.onSelectionChangedBoundToThis_=this.onSelectionChanged_.bind(this);document.addEventListener("keypress",
+this.onKeypress_.bind(this),!0)},createHelpButton_:function(){function c(a){if(e.visible&&(27==a.keyCode||63==a.keyCode))a.preventDefault(),document.removeEventListener("keydown",c),e.visible=!1}var e=new tracing.Overlay;e.classList.add("timeline-view-help-overlay");var a=document.createElement("div");a.className="timeline-button timeline-view-help-button";a.textContent="?";var b=document.createElement("div");b.style.whiteSpace="pre";b.style.fontFamily="monospace";a.addEventListener("click",function(){e.visible=
+!0;b.textContent=this.timeline_.keyHelp;document.addEventListener("keydown",c,!0)}.bind(this));e.appendChild(b);return a},get leftControls(){return this.leftControlsEl_},get rightControls(){return this.rightControlsEl_},get title(){return this.titleEl_.textContent.substring(this.titleEl_.textContent.length-2)},set title(c){this.titleEl_.textContent=c+":"},set traceData(c){this.model=new tracing.TimelineModel(c)},get model(){return this.timelineModel_},set model(c){this.timelineModel_=c;this.timelineContainer_.textContent=
 "";void 0!==this.timelineModel_.minTimestamp?(this.timeline_&&(this.timeline_.viewportTrack.detach(),this.timeline_.detach()),this.timeline_=new tracing.Timeline,this.timeline_.model=this.timelineModel_,this.timeline_.focusElement=this.focusElement_?this.focusElement_:this.parentElement,this.insertBefore(this.timeline_.viewportTrack,this.timelineContainer_),this.timelineContainer_.appendChild(this.timeline_),this.timeline_.addEventListener("selectionChange",this.onSelectionChangedBoundToThis_),this.findCtl_.controller.timeline=
-this.timeline_,this.onSelectionChanged_()):(this.timeline_=void 0,this.findCtl_.controller.timeline=void 0)},get timeline(){return this.timeline_},set focusElement(a){this.focusElement_=a;this.timeline_&&(this.timeline_.focusElement=a)},get focusElement(){return this.focusElement_?this.focusElement_:this.parentElement},get isAttachedToDocument_(){for(var a=this;a.parentNode;)a=a.parentNode;return a==this.ownerDocument},get listenToKeys_(){if(this.isAttachedToDocument_)return!this.focusElement_?!0:
-0<=this.focusElement.tabIndex?document.activeElement==this.focusElement:!0},onKeypress_:function(a){this.listenToKeys_&&(47==event.keyCode?(this.findCtl_.focus(),event.preventDefault()):63==a.keyCode&&(this.querySelector(".timeline-view-help-button").click(),a.preventDefault()))},beginFind:function(){if(!this.findInProgress_){this.findInProgress_=!0;var a=c();a.controller=new f;a.controller.timeline=this.timeline;a.visible=!0;a.addEventListener("close",function(){this.findInProgress_=!1}.bind(this));
-a.addEventListener("findNext",function(){});a.addEventListener("findPrevious",function(){})}},onSelectionChanged_:function(){var a=this.timelineContainer_.scrollTop;this.analysisEl_.selection=this.timeline_.selection;this.timelineContainer_.scrollTop=a}};return{TimelineFindControl:c,TimelineFindController:f,TimelineView:a}});
+this.timeline_,this.onSelectionChanged_()):(this.timeline_=void 0,this.findCtl_.controller.timeline=void 0)},get timeline(){return this.timeline_},set focusElement(c){this.focusElement_=c;this.timeline_&&(this.timeline_.focusElement=c)},get focusElement(){return this.focusElement_?this.focusElement_:this.parentElement},get isAttachedToDocument_(){for(var c=this;c.parentNode;)c=c.parentNode;return c==this.ownerDocument},get listenToKeys_(){if(this.isAttachedToDocument_)return!this.focusElement_?!0:
+0<=this.focusElement.tabIndex?document.activeElement==this.focusElement:!0},onKeypress_:function(c){this.listenToKeys_&&(47==event.keyCode?(this.findCtl_.focus(),event.preventDefault()):63==c.keyCode&&(this.querySelector(".timeline-view-help-button").click(),c.preventDefault()))},beginFind:function(){if(!this.findInProgress_){this.findInProgress_=!0;var c=e();c.controller=new g;c.controller.timeline=this.timeline;c.visible=!0;c.addEventListener("close",function(){this.findInProgress_=!1}.bind(this));
+c.addEventListener("findNext",function(){});c.addEventListener("findPrevious",function(){})}},onSelectionChanged_:function(){var c=this.timelineContainer_.scrollTop;this.analysisEl_.selection=this.timeline_.selection;this.timelineContainer_.scrollTop=c}};return{TimelineFindControl:e,TimelineFindController:g,TimelineView:c}});
diff --git a/src/tracing/linux_perf_importer.js b/src/tracing/linux_perf_importer.js
index 767453b..13b479b 100644
--- a/src/tracing/linux_perf_importer.js
+++ b/src/tracing/linux_perf_importer.js
@@ -93,30 +93,11 @@
   var lineRE = /^\s*(.+?)\s+\[(\d+)\]\s*([d.][N.][sh.][\d.])?\s*(\d+\.\d+):\s+(\S+):\s(.*)$/;
   TestExports.lineRE = lineRE;
 
-  // Matches the sched_switch record
-  var schedSwitchRE = new RegExp(
-      'prev_comm=(.+) prev_pid=(\\d+) prev_prio=(\\d+) prev_state=(\\S+) ==> ' +
-      'next_comm=(.+) next_pid=(\\d+) next_prio=(\\d+)');
-  TestExports.schedSwitchRE = schedSwitchRE;
-
-  // Matches the sched_wakeup record
-  var schedWakeupRE =
-      /comm=(.+) pid=(\d+) prio=(\d+) success=(\d+) target_cpu=(\d+)/;
-  TestExports.schedWakeupRE = schedWakeupRE;
-
   // Matches the trace_event_clock_sync record
   //  0: trace_event_clock_sync: parent_ts=19581477508
   var traceEventClockSyncRE = /trace_event_clock_sync: parent_ts=(\d+\.?\d*)/;
   TestExports.traceEventClockSyncRE = traceEventClockSyncRE;
 
-  // Matches the workqueue_execute_start record
-  //  workqueue_execute_start: work struct c7a8a89c: function MISRWrapper
-  var workqueueExecuteStartRE = /work struct (.+): function (\S+)/;
-
-  // Matches the workqueue_execute_start record
-  //  workqueue_execute_end: work struct c7a8a89c
-  var workqueueExecuteEndRE = /work struct (.+)/;
-
   /**
    * Guesses whether the provided events is a Linux perf string.
    * Looks for the magic string "# tracer" at the start of the file,
@@ -424,29 +405,76 @@
     },
 
     /**
+     * Helper to open a kernel thread slice.
+     */
+    openSlice: function(kthread, name, ts) {
+      kthread.openSliceTS = ts;
+      kthread.openSlice = name;
+    },
+
+    /**
+     * Helper to close a kernel thread slice.
+     */
+    closeSlice: function(kthread, ts, data) {
+      if (kthread.openSlice) {
+        var slice = new tracing.TimelineSlice(kthread.openSlice,
+            tracing.getStringColorId(kthread.openSlice),
+            kthread.openSliceTS,
+            data,
+            ts - kthread.openSliceTS);
+        kthread.thread.subRows[0].push(slice);
+        kthread.openSlice = undefined;
+      }
+    },
+
+    /**
+     * Helper to get a ThreadState for a given taskId.
+     */
+    getThreadState: function(taskId) {
+      var kpid = this.parsePid(taskId);
+      return this.threadStateByKPID_[kpid];
+    },
+
+    /**
+     * Helper to get or create a ThreadState for a given taskId.
+     */
+    getOrCreateThreadState: function(taskId, pid) {
+      var kpid = this.parsePid(taskId);
+      var state = this.threadStateByKPID_[kpid];
+      if (!state) {
+        state = new ThreadState();
+        state.threadName = this.parseThreadName(taskId);
+        state.tid = kpid;
+        state.pid = pid;
+        state.thread = this.model_.getOrCreateProcess(pid).
+            getOrCreateThread(kpid);
+        if (!state.thread.name) {
+          state.thread.name = state.threadName;
+        }
+        this.threadStateByKPID_[kpid] = state;
+      }
+      return state;
+    },
+
+    /**
      * Helper to process a 'begin' event (e.g. initiate a slice).
-     * @param {ThreadState} state Thread state (holds slices).
      * @param {string} name The trace event name.
      * @param {number} ts The trace event begin timestamp.
      */
-    processBegin: function(state, tname, name, ts, pid, tid) {
+    processBegin: function(taskId, name, ts, pid) {
+      var state = this.getOrCreateThreadState(taskId, pid);
       var colorId = tracing.getStringColorId(name);
       var slice = new tracing.TimelineThreadSlice(name, colorId, ts, null);
-      // XXX: Should these be removed from the slice before putting it into the
-      // model?
-      slice.pid = pid;
-      slice.tid = tid;
-      slice.threadName = tname;
       state.openSlices.push(slice);
     },
 
     /**
      * Helper to process an 'end' event (e.g. close a slice).
-     * @param {ThreadState} state Thread state (holds slices).
      * @param {number} ts The trace event begin timestamp.
      */
-    processEnd: function(state, ts) {
-      if (state.openSlices.length == 0) {
+    processEnd: function(taskId, ts) {
+      var state = this.getThreadState(taskId);
+      if (!state || state.openSlices.length == 0) {
         // Ignore E events that are unmatched.
         return;
       }
@@ -454,13 +482,8 @@
       slice.duration = ts - slice.start;
 
       // Store the slice on the correct subrow.
-      var thread = this.model_.getOrCreateProcess(slice.pid).
-          getOrCreateThread(slice.tid);
-      if (!thread.name)
-        thread.name = slice.threadName;
-      this.threadsByLinuxPid[slice.tid] = thread;
       var subRowIndex = state.openSlices.length;
-      thread.getSubrow(subRowIndex).push(slice);
+      state.thread.getSubrow(subRowIndex).push(slice);
 
       // Add the slice to the subSlices array of its parent.
       if (state.openSlices.length) {
@@ -522,10 +545,8 @@
           slice.didNotFinish = true;
 
           // Store the slice on the correct subrow.
-          var thread = this.model_.getOrCreateProcess(slice.pid)
-                           .getOrCreateThread(slice.tid);
           var subRowIndex = state.openSlices.length;
-          thread.getSubrow(subRowIndex).push(slice);
+          state.thread.getSubrow(subRowIndex).push(slice);
 
           // Add the slice to the subSlices array of its parent.
           if (state.openSlices.length) {
@@ -557,7 +578,6 @@
       ctr.samples.push(value);
     },
 
-
     /**
      * Walks the this.events_ structure and creates TimelineCpu objects.
      */
@@ -582,272 +602,268 @@
         var eventName = eventBase[5];
         var eventInfo = eventBase[6];
 
-        var cpuState = this.getOrCreateCpuState(parseInt(cpuNum));
-        var ts = parseFloat(timestamp) * 1000;
-
-        switch (eventName) {
-          case 'sched_switch':
-            var event = schedSwitchRE.exec(eventInfo);
+        var eventDefinition = this.eventDefinitions[eventName];
+        if (eventDefinition) {
+          // Parse the event info.
+          var event;
+          if (eventDefinition.format) {
+            event = eventDefinition.format.exec(eventInfo);
             if (!event) {
               this.malformedEvent(eventName);
               continue;
             }
+          } else {
+            event = {};
+          }
 
-            var prevState = event[4];
-            var nextComm = event[5];
-            var nextPid = parseInt(event[6]);
-            var nextPrio = parseInt(event[7]);
-            cpuState.switchRunningLinuxPid(
-                this, prevState, ts, nextPid, nextComm, nextPrio);
-            break;
-          case 'sched_wakeup':
-            var event = schedWakeupRE.exec(eventInfo);
-            if (!event) {
-              this.malformedEvent(eventName);
-              continue;
-            }
+          // Add the basic event properties.
+          event.timestamp = parseFloat(timestamp) * 1000;
+          event.name = eventName;
+          event.info = eventInfo;
+          event.taskId = taskId;
+          event.cpuState = this.getOrCreateCpuState(parseInt(cpuNum));
 
-            var comm = event[1];
-            var pid = parseInt(event[2]);
-            var prio = parseInt(event[3]);
-            this.markPidRunnable(ts, pid, comm, prio);
-            break;
-          case 'power_start':  // NB: old-style power event, deprecated
-            var event = /type=(\d+) state=(\d) cpu_id=(\d)+/.exec(eventInfo);
-            if (!event) {
-              this.malformedEvent(eventName);
-              continue;
-            }
-
-            var targetCpuNumber = parseInt(event[3]);
-            var targetCpu = this.getOrCreateCpuState(targetCpuNumber);
-            var powerCounter;
-            if (event[1] == '1') {
-              powerCounter = targetCpu.cpu.getOrCreateCounter('', 'C-State');
-            } else {
-              this.importError('Don\'t understand power_start events of ' +
-                  'type ' + event[1]);
-              continue;
-            }
-            if (powerCounter.numSeries == 0) {
-              powerCounter.seriesNames.push('state');
-              powerCounter.seriesColors.push(
-                  tracing.getStringColorId(powerCounter.name + '.' + 'state'));
-            }
-            var powerState = parseInt(event[2]);
-            powerCounter.timestamps.push(ts);
-            powerCounter.samples.push(powerState);
-            break;
-          case 'power_frequency':  // NB: old-style power event, deprecated
-            var event = /type=(\d+) state=(\d+) cpu_id=(\d)+/.exec(
-                eventInfo);
-            if (!event) {
-              this.malformedEvent(eventName);
-              continue;
-            }
-
-            var targetCpuNumber = parseInt(event[3]);
-            var targetCpu = this.getOrCreateCpuState(targetCpuNumber);
-            var powerCounter =
-                targetCpu.cpu.getOrCreateCounter('', 'Power Frequency');
-            if (powerCounter.numSeries == 0) {
-              powerCounter.seriesNames.push('state');
-              powerCounter.seriesColors.push(
-                  tracing.getStringColorId(powerCounter.name + '.' + 'state'));
-            }
-            var powerState = parseInt(event[2]);
-            powerCounter.timestamps.push(ts);
-            powerCounter.samples.push(powerState);
-            break;
-          case 'cpu_frequency':
-            var event = /state=(\d+) cpu_id=(\d)+/.exec(eventInfo);
-            if (!event) {
-              this.malformedEvent(eventName);
-              continue;
-            }
-
-            var targetCpuNumber = parseInt(event[2]);
-            var targetCpu = this.getOrCreateCpuState(targetCpuNumber);
-            var powerCounter =
-                targetCpu.cpu.getOrCreateCounter('', 'Clock Frequency');
-            if (powerCounter.numSeries == 0) {
-              powerCounter.seriesNames.push('state');
-              powerCounter.seriesColors.push(
-                  tracing.getStringColorId(powerCounter.name + '.' + 'state'));
-            }
-            var powerState = parseInt(event[1]);
-            powerCounter.timestamps.push(ts);
-            powerCounter.samples.push(powerState);
-            break;
-          case 'cpu_idle':
-            var event = /state=(\d+) cpu_id=(\d)+/.exec(eventInfo);
-            if (!event) {
-              this.malformedEvent(eventName);
-              continue;
-            }
-
-            var targetCpuNumber = parseInt(event[2]);
-            var targetCpu = this.getOrCreateCpuState(targetCpuNumber);
-            var powerCounter = targetCpu.cpu.getOrCreateCounter('', 'C-State');
-            if (powerCounter.numSeries == 0) {
-              powerCounter.seriesNames.push('state');
-              powerCounter.seriesColors.push(
-                  tracing.getStringColorId(powerCounter.name));
-            }
-            var powerState = parseInt(event[1]);
-            // NB: 4294967295/-1 means an exit from the current state
-            if (powerState != 4294967295)
-              powerCounter.samples.push(powerState);
-            else
-              powerCounter.samples.push(0);
-            powerCounter.timestamps.push(ts);
-            break;
-          case 'workqueue_execute_start':
-            var event = workqueueExecuteStartRE.exec(eventInfo);
-            if (!event) {
-              this.malformedEvent(eventName);
-              continue;
-            }
-
-            var kthread = this.getOrCreateKernelThread(taskId);
-            kthread.openSliceTS = ts;
-            kthread.openSlice = event[2];
-            break;
-          case 'workqueue_execute_end':
-            var event = workqueueExecuteEndRE.exec(eventInfo);
-            if (!event) {
-              this.malformedEvent(eventName);
-              continue;
-            }
-
-            var kthread = this.getOrCreateKernelThread(taskId);
-            if (kthread.openSlice) {
-              var slice = new tracing.TimelineSlice(kthread.openSlice,
-                  tracing.getStringColorId(kthread.openSlice),
-                  kthread.openSliceTS,
-                  {},
-                  ts - kthread.openSliceTS);
-
-              kthread.thread.subRows[0].push(slice);
-            }
-            kthread.openSlice = undefined;
-            break;
-          case 'workqueue_queue_work':
-            // ignored for now
-            break;
-          case 'workqueue_activate_work':
-            // ignored for now
-            break;
-          case 'i915_gem_object_pwrite':
-            var event = /obj=(.+), offset=(\d+), len=(\d+)/.exec(eventInfo);
-            if (!event) {
-              this.malformedEvent(eventName);
-              continue;
-            }
-
-            var obj = event[1];
-            var offset = parseInt(event[2]);
-            var len = parseInt(event[3]);
-            var kthread = this.getOrCreateKernelThread('i915_gem', 0, 1);
-            kthread.openSlice = 'pwrite:' + obj;
-            var slice = new tracing.TimelineSlice(kthread.openSlice,
-                tracing.getStringColorId(kthread.openSlice),
-                ts,
-                {
-                  obj: obj,
-                  offset: offset,
-                  len: len
-                }, 0);
-
-            kthread.thread.subRows[0].push(slice);
-            break;
-          case 'i915_flip_request':
-            var event = /plane=(\d+), obj=(.+)/.exec(eventInfo);
-            if (!event) {
-              this.malformedEvent(eventName);
-              continue;
-            }
-
-            var plane = parseInt(event[1]);
-            var obj = event[2];
-            // use i915_obj_plane?
-            var kthread = this.getOrCreateKernelThread('i915_flip', 0, 2);
-            kthread.openSliceTS = ts;
-            kthread.openSlice = 'flip:' + obj + '/' + plane;
-            break;
-          case 'i915_flip_complete':
-            var event = /plane=(\d+), obj=(.+)/.exec(eventInfo);
-            if (!event) {
-              this.malformedEvent(eventName);
-              continue;
-            }
-
-            var plane = parseInt(event[1]);
-            var obj = event[2];
-            // use i915_obj_plane?
-            var kthread = this.getOrCreateKernelThread('i915_flip', 0, 2);
-            if (kthread.openSlice) {
-              var slice = new tracing.TimelineSlice(kthread.openSlice,
-                  tracing.getStringColorId(kthread.openSlice),
-                  kthread.openSliceTS,
-                  {
-                    obj: obj,
-                    plane: plane
-                  },
-                  ts - kthread.openSliceTS);
-
-              kthread.thread.subRows[0].push(slice);
-            }
-            kthread.openSlice = undefined;
-            break;
-          case '0':  // NB: old-style trace markers; deprecated
-          case 'tracing_mark_write':
-            var event = traceEventClockSyncRE.exec(eventInfo);
-            if (event)
-              this.clockSyncRecords_.push({
-                perfTS: ts,
-                parentTS: event[1] * 1000
-              });
-            else {
-              var tid = this.parsePid(taskId);
-              var tname = this.parseThreadName(taskId);
-              var kpid = tid;
-
-              if (!(kpid in this.threadStateByKPID_))
-                this.threadStateByKPID_[kpid] = new ThreadState();
-              var state = this.threadStateByKPID_[kpid];
-
-              var event = eventInfo.split('|')
-              switch (event[0]) {
-                case 'B':
-                  var pid = parseInt(event[1]);
-                  var name = event[2];
-                  this.processBegin(state, tname, name, ts, pid, tid);
-                  break;
-                case 'E':
-                  this.processEnd(state, ts);
-                  break;
-                case 'C':
-                  var pid = parseInt(event[1]);
-                  var name = event[2];
-                  var value = parseInt(event[3]);
-                  this.processCounter(name, ts, value, pid);
-                  break;
-                default:
-                  this.malformedEvent(eventName);
-                  break;
-              }
-            }
-            break;
-
-          default:
-            console.log('unknown event ' + eventName);
-            break;
+          // Invoke the handler.
+          if (eventDefinition.handler) {
+            eventDefinition.handler(this, event);
+          }
+        } else {
+          console.log('unknown event ' + eventName);
         }
       }
+    },
+
+    /**
+     * Table of supported events represented as an associative array indexed by event name.
+     * Each event definition has the following properties:
+     *
+     *   format:   A regular expression to parse the event info.
+     *             If omitted, the event information is not parsed but the other basic
+     *             properties are still provided to the event handler.
+     *   handler:  A handler function to invoke to handle the event.
+     *             If omitted, the event is parsed but not handled.
+     *
+     * The event object passed as a parameter to the handler has the matched groups from
+     * from the regular expression and in addition has the following properties:
+     *
+     *   timestamp: The uptime in milliseconds.
+     *   name:      The event name.
+     *   info:      The unparsed event info.
+     *   taskId:    The task ID.
+     *   cpuState:  The CPU state object for the CPU associated with the event.
+     */
+    eventDefinitions: {
+      'sched_switch': {
+        format: new RegExp(
+            'prev_comm=(.+) prev_pid=(\\d+) prev_prio=(\\d+) prev_state=(\\S+) ==> ' +
+            'next_comm=(.+) next_pid=(\\d+) next_prio=(\\d+)'),
+        handler: function(importer, event) {
+          var prevState = event[4];
+          var nextComm = event[5];
+          var nextPid = parseInt(event[6]);
+          var nextPrio = parseInt(event[7]);
+          event.cpuState.switchRunningLinuxPid(
+              importer, prevState, event.timestamp, nextPid, nextComm, nextPrio);
+        }
+      },
+
+      'sched_wakeup': {
+        format: /comm=(.+) pid=(\d+) prio=(\d+) success=(\d+) target_cpu=(\d+)/,
+        handler: function(importer, event) {
+          var comm = event[1];
+          var pid = parseInt(event[2]);
+          var prio = parseInt(event[3]);
+          importer.markPidRunnable(event.timestamp, pid, comm, prio);
+        }
+      },
+
+      'power_start': { // NB: old-style power event, deprecated
+        format: /type=(\d+) state=(\d) cpu_id=(\d)+/,
+        handler: function(importer, event) {
+          var targetCpuNumber = parseInt(event[3]);
+          var targetCpu = importer.getOrCreateCpuState(targetCpuNumber);
+          var powerCounter;
+          if (event[1] == '1') {
+            powerCounter = targetCpu.cpu.getOrCreateCounter('', 'C-State');
+          } else {
+            importer.importError('Don\'t understand power_start events of ' +
+                'type ' + event[1]);
+            return;
+          }
+          if (powerCounter.numSeries == 0) {
+            powerCounter.seriesNames.push('state');
+            powerCounter.seriesColors.push(
+                tracing.getStringColorId(powerCounter.name + '.' + 'state'));
+          }
+          var powerState = parseInt(event[2]);
+          powerCounter.timestamps.push(event.timestamp);
+          powerCounter.samples.push(powerState);
+        }
+      },
+
+      'power_frequency': { // NB: old-style power event, deprecated
+        format: /type=(\d+) state=(\d+) cpu_id=(\d)+/,
+        handler: function(importer, event) {
+          var targetCpuNumber = parseInt(event[3]);
+          var targetCpu = importer.getOrCreateCpuState(targetCpuNumber);
+          var powerCounter = targetCpu.cpu.getOrCreateCounter('', 'Power Frequency');
+          if (powerCounter.numSeries == 0) {
+            powerCounter.seriesNames.push('state');
+            powerCounter.seriesColors.push(
+                tracing.getStringColorId(powerCounter.name + '.' + 'state'));
+          }
+          var powerState = parseInt(event[2]);
+          powerCounter.timestamps.push(event.timestamp);
+          powerCounter.samples.push(powerState);
+        }
+      },
+
+      'cpu_frequency': {
+        format: /state=(\d+) cpu_id=(\d)+/,
+        handler: function(importer, event) {
+          var targetCpuNumber = parseInt(event[2]);
+          var targetCpu = importer.getOrCreateCpuState(targetCpuNumber);
+          var powerCounter = targetCpu.cpu.getOrCreateCounter('', 'Clock Frequency');
+          if (powerCounter.numSeries == 0) {
+            powerCounter.seriesNames.push('state');
+            powerCounter.seriesColors.push(
+                tracing.getStringColorId(powerCounter.name + '.' + 'state'));
+          }
+          var powerState = parseInt(event[1]);
+          powerCounter.timestamps.push(event.timestamp);
+          powerCounter.samples.push(powerState);
+        }
+      },
+
+      'cpu_idle': {
+        format: /state=(\d+) cpu_id=(\d)+/,
+        handler: function(importer, event) {
+          var targetCpuNumber = parseInt(event[2]);
+          var targetCpu = importer.getOrCreateCpuState(targetCpuNumber);
+          var powerCounter = targetCpu.cpu.getOrCreateCounter('', 'C-State');
+          if (powerCounter.numSeries == 0) {
+            powerCounter.seriesNames.push('state');
+            powerCounter.seriesColors.push(
+                tracing.getStringColorId(powerCounter.name));
+          }
+          var powerState = parseInt(event[1]);
+          // NB: 4294967295/-1 means an exit from the current state
+          if (powerState != 4294967295)
+            powerCounter.samples.push(powerState);
+          else
+            powerCounter.samples.push(0);
+          powerCounter.timestamps.push(event.timestamp);
+        }
+      },
+
+      'workqueue_execute_start': {
+        // workqueue_execute_start: work struct c7a8a89c: function MISRWrapper
+        format: /work struct (.+): function (\S+)/,
+        handler: function(importer, event) {
+          var kthread = importer.getOrCreateKernelThread(event.taskId);
+          importer.openSlice(kthread, event[2], event.timestamp);
+        }
+      },
+
+      'workqueue_execute_end': {
+        // workqueue_execute_end: work struct c7a8a89c
+        format: /work struct (.+)/,
+        handler: function(importer, event) {
+          var kthread = importer.getOrCreateKernelThread(event.taskId);
+          importer.closeSlice(kthread, event.timestamp, {});
+        }
+      },
+
+      'workqueue_queue_work': {
+        // ignored for now
+      },
+
+      'workqueue_activate_work': {
+        // ignored for now
+      },
+
+      'i915_gem_object_pwrite': {
+        format: /obj=(.+), offset=(\d+), len=(\d+)/,
+        handler: function(importer, event) {
+          var obj = event[1];
+          var offset = parseInt(event[2]);
+          var len = parseInt(event[3]);
+          var kthread = importer.getOrCreateKernelThread('i915_gem', 0, 1);
+          importer.openSlice(kthread, 'pwrite:' + obj, event.timestamp);
+          importer.closeSlice(kthread, event.timestamp, {
+                obj: obj,
+                offset: offset,
+                len: len
+              });
+        }
+      },
+
+      'i915_flip_request': {
+        format: /plane=(\d+), obj=(.+)/,
+        handler: function(importer, event) {
+          var plane = parseInt(event[1]);
+          var obj = event[2];
+          // use i915_obj_plane?
+          var kthread = importer.getOrCreateKernelThread('i915_flip', 0, 2);
+          importer.openSlice(kthread, 'flip:' + obj + '/' + plane, event.timestamp);
+        }
+      },
+
+      'i915_flip_complete': {
+        format: /plane=(\d+), obj=(.+)/,
+        handler: function(importer, event) {
+          var plane = parseInt(event[1]);
+          var obj = event[2];
+          // use i915_obj_plane?
+          var kthread = importer.getOrCreateKernelThread('i915_flip', 0, 2);
+          importer.closeSlice(kthread, event.timestamp, {
+                obj: obj,
+                plane: plane
+              });
+        }
+      },
+
+      'tracing_mark_write': {
+        handler: function(importer, event) {
+          var eventData = traceEventClockSyncRE.exec(event.info);
+          if (eventData) {
+            importer.clockSyncRecords_.push({
+              perfTS: event.timestamp,
+              parentTS: eventData[1] * 1000
+            });
+          } else {
+            var eventData = event.info.split('|')
+            switch (eventData[0]) {
+              case 'B':
+                var pid = parseInt(eventData[1]);
+                var name = eventData[2];
+                importer.processBegin(event.taskId, name, event.timestamp, pid);
+                break;
+              case 'E':
+                importer.processEnd(event.taskId, event.timestamp);
+                break;
+              case 'C':
+                var pid = parseInt(eventData[1]);
+                var name = eventData[2];
+                var value = parseInt(eventData[3]);
+                importer.processCounter(name, event.timestamp, value, pid);
+                break;
+              default:
+                importer.malformedEvent(event.name);
+                break;
+            }
+          }
+        }
+      },
     }
   };
 
+  // NB: old-style trace markers; deprecated
+  LinuxPerfImporter.prototype.eventDefinitions['0'] =
+      LinuxPerfImporter.prototype.eventDefinitions['tracing_mark_write'];
+
+  TestExports.eventDefinitions = LinuxPerfImporter.prototype.eventDefinitions;
+
   tracing.TimelineModel.registerImporter(LinuxPerfImporter);
 
   return {
diff --git a/src/tracing/linux_perf_importer_test.html b/src/tracing/linux_perf_importer_test.html
index 847e111..db3038d 100644
--- a/src/tracing/linux_perf_importer_test.html
+++ b/src/tracing/linux_perf_importer_test.html
@@ -30,10 +30,11 @@
   assertNotNull(x);
   assertEquals('<idle>-0', x[1]);
   assertEquals('001', x[2]);
-  assertEquals('4467.843475', x[3]);
-  assertEquals('sched_switch', x[4]);
+  assertEquals(undefined, x[3]);
+  assertEquals('4467.843475', x[4]);
+  assertEquals('sched_switch', x[5]);
   assertEquals('prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ==> ' +
-      'next_comm=SurfaceFlinger next_pid=178 next_prio=112', x[5]);
+      'next_comm=SurfaceFlinger next_pid=178 next_prio=112', x[6]);
 
   var x = re.exec('Binder Thread #-647   [001]   260.464294: sched_switch: ' +
       'prev_comm=Binder Thread # prev_pid=647 prev_prio=120 prev_state=D ==> ' +
@@ -42,7 +43,7 @@
 }
 
 function testSchedSwitchRE() {
-  var re = tracing._LinuxPerfImporterTestExports.schedSwitchRE;
+  var re = tracing._LinuxPerfImporterTestExports.eventDefinitions['sched_switch'].format;
   var x = re.exec('prev_comm=swapper prev_pid=0 prev_prio=120 prev_state=R ' +
       '==> next_comm=SurfaceFlinger next_pid=178 next_prio=112');
   assertNotNull(x);
@@ -68,7 +69,7 @@
 }
 
 function testSchedWakeupRE() {
-  var re = tracing._LinuxPerfImporterTestExports.schedWakeupRE;
+  var re = tracing._LinuxPerfImporterTestExports.eventDefinitions['sched_wakeup'].format;
   var x = re.exec(
       'comm=SensorService pid=207 prio=112 success=1 target_cpu=000');
   assertNotNull(x);
diff --git a/systrace.py b/systrace.py
index 98a143f..0132279 100755
--- a/systrace.py
+++ b/systrace.py
@@ -10,7 +10,7 @@
 the kernel.  It creates an HTML file for visualizing the trace.
 """
 
-import errno, optparse, os, select, subprocess, sys, time, zlib
+import errno, optparse, os, select, subprocess, sys, time, zlib, config
 
 # This list is based on the tags in frameworks/native/include/utils/Trace.h.
 trace_tag_bits = {
@@ -49,6 +49,9 @@
                     help='set the enabled trace tags and exit; set to a ' +
                     'comma separated list of: ' +
                     ', '.join(trace_tag_bits.iterkeys()))
+  parser.add_option('--link-assets', dest='link_assets', default=False,
+                    action='store_true', help='link to original CSS or JS resources '
+                    'instead of embedding them')
   options, args = parser.parse_args()
 
   if options.set_tags:
@@ -94,10 +97,15 @@
       parser.error('the trace buffer size must be a positive number')
 
   script_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
-  css_filename = os.path.join(script_dir, 'style.css')
-  js_filename = os.path.join(script_dir, 'script.js')
-  css = open(css_filename).read()
-  js = open(js_filename).read()
+
+  if options.link_assets:
+    css = '\n'.join(linked_css_tag % (os.path.join(script_dir, f)) for f in config.css_in_files)
+    js = '\n'.join(linked_js_tag % (os.path.join(script_dir, f)) for f in config.js_in_files)
+  else:
+    css_filename = os.path.join(script_dir, config.css_out_file)
+    js_filename = os.path.join(script_dir, config.js_out_file)
+    css = compiled_css_tag % (open(css_filename).read())
+    js = compiled_js_tag % (open(js_filename).read())
 
   html_filename = options.output_file
   html_file = open(html_filename, 'w')
@@ -159,8 +167,8 @@
 <html>
 <head i18n-values="dir:textdirection;">
 <title>Android System Trace</title>
-<style type="text/css">%s</style>
-<script language="javascript">%s</script>
+%s
+%s
 <style>
   .view {
     overflow: hidden;
@@ -185,5 +193,11 @@
 </html>
 """
 
+compiled_css_tag = """<style type="text/css">%s</style>"""
+compiled_js_tag = """<script language="javascript">%s</script>"""
+
+linked_css_tag = """<link rel="stylesheet" href="%s"></link>"""
+linked_js_tag = """<script language="javascript" src="%s"></script>"""
+
 if __name__ == '__main__':
   main()
diff --git a/update.py b/update.py
index 183949c..357e1a0 100755
--- a/update.py
+++ b/update.py
@@ -1,50 +1,12 @@
 #!/usr/bin/python
 
-import httplib, urllib, subprocess, sys
-
-js_in_files = (
-  'init.js',
-  'src/shared/js/cr.js',
-  'src/shared/js/cr/event_target.js',
-  'src/shared/js/cr/ui.js',
-  'src/shared/js/cr/ui/focus_outline_manager.js',
-  'src/shared/js/cr/ui/tabs.js',
-  'src/shared/js/util.js',
-  'src/tracing/overlay.js',
-  'src/tracing/tracing_controller.js',
-  'src/tracing/timeline_model.js',
-  'src/tracing/linux_perf_importer.js',
-  'src/tracing/trace_event_importer.js',
-  'src/tracing/sorted_array_utils.js',
-  'src/tracing/measuring_stick.js',
-  'src/tracing/timeline.js',
-  'src/tracing/timeline_analysis.js',
-  'src/tracing/timeline_track.js',
-  'src/tracing/fast_rect_renderer.js',
-  'src/tracing/profiling_view.js',
-  'src/tracing/timeline_view.js',
-)
-
-css_in_files = (
-  'src/shared/css/tabs.css',
-  'src/shared/css/widgets.css',
-  'src/tracing/overlay.css',
-  'src/tracing/profiling_view.css',
-  'src/tracing/timeline_analysis.css',
-  'src/tracing/timeline_view.css',
-  'src/tracing/timeline.css',
-  'src/tracing/tracing_controller.css',
-)
-
-js_out_file = 'script.js'
-
-css_out_file = 'style.css'
+import httplib, urllib, subprocess, sys, config
 
 # Read all the Javascript files.
-js_code = [('js_code', open(f).read()) for f in js_in_files]
+js_code = [('js_code', open(f).read()) for f in config.js_in_files]
 
 # Read all the CSS files and concatenate them.
-css_code = ''.join(open(f).read() for f in css_in_files)
+css_code = ''.join(open(f).read() for f in config.css_in_files)
 
 # Define the parameters for the POST request and encode them in
 # a URL-safe format.
@@ -67,14 +29,14 @@
   print sys.stderr, "error returned from JS compile service: %d" % response.status
   sys.exit(1)
 
-open(js_out_file, 'wt').write(data)
-print 'Generated %s.  Check the file to see if errors occured!' % js_out_file
+open(config.js_out_file, 'wt').write(data)
+print 'Generated %s.  Check the file to see if errors occured!' % config.js_out_file
 
-yuic_args = ['yui-compressor', '--type', 'css', '-o', css_out_file]
+yuic_args = ['yui-compressor', '--type', 'css', '-o', config.css_out_file]
 p = subprocess.Popen(yuic_args, stdin=subprocess.PIPE)
 p.communicate(input=css_code)
 if p.wait() != 0:
-  print 'Failed to generate %s.' % css_out_file
+  print 'Failed to generate %s.' % config.css_out_file
   sys.exit(1)
 
-print 'Generated %s.' % css_out_file
+print 'Generated %s.' % config.css_out_file