clock_parser.js revision 66a37686207944273ced825e0e8b6b6375f8c3de
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'use strict'; 6 7/** 8 * @fileoverview Parses trace_marker events that were inserted in the trace by 9 * userland. 10 */ 11base.require('tracing.importer.linux_perf.parser'); 12base.exportTo('tracing.importer.linux_perf', function() { 13 14 var Parser = tracing.importer.linux_perf.Parser; 15 16 /** 17 * Parses linux trace mark events that were inserted in the trace by userland. 18 * @constructor 19 */ 20 function ClockParser(importer) { 21 Parser.call(this, importer); 22 23 importer.registerEventHandler('clock_set_rate', 24 ClockParser.prototype.traceMarkWriteClockEvent.bind(this)); 25 26 this.model_ = importer.model_; 27 this.ppids_ = {}; 28 } 29 30 ClockParser.prototype = { 31 __proto__: Parser.prototype, 32 33 traceMarkWriteClockEvent: function(eventName, cpuNumber, pid, ts, 34 eventBase, threadName) { 35 var event = /(\S+) state=(\d+) cpu_id=(\d+)/.exec(eventBase.details); 36 37 38 var name = event[1]; 39 var rate = parseInt(event[2]); 40 41 var ctr = this.model_.getOrCreateProcess(0) 42 .getOrCreateCounter(null, name); 43 // Initialize the counter's series fields if needed. 44 if (ctr.numSeries == 0) { 45 ctr.seriesNames.push('value'); 46 ctr.seriesColors.push( 47 tracing.getStringColorId(ctr.name + '.' + 'value')); 48 } 49 50 // Add the sample value. 51 ctr.timestamps.push(ts); 52 ctr.samples.push(rate); 53 54 return true; 55 } 56 }; 57 58 Parser.registerSubtype(ClockParser); 59 60 return { 61 ClockParser: ClockParser 62 }; 63}); 64