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