1 // Copyright (c) 2013 Intel Corporation. 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.
8 // ----------------------------------------------------------------------------
10 // XDK profiling support for V8
14 // 1. XDK agent source files are located in v8/src/third_party/xdk folder.
16 // To integrate this stuff into V8 build system you need to modify
19 // 1. v8/build/features.gypi
20 // 'v8_enable_xdkprof': 1,
21 // 2. v8/tools/gyp/v8.gyp
22 // ['v8_enable_xdkprof==1', {
23 // 'dependencies': ['../../src/third_party/xdk/xdk-v8.gyp:v8_xdk',],
26 // 2. Two V8 files v8/src/log.cc and v8/src/log.h need to be modified
28 // The changes related to start CPU ticks collection using V8 built-in
30 // We are working on reduce these changes up to 2 lines:
32 // #include "third_party/xdk/xdk-v8.h"
33 // bool Logger::SetUp(Isolate* isolate) {
35 // xdk::XDKInitializeForV8(isolate);
43 // XDK agent is initialized as a part of V8 built-in profiler on process
44 // start up. V8 built-in profiler should be paused (CPU ticks are not
48 // bool Logger::SetUp(Isolate* isolate) {
50 // xdk::XDKInitializeForV8(isolate);
54 // XDKInitializeForV8() function
55 // 1. Checks whether XDK agent can be initialized. If a marker file is not
56 // found that initialization will be discarded.
57 // 2. Starts a listener thread to accept start / stop profiling command
58 // from AppAnalyzer (xdk/xdk-agent.cc).
59 // 3. Registeres a callback to consume the CodeAdded, CodeMoved,
60 // CodeDeleted events and events related to source line info by
65 // XDK profiler consumes the code events (EventHandler() in xdk/xdk-agent.cc)
66 // V8 emits these events even when CPU ticks collection is paused.
67 // The profiler uses the code events to maintain a function snapshot (list of
68 // code ranges assosiated with function name and source line info)
73 // When the profiler receives a command to start profiling that it calls
74 // resumeSampling() (xdk/xdk-agent.cc) which
75 // 1. Creates a new trace file to log the ticks and code events
76 // 2. Puts the function snapshot into the trace file
77 // 3. Resumes CPU ticks collection
81 // When the profiler receives a command to stop profiling that it calls
82 // pauseSampling() (xdk/xdk-agent.cc) which stops the CPU ticks collection.
83 // Note that the agent continues to consume the code events to maintain
84 // the function snapshot.
86 // When collection is stopped that AppAnalyzer takes the trace file for
89 // ----------------------------------------------------------------------------
94 // - Overrides the V8 flags to specify a new logfile for writting profiling data
95 // (CPU ticks and Code* events).
96 // - Registers callback to get line number info and code events from V8 built-in
97 // profiler. These data are needed to mantain the code map.
98 // - Starts the XDK agent listener thread which is awaiting for start and stop
99 // profiling commands.
100 void XDKInitializeForV8(v8::internal::Isolate* isolate);
102 bool XDKIsAgentAlive();