1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 /** 6 * @fileoverview Parses trace_marker events that were inserted in the trace by 7 * userland. 8 */ 9 base.require('linux_perf_parser'); 10 base.exportTo('tracing', function() { 11 12 var LinuxPerfParser = tracing.LinuxPerfParser; 13 14 /** 15 * Parses linux trace mark events that were inserted in the trace by userland. 16 * @constructor 17 */ 18 function LinuxPerfAndroidParser(importer) { 19 LinuxPerfParser.call(this, importer); 20 21 importer.registerEventHandler('tracing_mark_write:android', 22 LinuxPerfAndroidParser.prototype.traceMarkWriteAndroidEvent.bind(this)); 23 importer.registerEventHandler('0:android', 24 LinuxPerfAndroidParser.prototype.traceMarkWriteAndroidEvent.bind(this)); 25 26 this.model_ = importer.model_; 27 this.ppids_ = {}; 28 } 29 30 LinuxPerfAndroidParser.prototype = { 31 __proto__: LinuxPerfParser.prototype, 32 33 traceMarkWriteAndroidEvent: function(eventName, cpuNumber, pid, ts, 34 eventBase, threadName) { 35 var eventData = eventBase[2].split('|'); 36 switch (eventData[0]) { 37 case 'B': 38 var ppid = parseInt(eventData[1]); 39 var name = eventData[2]; 40 var thread = this.model_.getOrCreateProcess(ppid) 41 .getOrCreateThread(pid); 42 thread.name = threadName; 43 if (!thread.isTimestampValidForBeginOrEnd(ts)) { 44 this.model_.importErrors.push( 45 'Timestamps are moving backward.'); 46 return false; 47 } 48 49 this.ppids_[pid] = ppid; 50 thread.beginSlice(null, name, ts, {}); 51 52 break; 53 case 'E': 54 var ppid = this.ppids_[pid]; 55 if (ppid === undefined) { 56 // Silently ignore unmatched E events. 57 break; 58 } 59 60 var thread = this.model_.getOrCreateProcess(ppid) 61 .getOrCreateThread(pid); 62 if (!thread.openSliceCount) { 63 // Silently ignore unmatched E events. 64 break; 65 } 66 67 var slice = thread.endSlice(ts); 68 69 // TODO(jgennis): add real support for arguments 70 args = {}; 71 for (var arg in args) { 72 if (slice.args[arg] !== undefined) { 73 this.model_.importErrors.push( 74 'Both the B and E events of ' + slice.name + 75 'provided values for argument ' + arg + '. ' + 76 'The value of the E event will be used.'); 77 } 78 slice.args[arg] = event.args[arg]; 79 } 80 81 break; 82 case 'C': 83 var ppid = parseInt(eventData[1]); 84 var name = eventData[2]; 85 var value = parseInt(eventData[3]); 86 87 var ctr = this.model_.getOrCreateProcess(ppid) 88 .getOrCreateCounter(null, name); 89 // Initialize the counter's series fields if needed. 90 if (ctr.numSeries == 0) { 91 ctr.seriesNames.push('value'); 92 ctr.seriesColors.push( 93 tracing.getStringColorId(ctr.name + '.' + 'value')); 94 } 95 96 // Add the sample value. 97 ctr.timestamps.push(ts); 98 ctr.samples.push(value); 99 100 break; 101 default: 102 return false; 103 } 104 105 return true; 106 }, 107 }; 108 109 LinuxPerfParser.registerSubtype(LinuxPerfAndroidParser); 110 111 return { 112 LinuxPerfAndroidParser: LinuxPerfAndroidParser 113 }; 114 }); 115