Chromium Code Reviews| 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 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> array = protocol::Array<protocol::Profiler::PositionTickInfo>::create(); |
|
caseq
2016/08/22 19:14:20
auto array = ...
alph
2016/08/22 19:24:08
Done.
| |
| 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 | |
| 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() | 50 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 std::unique_ptr<protocol::Profiler::CPUProfileNode> result = protocol::Profi ler::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 std::unique_ptr<protocol::Array<int>> children = protocol::Array<int>::c reate(); |
| 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] != '\0' && strcmp(deoptReason, "no reason" )) | |
|
caseq
2016/08/22 19:14:20
nit: drop != '\0'
alph
2016/08/22 19:24:08
Done.
| |
| 72 result->setDeoptReason(deoptReason); | |
| 73 | |
| 74 std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> posit ionTicks = 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 std::unique_ptr<protocol::Array<int>> 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; |
| (...skipping 240 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 |