| 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 10 matching lines...) Expand all Loading... |
| 21 namespace ProfilerAgentState { | 21 namespace ProfilerAgentState { |
| 22 static const char samplingInterval[] = "samplingInterval"; | 22 static const char samplingInterval[] = "samplingInterval"; |
| 23 static const char userInitiatedProfiling[] = "userInitiatedProfiling"; | 23 static const char userInitiatedProfiling[] = "userInitiatedProfiling"; |
| 24 static const char profilerEnabled[] = "profilerEnabled"; | 24 static const char profilerEnabled[] = "profilerEnabled"; |
| 25 } | 25 } |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> buildInsp
ectorObjectForPositionTicks(const v8::CpuProfileNode* node) | 29 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> buildInsp
ectorObjectForPositionTicks(const v8::CpuProfileNode* node) |
| 30 { | 30 { |
| 31 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> array
= protocol::Array<protocol::Profiler::PositionTickInfo>::create(); | |
| 32 unsigned lineCount = node->GetHitLineCount(); | 31 unsigned lineCount = node->GetHitLineCount(); |
| 33 if (!lineCount) | 32 if (!lineCount) |
| 34 return array; | 33 return nullptr; |
| 35 | 34 auto array = protocol::Array<protocol::Profiler::PositionTickInfo>::create()
; |
| 36 std::vector<v8::CpuProfileNode::LineTick> entries(lineCount); | 35 std::vector<v8::CpuProfileNode::LineTick> entries(lineCount); |
| 37 if (node->GetLineTicks(&entries[0], lineCount)) { | 36 if (node->GetLineTicks(&entries[0], lineCount)) { |
| 38 for (unsigned i = 0; i < lineCount; i++) { | 37 for (unsigned i = 0; i < lineCount; i++) { |
| 39 std::unique_ptr<protocol::Profiler::PositionTickInfo> line = protoco
l::Profiler::PositionTickInfo::create() | 38 std::unique_ptr<protocol::Profiler::PositionTickInfo> line = protoco
l::Profiler::PositionTickInfo::create() |
| 40 .setLine(entries[i].line) | 39 .setLine(entries[i].line) |
| 41 .setTicks(entries[i].hit_count).build(); | 40 .setTicks(entries[i].hit_count).build(); |
| 42 array->addItem(std::move(line)); | 41 array->addItem(std::move(line)); |
| 43 } | 42 } |
| 44 } | 43 } |
| 45 | |
| 46 return array; | 44 return array; |
| 47 } | 45 } |
| 48 | 46 |
| 49 std::unique_ptr<protocol::Profiler::CPUProfileNode> buildInspectorObjectFor(v8::
Isolate* isolate, const v8::CpuProfileNode* node) | 47 std::unique_ptr<protocol::Profiler::CPUProfileNode> buildInspectorObjectFor(v8::
Isolate* isolate, const v8::CpuProfileNode* node) |
| 50 { | 48 { |
| 51 v8::HandleScope handleScope(isolate); | 49 v8::HandleScope handleScope(isolate); |
| 52 | 50 auto callFrame = protocol::Runtime::CallFrame::create() |
| 53 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> posit
ionTicks = buildInspectorObjectForPositionTicks(node); | |
| 54 std::unique_ptr<protocol::Runtime::CallFrame> callFrame = protocol::Runtime:
:CallFrame::create() | |
| 55 .setFunctionName(toProtocolString(node->GetFunctionName())) | 51 .setFunctionName(toProtocolString(node->GetFunctionName())) |
| 56 .setScriptId(String16::fromInteger(node->GetScriptId())) | 52 .setScriptId(String16::fromInteger(node->GetScriptId())) |
| 57 .setUrl(toProtocolString(node->GetScriptResourceName())) | 53 .setUrl(toProtocolString(node->GetScriptResourceName())) |
| 58 .setLineNumber(node->GetLineNumber() - 1) | 54 .setLineNumber(node->GetLineNumber() - 1) |
| 59 .setColumnNumber(node->GetColumnNumber() - 1) | 55 .setColumnNumber(node->GetColumnNumber() - 1) |
| 60 .build(); | 56 .build(); |
| 61 std::unique_ptr<protocol::Profiler::CPUProfileNode> result = protocol::Profi
ler::CPUProfileNode::create() | 57 auto result = protocol::Profiler::CPUProfileNode::create() |
| 62 .setCallFrame(std::move(callFrame)) | 58 .setCallFrame(std::move(callFrame)) |
| 63 .setHitCount(node->GetHitCount()) | 59 .setHitCount(node->GetHitCount()) |
| 64 .setPositionTicks(std::move(positionTicks)) | |
| 65 .setDeoptReason(node->GetBailoutReason()) | |
| 66 .setId(node->GetNodeId()).build(); | 60 .setId(node->GetNodeId()).build(); |
| 67 | 61 |
| 68 const int childrenCount = node->GetChildrenCount(); | 62 const int childrenCount = node->GetChildrenCount(); |
| 69 if (childrenCount) { | 63 if (childrenCount) { |
| 70 std::unique_ptr<protocol::Array<int>> children = protocol::Array<int>::c
reate(); | 64 auto children = protocol::Array<int>::create(); |
| 71 for (int i = 0; i < childrenCount; i++) | 65 for (int i = 0; i < childrenCount; i++) |
| 72 children->addItem(node->GetChild(i)->GetNodeId()); | 66 children->addItem(node->GetChild(i)->GetNodeId()); |
| 73 result->setChildren(std::move(children)); | 67 result->setChildren(std::move(children)); |
| 74 } | 68 } |
| 69 |
| 70 const char* deoptReason = node->GetBailoutReason(); |
| 71 if (deoptReason && deoptReason[0] && strcmp(deoptReason, "no reason")) |
| 72 result->setDeoptReason(deoptReason); |
| 73 |
| 74 auto positionTicks = buildInspectorObjectForPositionTicks(node); |
| 75 if (positionTicks) |
| 76 result->setPositionTicks(std::move(positionTicks)); |
| 77 |
| 75 return result; | 78 return result; |
| 76 } | 79 } |
| 77 | 80 |
| 78 std::unique_ptr<protocol::Array<int>> buildInspectorObjectForSamples(v8::CpuProf
ile* v8profile) | 81 std::unique_ptr<protocol::Array<int>> buildInspectorObjectForSamples(v8::CpuProf
ile* v8profile) |
| 79 { | 82 { |
| 80 std::unique_ptr<protocol::Array<int>> array = protocol::Array<int>::create()
; | 83 auto array = protocol::Array<int>::create(); |
| 81 int count = v8profile->GetSamplesCount(); | 84 int count = v8profile->GetSamplesCount(); |
| 82 for (int i = 0; i < count; i++) | 85 for (int i = 0; i < count; i++) |
| 83 array->addItem(v8profile->GetSample(i)->GetNodeId()); | 86 array->addItem(v8profile->GetSample(i)->GetNodeId()); |
| 84 return array; | 87 return array; |
| 85 } | 88 } |
| 86 | 89 |
| 87 std::unique_ptr<protocol::Array<int>> buildInspectorObjectForTimestamps(v8::CpuP
rofile* v8profile) | 90 std::unique_ptr<protocol::Array<int>> buildInspectorObjectForTimestamps(v8::CpuP
rofile* v8profile) |
| 88 { | 91 { |
| 89 std::unique_ptr<protocol::Array<int>> array = protocol::Array<int>::create()
; | 92 auto array = protocol::Array<int>::create(); |
| 90 int count = v8profile->GetSamplesCount(); | 93 int count = v8profile->GetSamplesCount(); |
| 91 uint64_t lastTime = v8profile->GetStartTime(); | 94 uint64_t lastTime = v8profile->GetStartTime(); |
| 92 for (int i = 0; i < count; i++) { | 95 for (int i = 0; i < count; i++) { |
| 93 uint64_t ts = v8profile->GetSampleTimestamp(i); | 96 uint64_t ts = v8profile->GetSampleTimestamp(i); |
| 94 array->addItem(static_cast<int>(ts - lastTime)); | 97 array->addItem(static_cast<int>(ts - lastTime)); |
| 95 lastTime = ts; | 98 lastTime = ts; |
| 96 } | 99 } |
| 97 return array; | 100 return array; |
| 98 } | 101 } |
| 99 | 102 |
| 100 void flattenNodesTree(v8::Isolate* isolate, const v8::CpuProfileNode* node, prot
ocol::Array<protocol::Profiler::CPUProfileNode>* list) | 103 void flattenNodesTree(v8::Isolate* isolate, const v8::CpuProfileNode* node, prot
ocol::Array<protocol::Profiler::CPUProfileNode>* list) |
| 101 { | 104 { |
| 102 list->addItem(buildInspectorObjectFor(isolate, node)); | 105 list->addItem(buildInspectorObjectFor(isolate, node)); |
| 103 const int childrenCount = node->GetChildrenCount(); | 106 const int childrenCount = node->GetChildrenCount(); |
| 104 for (int i = 0; i < childrenCount; i++) | 107 for (int i = 0; i < childrenCount; i++) |
| 105 flattenNodesTree(isolate, node->GetChild(i), list); | 108 flattenNodesTree(isolate, node->GetChild(i), list); |
| 106 } | 109 } |
| 107 | 110 |
| 108 std::unique_ptr<protocol::Profiler::CPUProfile> createCPUProfile(v8::Isolate* is
olate, v8::CpuProfile* v8profile) | 111 std::unique_ptr<protocol::Profiler::CPUProfile> createCPUProfile(v8::Isolate* is
olate, v8::CpuProfile* v8profile) |
| 109 { | 112 { |
| 110 std::unique_ptr<protocol::Array<protocol::Profiler::CPUProfileNode>> nodes =
protocol::Array<protocol::Profiler::CPUProfileNode>::create(); | 113 auto nodes = protocol::Array<protocol::Profiler::CPUProfileNode>::create(); |
| 111 flattenNodesTree(isolate, v8profile->GetTopDownRoot(), nodes.get()); | 114 flattenNodesTree(isolate, v8profile->GetTopDownRoot(), nodes.get()); |
| 112 | 115 |
| 113 std::unique_ptr<protocol::Profiler::CPUProfile> profile = protocol::Profiler
::CPUProfile::create() | 116 auto profile = protocol::Profiler::CPUProfile::create() |
| 114 .setNodes(std::move(nodes)) | 117 .setNodes(std::move(nodes)) |
| 115 .setStartTime(static_cast<double>(v8profile->GetStartTime())) | 118 .setStartTime(static_cast<double>(v8profile->GetStartTime())) |
| 116 .setEndTime(static_cast<double>(v8profile->GetEndTime())).build(); | 119 .setEndTime(static_cast<double>(v8profile->GetEndTime())).build(); |
| 117 profile->setSamples(buildInspectorObjectForSamples(v8profile)); | 120 profile->setSamples(buildInspectorObjectForSamples(v8profile)); |
| 118 profile->setTimestampDeltas(buildInspectorObjectForTimestamps(v8profile)); | 121 profile->setTimestampDeltas(buildInspectorObjectForTimestamps(v8profile)); |
| 119 return profile; | 122 return profile; |
| 120 } | 123 } |
| 121 | 124 |
| 122 std::unique_ptr<protocol::Debugger::Location> currentDebugLocation(V8InspectorIm
pl* inspector) | 125 std::unique_ptr<protocol::Debugger::Location> currentDebugLocation(V8InspectorIm
pl* inspector) |
| 123 { | 126 { |
| 124 std::unique_ptr<V8StackTrace> callStack = inspector->captureStackTrace(1); | 127 std::unique_ptr<V8StackTrace> callStack = inspector->captureStackTrace(1); |
| 125 std::unique_ptr<protocol::Debugger::Location> location = protocol::Debugger:
:Location::create() | 128 auto location = protocol::Debugger::Location::create() |
| 126 .setScriptId(callStack->topScriptId()) | 129 .setScriptId(callStack->topScriptId()) |
| 127 .setLineNumber(callStack->topLineNumber()).build(); | 130 .setLineNumber(callStack->topLineNumber()).build(); |
| 128 location->setColumnNumber(callStack->topColumnNumber()); | 131 location->setColumnNumber(callStack->topColumnNumber()); |
| 129 return location; | 132 return location; |
| 130 } | 133 } |
| 131 | 134 |
| 132 volatile int s_lastProfileId = 0; | 135 volatile int s_lastProfileId = 0; |
| 133 | 136 |
| 134 } // namespace | 137 } // namespace |
| 135 | 138 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 v8::CpuProfiler* V8ProfilerAgentImpl::profiler() | 328 v8::CpuProfiler* V8ProfilerAgentImpl::profiler() |
| 326 { | 329 { |
| 327 #if ENSURE_V8_VERSION(5, 4) | 330 #if ENSURE_V8_VERSION(5, 4) |
| 328 return m_profiler; | 331 return m_profiler; |
| 329 #else | 332 #else |
| 330 return m_isolate->GetCpuProfiler(); | 333 return m_isolate->GetCpuProfiler(); |
| 331 #endif | 334 #endif |
| 332 } | 335 } |
| 333 | 336 |
| 334 } // namespace v8_inspector | 337 } // namespace v8_inspector |
| OLD | NEW |