1<!DOCTYPE html> 2<!-- 3Copyright (c) 2013 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7 8<link rel="import" href="/tracing/extras/importer/linux_perf/parser.html"> 9<link rel="import" href="/tracing/model/counter_series.html"> 10 11<script> 12'use strict'; 13 14/** 15 * @fileoverview Parses trace_marker events that were inserted in the trace by 16 * userland. 17 */ 18tr.exportTo('tr.e.importer.linux_perf', function() { 19 var ColorScheme = tr.b.ColorScheme; 20 var Parser = tr.e.importer.linux_perf.Parser; 21 22 /** 23 * Parses linux trace mark events that were inserted in the trace by userland. 24 * @constructor 25 */ 26 function BusParser(importer) { 27 Parser.call(this, importer); 28 29 importer.registerEventHandler('memory_bus_usage', 30 BusParser.prototype.traceMarkWriteBusEvent.bind(this)); 31 32 this.model_ = importer.model_; 33 this.ppids_ = {}; 34 } 35 36 BusParser.prototype = { 37 __proto__: Parser.prototype, 38 39 traceMarkWriteBusEvent: function(eventName, cpuNumber, pid, ts, 40 eventBase, threadName) { 41 var re = new RegExp('bus=(\\S+) rw_bytes=(\\d+) r_bytes=(\\d+) ' + 42 'w_bytes=(\\d+) cycles=(\\d+) ns=(\\d+)'); 43 var event = re.exec(eventBase.details); 44 45 var name = event[1]; 46 var rw_bytes = parseInt(event[2]); 47 var r_bytes = parseInt(event[3]); 48 var w_bytes = parseInt(event[4]); 49 var cycles = parseInt(event[5]); 50 var ns = parseInt(event[6]); 51 52 // BW in MB/s 53 var r_bw = r_bytes * 1000000000 / ns; 54 r_bw /= 1024 * 1024; 55 var w_bw = w_bytes * 1000000000 / ns; 56 w_bw /= 1024 * 1024; 57 58 var ctr = this.model_.kernel 59 .getOrCreateCounter(null, 'bus ' + name + ' read'); 60 if (ctr.numSeries === 0) { 61 ctr.addSeries(new tr.model.CounterSeries('value', 62 ColorScheme.getColorIdForGeneralPurposeString( 63 ctr.name + '.' + 'value'))); 64 } 65 ctr.series.forEach(function(series) { 66 series.addCounterSample(ts, r_bw); 67 }); 68 69 ctr = this.model_.kernel 70 .getOrCreateCounter(null, 'bus ' + name + ' write'); 71 if (ctr.numSeries === 0) { 72 ctr.addSeries(new tr.model.CounterSeries('value', 73 ColorScheme.getColorIdForGeneralPurposeString( 74 ctr.name + '.' + 'value'))); 75 } 76 ctr.series.forEach(function(series) { 77 series.addCounterSample(ts, r_bw); 78 }); 79 80 return true; 81 } 82 }; 83 84 Parser.register(BusParser); 85 86 return { 87 BusParser: BusParser 88 }; 89}); 90</script> 91