Upstream version 6.34.113.0
[platform/framework/web/crosswalk.git] / src / v8 / src / third_party / xdk / xdk-v8.h
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.
4
5 #ifndef V8_XDK_H_
6 #define V8_XDK_H_
7
8 // ----------------------------------------------------------------------------
9 //
10 //                          XDK profiling support for V8
11 //
12 //  SOURCES:
13 //
14 //  1. XDK agent source files are located in v8/src/third_party/xdk folder.
15 //
16 //       To integrate this stuff into V8 build system you need to modify
17 //       two v8 files:
18 //
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',],
24 //           }],
25 //
26 //  2. Two V8 files v8/src/log.cc and v8/src/log.h need to be modified
27 //
28 //       The changes related to start CPU ticks collection using V8 built-in
29 //       profiler.
30 //       We are working on reduce these changes up to 2 lines:
31 //
32 //           #include "third_party/xdk/xdk-v8.h"
33 //           bool Logger::SetUp(Isolate* isolate) {
34 //             ...
35 //             xdk::XDKInitializeForV8(isolate);
36 //             ...
37 //           }
38 //
39 //  OVERVIEW:
40 //
41 //  Start up
42 //
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
45 //    collected).
46 //
47 //           v8/src/log.cc:
48 //           bool Logger::SetUp(Isolate* isolate) {
49 //             ...
50 //             xdk::XDKInitializeForV8(isolate);
51 //             ...
52 //           }
53 //
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
61 //         the agent.
62 //
63 //  Runtime
64 //
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)
69 //    (xdk-code-map.cc).
70 //
71 //    Start profiling
72 //
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
78 //
79 //    Stop profiling
80 //
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.
85 //
86 //      When collection is stopped that AppAnalyzer takes the trace file for
87 //      processing.
88 //
89 // ----------------------------------------------------------------------------
90
91 namespace xdk {
92
93 // This function
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);
101
102 bool XDKIsAgentAlive();
103
104 }  // namespace XDK
105
106 #endif  // V8_XDK_H_
107