OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" | 5 #include "platform/v8_inspector/V8ProfilerAgentImpl.h" |
6 | 6 |
7 #include "platform/v8_inspector/Atomics.h" | 7 #include "platform/v8_inspector/Atomics.h" |
8 #include "platform/v8_inspector/V8InspectorImpl.h" | 8 #include "platform/v8_inspector/V8InspectorImpl.h" |
9 #include "platform/v8_inspector/V8InspectorSessionImpl.h" | 9 #include "platform/v8_inspector/V8InspectorSessionImpl.h" |
10 #include "platform/v8_inspector/V8StackTraceImpl.h" | 10 #include "platform/v8_inspector/V8StackTraceImpl.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 return array; | 46 return array; |
47 } | 47 } |
48 | 48 |
49 std::unique_ptr<protocol::Profiler::CPUProfileNode> buildInspectorObjectFor(v8::
Isolate* isolate, const v8::CpuProfileNode* node) | 49 std::unique_ptr<protocol::Profiler::CPUProfileNode> buildInspectorObjectFor(v8::
Isolate* isolate, const v8::CpuProfileNode* node) |
50 { | 50 { |
51 v8::HandleScope handleScope(isolate); | 51 v8::HandleScope handleScope(isolate); |
52 | 52 |
53 std::unique_ptr<protocol::Array<protocol::Profiler::CPUProfileNode>> childre
n = protocol::Array<protocol::Profiler::CPUProfileNode>::create(); | 53 std::unique_ptr<protocol::Array<int>> children = protocol::Array<int>::creat
e(); |
54 const int childrenCount = node->GetChildrenCount(); | 54 const int childrenCount = node->GetChildrenCount(); |
55 for (int i = 0; i < childrenCount; i++) { | 55 for (int i = 0; i < childrenCount; i++) |
56 const v8::CpuProfileNode* child = node->GetChild(i); | 56 children->addItem(node->GetChild(i)->GetNodeId()); |
57 children->addItem(buildInspectorObjectFor(isolate, child)); | |
58 } | |
59 | 57 |
60 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> posit
ionTicks = buildInspectorObjectForPositionTicks(node); | 58 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> posit
ionTicks = buildInspectorObjectForPositionTicks(node); |
61 | 59 |
62 std::unique_ptr<protocol::Runtime::CallFrame> callFrame = protocol::Runtime:
:CallFrame::create() | 60 std::unique_ptr<protocol::Runtime::CallFrame> callFrame = protocol::Runtime:
:CallFrame::create() |
63 .setFunctionName(toProtocolString(node->GetFunctionName())) | 61 .setFunctionName(toProtocolString(node->GetFunctionName())) |
64 .setScriptId(String16::fromInteger(node->GetScriptId())) | 62 .setScriptId(String16::fromInteger(node->GetScriptId())) |
65 .setUrl(toProtocolString(node->GetScriptResourceName())) | 63 .setUrl(toProtocolString(node->GetScriptResourceName())) |
66 .setLineNumber(node->GetLineNumber() - 1) | 64 .setLineNumber(node->GetLineNumber() - 1) |
67 .setColumnNumber(node->GetColumnNumber() - 1) | 65 .setColumnNumber(node->GetColumnNumber() - 1) |
68 .build(); | 66 .build(); |
(...skipping 18 matching lines...) Expand all Loading... |
87 | 85 |
88 std::unique_ptr<protocol::Array<double>> buildInspectorObjectForTimestamps(v8::C
puProfile* v8profile) | 86 std::unique_ptr<protocol::Array<double>> buildInspectorObjectForTimestamps(v8::C
puProfile* v8profile) |
89 { | 87 { |
90 std::unique_ptr<protocol::Array<double>> array = protocol::Array<double>::cr
eate(); | 88 std::unique_ptr<protocol::Array<double>> array = protocol::Array<double>::cr
eate(); |
91 int count = v8profile->GetSamplesCount(); | 89 int count = v8profile->GetSamplesCount(); |
92 for (int i = 0; i < count; i++) | 90 for (int i = 0; i < count; i++) |
93 array->addItem(v8profile->GetSampleTimestamp(i)); | 91 array->addItem(v8profile->GetSampleTimestamp(i)); |
94 return array; | 92 return array; |
95 } | 93 } |
96 | 94 |
| 95 void flattenNodesTree(v8::Isolate* isolate, const v8::CpuProfileNode* node, prot
ocol::Array<protocol::Profiler::CPUProfileNode>* list) |
| 96 { |
| 97 list->addItem(buildInspectorObjectFor(isolate, node)); |
| 98 const int childrenCount = node->GetChildrenCount(); |
| 99 for (int i = 0; i < childrenCount; i++) |
| 100 flattenNodesTree(isolate, node->GetChild(i), list); |
| 101 } |
| 102 |
97 std::unique_ptr<protocol::Profiler::CPUProfile> createCPUProfile(v8::Isolate* is
olate, v8::CpuProfile* v8profile) | 103 std::unique_ptr<protocol::Profiler::CPUProfile> createCPUProfile(v8::Isolate* is
olate, v8::CpuProfile* v8profile) |
98 { | 104 { |
| 105 std::unique_ptr<protocol::Array<protocol::Profiler::CPUProfileNode>> nodes =
protocol::Array<protocol::Profiler::CPUProfileNode>::create(); |
| 106 flattenNodesTree(isolate, v8profile->GetTopDownRoot(), nodes.get()); |
| 107 |
99 std::unique_ptr<protocol::Profiler::CPUProfile> profile = protocol::Profiler
::CPUProfile::create() | 108 std::unique_ptr<protocol::Profiler::CPUProfile> profile = protocol::Profiler
::CPUProfile::create() |
100 .setHead(buildInspectorObjectFor(isolate, v8profile->GetTopDownRoot())) | 109 .setNodes(std::move(nodes)) |
101 .setStartTime(static_cast<double>(v8profile->GetStartTime()) / 1000000) | 110 .setStartTime(static_cast<double>(v8profile->GetStartTime()) / 1000000) |
102 .setEndTime(static_cast<double>(v8profile->GetEndTime()) / 1000000).buil
d(); | 111 .setEndTime(static_cast<double>(v8profile->GetEndTime()) / 1000000).buil
d(); |
103 profile->setSamples(buildInspectorObjectForSamples(v8profile)); | 112 profile->setSamples(buildInspectorObjectForSamples(v8profile)); |
104 profile->setTimestamps(buildInspectorObjectForTimestamps(v8profile)); | 113 profile->setTimestamps(buildInspectorObjectForTimestamps(v8profile)); |
105 return profile; | 114 return profile; |
106 } | 115 } |
107 | 116 |
108 std::unique_ptr<protocol::Debugger::Location> currentDebugLocation(V8InspectorIm
pl* inspector) | 117 std::unique_ptr<protocol::Debugger::Location> currentDebugLocation(V8InspectorIm
pl* inspector) |
109 { | 118 { |
110 std::unique_ptr<V8StackTrace> callStack = inspector->captureStackTrace(1); | 119 std::unique_ptr<V8StackTrace> callStack = inspector->captureStackTrace(1); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 v8::CpuProfiler* V8ProfilerAgentImpl::profiler() | 320 v8::CpuProfiler* V8ProfilerAgentImpl::profiler() |
312 { | 321 { |
313 #if ENSURE_V8_VERSION(5, 4) | 322 #if ENSURE_V8_VERSION(5, 4) |
314 return m_profiler; | 323 return m_profiler; |
315 #else | 324 #else |
316 return m_isolate->GetCpuProfiler(); | 325 return m_isolate->GetCpuProfiler(); |
317 #endif | 326 #endif |
318 } | 327 } |
319 | 328 |
320 } // namespace blink | 329 } // namespace blink |
OLD | NEW |