HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Jelly Bean MR2
|
4.3_r1
下载
查看原文件
收藏
根目录
external
chromium-trace
trace-viewer
src
importer
linux_perf_importer.js
// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. /** * @fileoverview Imports text files in the Linux event trace format into the * model. This format is output both by sched_trace and by Linux's perf * tool. * * This importer assumes the events arrive as a string. The unit tests provide * examples of the trace format. * * Linux scheduler traces use a definition for 'pid' that is different than * tracing uses. Whereas tracing uses pid to identify a specific process, a pid * in a linux trace refers to a specific thread within a process. Within this * file, we the definition used in Linux traces, as it improves the importing * code's readability. */ 'use strict'; base.require('model'); base.require('color_scheme'); base.require('importer.linux_perf.bus_parser'); base.require('importer.linux_perf.clock_parser'); base.require('importer.linux_perf.cpufreq_parser'); base.require('importer.linux_perf.disk_parser'); base.require('importer.linux_perf.drm_parser'); base.require('importer.linux_perf.exynos_parser'); base.require('importer.linux_perf.gesture_parser'); base.require('importer.linux_perf.i915_parser'); base.require('importer.linux_perf.mali_parser'); base.require('importer.linux_perf.power_parser'); base.require('importer.linux_perf.sched_parser'); base.require('importer.linux_perf.workqueue_parser'); base.require('importer.linux_perf.android_parser'); base.require('importer.linux_perf.kfunc_parser'); base.exportTo('tracing.importer', function() { /** * Represents the scheduling state for a single thread. * @constructor */ function CpuState(cpu) { this.cpu = cpu; } CpuState.prototype = { __proto__: Object.prototype, /** * Switches the active pid on this Cpu. If necessary, add a Slice * to the cpu representing the time spent on that Cpu since the last call to * switchRunningLinuxPid. */ switchRunningLinuxPid: function(importer, prevState, ts, pid, comm, prio) { // Generate a slice if the last active pid was not the idle task if (this.lastActivePid !== undefined && this.lastActivePid != 0) { var duration = ts - this.lastActiveTs; var thread = importer.threadsByLinuxPid[this.lastActivePid]; var name; if (thread) name = thread.userFriendlyName; else name = this.lastActiveComm; var slice = new tracing.model.Slice('', name, tracing.getStringColorId(name), this.lastActiveTs, { comm: this.lastActiveComm, tid: this.lastActivePid, prio: this.lastActivePrio, stateWhenDescheduled: prevState }, duration); this.cpu.slices.push(slice); } this.lastActiveTs = ts; this.lastActivePid = pid; this.lastActiveComm = comm; this.lastActivePrio = prio; } }; /** * Imports linux perf events into a specified model. * @constructor */ function LinuxPerfImporter(model, events) { this.importPriority = 2; this.model_ = model; this.events_ = events; this.clockSyncRecords_ = []; this.cpuStates_ = {}; this.wakeups_ = []; this.kernelThreadStates_ = {}; this.buildMapFromLinuxPidsToThreads(); this.lineNumberBase = 0; this.lineNumber = -1; this.pseudoThreadCounter = 1; this.parsers_ = []; this.eventHandlers_ = {}; } TestExports = {}; // Matches the trace record in 3.2 and later with the print-tgid option: //
-0 0 [001] d... 1.23: sched_switch // // A TGID (Thread Group ID) is basically what the Linux kernel calls what // userland refers to as a process ID (as opposed to a Linux pid, which is // what userland calls a thread ID). var lineREWithTGID = new RegExp( '^\\s*(.+)-(\\d+)\\s+\\(\\s*(\\d+|-+)\\)\\s\\[(\\d+)\\]' + '\\s+[dX.][N.][Hhs.][0-9a-f.]' + '\\s+(\\d+\\.\\d+):\\s+(\\S+):\\s(.*)$'); var lineParserWithTGID = function(line) { var groups = lineREWithTGID.exec(line); if (!groups) { return groups; } var tgid = groups[3]; if (tgid[0] === '-') tgid = undefined; return { threadName: groups[1], pid: groups[2], tgid: tgid, cpuNumber: groups[4], timestamp: groups[5], eventName: groups[6], details: groups[7] }; } TestExports.lineParserWithTGID = lineParserWithTGID; // Matches the default trace record in 3.2 and later (includes irq-info): //
-0 [001] d... 1.23: sched_switch var lineREWithIRQInfo = new RegExp( '^\\s*(.+)-(\\d+)\\s+\\[(\\d+)\\]' + '\\s+[dX.][N.][Hhs.][0-9a-f.]' + '\\s+(\\d+\\.\\d+):\\s+(\\S+):\\s(.*)$'); var lineParserWithIRQInfo = function(line) { var groups = lineREWithIRQInfo.exec(line); if (!groups) { return groups; } return { threadName: groups[1], pid: groups[2], cpuNumber: groups[3], timestamp: groups[4], eventName: groups[5], details: groups[6] }; } TestExports.lineParserWithIRQInfo = lineParserWithIRQInfo; // Matches the default trace record pre-3.2: //
-0 [001] 1.23: sched_switch var lineREWithLegacyFmt = /^\s*(.+)-(\d+)\s+\[(\d+)\]\s*(\d+\.\d+):\s+(\S+):\s(.*)$/; var lineParserWithLegacyFmt = function(line) { var groups = lineREWithLegacyFmt.exec(line); if (!groups) { return groups; } return { threadName: groups[1], pid: groups[2], cpuNumber: groups[3], timestamp: groups[4], eventName: groups[5], details: groups[6] }; } TestExports.lineParserWithLegacyFmt = lineParserWithLegacyFmt; // 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; // Some kernel trace events are manually classified in slices and // hand-assigned a pseudo PID. var pseudoKernelPID = 0; /** * Deduce the format of trace data. Linix kernels prior to 3.3 used one * format (by default); 3.4 and later used another. Additionally, newer * kernels can optionally trace the TGID. * * @return {function} the function for parsing data when the format is * recognized; otherwise null. */ function autoDetectLineParser(line) { if (lineREWithTGID.test(line)) return lineParserWithTGID; if (lineREWithIRQInfo.test(line)) return lineParserWithIRQInfo; if (lineREWithLegacyFmt.test(line)) return lineParserWithLegacyFmt; return null; }; TestExports.autoDetectLineParser = autoDetectLineParser; /** * Guesses whether the provided events is a Linux perf string. * Looks for the magic string "# tracer" at the start of the file, * or the typical task-pid-cpu-timestamp-function sequence of a typical * trace's body. * * @return {boolean} True when events is a linux perf array. */ LinuxPerfImporter.canImport = function(events) { if (!(typeof(events) === 'string' || events instanceof String)) return false; if (LinuxPerfImporter._extractEventsFromSystraceHTML(events, false).ok) return true; if (/^# tracer:/.test(events)) return true; var m = /^(.+)\n/.exec(events); if (m) events = m[1]; if (autoDetectLineParser(events)) return true; return false; }; LinuxPerfImporter._extractEventsFromSystraceHTML = function( incoming_events, produce_result) { var failure = {ok: false}; if (produce_result === undefined) produce_result = true; if (/^/.test(incoming_events) == false) return failure; var lines = incoming_events.split('\n'); var cur_line = 1; function advanceToLineMatching(regex) { for (; cur_line < lines.length; cur_line++) { if (regex.test(lines[cur_line])) return true; } return false; } // Try to find the data... if (!advanceToLineMatching(/^
登录后可以享受更多权益
您还没有登录,登录后您可以:
收藏Android系统代码
收藏喜欢的文章
多个平台共享账号
去登录
首次使用?从这里
注册