| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 77 |
| 78 std::unique_ptr<protocol::Array<int>> buildInspectorObjectForSamples(v8::CpuProf
ile* v8profile) | 78 std::unique_ptr<protocol::Array<int>> buildInspectorObjectForSamples(v8::CpuProf
ile* v8profile) |
| 79 { | 79 { |
| 80 std::unique_ptr<protocol::Array<int>> array = protocol::Array<int>::create()
; | 80 std::unique_ptr<protocol::Array<int>> array = protocol::Array<int>::create()
; |
| 81 int count = v8profile->GetSamplesCount(); | 81 int count = v8profile->GetSamplesCount(); |
| 82 for (int i = 0; i < count; i++) | 82 for (int i = 0; i < count; i++) |
| 83 array->addItem(v8profile->GetSample(i)->GetNodeId()); | 83 array->addItem(v8profile->GetSample(i)->GetNodeId()); |
| 84 return array; | 84 return array; |
| 85 } | 85 } |
| 86 | 86 |
| 87 std::unique_ptr<protocol::Array<double>> buildInspectorObjectForTimestamps(v8::C
puProfile* v8profile) | 87 std::unique_ptr<protocol::Array<int>> buildInspectorObjectForTimestamps(v8::CpuP
rofile* v8profile) |
| 88 { | 88 { |
| 89 std::unique_ptr<protocol::Array<double>> array = protocol::Array<double>::cr
eate(); | 89 std::unique_ptr<protocol::Array<int>> array = protocol::Array<int>::create()
; |
| 90 int count = v8profile->GetSamplesCount(); | 90 int count = v8profile->GetSamplesCount(); |
| 91 for (int i = 0; i < count; i++) | 91 uint64_t lastTime = v8profile->GetStartTime(); |
| 92 array->addItem(v8profile->GetSampleTimestamp(i)); | 92 for (int i = 0; i < count; i++) { |
| 93 uint64_t ts = v8profile->GetSampleTimestamp(i); |
| 94 array->addItem(static_cast<int>(ts - lastTime)); |
| 95 lastTime = ts; |
| 96 } |
| 93 return array; | 97 return array; |
| 94 } | 98 } |
| 95 | 99 |
| 96 void flattenNodesTree(v8::Isolate* isolate, const v8::CpuProfileNode* node, prot
ocol::Array<protocol::Profiler::CPUProfileNode>* list) | 100 void flattenNodesTree(v8::Isolate* isolate, const v8::CpuProfileNode* node, prot
ocol::Array<protocol::Profiler::CPUProfileNode>* list) |
| 97 { | 101 { |
| 98 list->addItem(buildInspectorObjectFor(isolate, node)); | 102 list->addItem(buildInspectorObjectFor(isolate, node)); |
| 99 const int childrenCount = node->GetChildrenCount(); | 103 const int childrenCount = node->GetChildrenCount(); |
| 100 for (int i = 0; i < childrenCount; i++) | 104 for (int i = 0; i < childrenCount; i++) |
| 101 flattenNodesTree(isolate, node->GetChild(i), list); | 105 flattenNodesTree(isolate, node->GetChild(i), list); |
| 102 } | 106 } |
| 103 | 107 |
| 104 std::unique_ptr<protocol::Profiler::CPUProfile> createCPUProfile(v8::Isolate* is
olate, v8::CpuProfile* v8profile) | 108 std::unique_ptr<protocol::Profiler::CPUProfile> createCPUProfile(v8::Isolate* is
olate, v8::CpuProfile* v8profile) |
| 105 { | 109 { |
| 106 std::unique_ptr<protocol::Array<protocol::Profiler::CPUProfileNode>> nodes =
protocol::Array<protocol::Profiler::CPUProfileNode>::create(); | 110 std::unique_ptr<protocol::Array<protocol::Profiler::CPUProfileNode>> nodes =
protocol::Array<protocol::Profiler::CPUProfileNode>::create(); |
| 107 flattenNodesTree(isolate, v8profile->GetTopDownRoot(), nodes.get()); | 111 flattenNodesTree(isolate, v8profile->GetTopDownRoot(), nodes.get()); |
| 108 | 112 |
| 109 std::unique_ptr<protocol::Profiler::CPUProfile> profile = protocol::Profiler
::CPUProfile::create() | 113 std::unique_ptr<protocol::Profiler::CPUProfile> profile = protocol::Profiler
::CPUProfile::create() |
| 110 .setNodes(std::move(nodes)) | 114 .setNodes(std::move(nodes)) |
| 111 .setStartTime(static_cast<double>(v8profile->GetStartTime()) / 1000000) | 115 .setStartTime(static_cast<double>(v8profile->GetStartTime())) |
| 112 .setEndTime(static_cast<double>(v8profile->GetEndTime()) / 1000000).buil
d(); | 116 .setEndTime(static_cast<double>(v8profile->GetEndTime())).build(); |
| 113 profile->setSamples(buildInspectorObjectForSamples(v8profile)); | 117 profile->setSamples(buildInspectorObjectForSamples(v8profile)); |
| 114 profile->setTimestamps(buildInspectorObjectForTimestamps(v8profile)); | 118 profile->setTimestampDeltas(buildInspectorObjectForTimestamps(v8profile)); |
| 115 return profile; | 119 return profile; |
| 116 } | 120 } |
| 117 | 121 |
| 118 std::unique_ptr<protocol::Debugger::Location> currentDebugLocation(V8InspectorIm
pl* inspector) | 122 std::unique_ptr<protocol::Debugger::Location> currentDebugLocation(V8InspectorIm
pl* inspector) |
| 119 { | 123 { |
| 120 std::unique_ptr<V8StackTrace> callStack = inspector->captureStackTrace(1); | 124 std::unique_ptr<V8StackTrace> callStack = inspector->captureStackTrace(1); |
| 121 std::unique_ptr<protocol::Debugger::Location> location = protocol::Debugger:
:Location::create() | 125 std::unique_ptr<protocol::Debugger::Location> location = protocol::Debugger:
:Location::create() |
| 122 .setScriptId(callStack->topScriptId()) | 126 .setScriptId(callStack->topScriptId()) |
| 123 .setLineNumber(callStack->topLineNumber()).build(); | 127 .setLineNumber(callStack->topLineNumber()).build(); |
| 124 location->setColumnNumber(callStack->topColumnNumber()); | 128 location->setColumnNumber(callStack->topColumnNumber()); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 v8::CpuProfiler* V8ProfilerAgentImpl::profiler() | 325 v8::CpuProfiler* V8ProfilerAgentImpl::profiler() |
| 322 { | 326 { |
| 323 #if ENSURE_V8_VERSION(5, 4) | 327 #if ENSURE_V8_VERSION(5, 4) |
| 324 return m_profiler; | 328 return m_profiler; |
| 325 #else | 329 #else |
| 326 return m_isolate->GetCpuProfiler(); | 330 return m_isolate->GetCpuProfiler(); |
| 327 #endif | 331 #endif |
| 328 } | 332 } |
| 329 | 333 |
| 330 } // namespace v8_inspector | 334 } // namespace v8_inspector |
| OLD | NEW |