Skip to content

Commit

Permalink
Inspector snapshot
Browse files Browse the repository at this point in the history
Blink Commit: 60cd6e859b9f557d2312f5bf532f6aec5f284980
  • Loading branch information
Eugene Ostroukhov committed Aug 23, 2016
1 parent ab732a6 commit 55f21a5
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,11 @@ def read_protocol_file(file_name, json_api):
json_string = input_file.read()
input_file.close()
parsed_json = json.loads(json_string)
version = parsed_json["version"]["major"] + "." + parsed_json["version"]["minor"]
domains = []
for domain in parsed_json["domains"]:
domains.append(domain["domain"])
domain["version"] = version
json_api["domains"] += parsed_json["domains"]
return domains

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace {{domain.domain}} {

const char Metainfo::domainName[] = "{{domain.domain}}";
const char Metainfo::commandPrefix[] = "{{domain.domain}}.";
const char Metainfo::version[] = "{{domain.version}}";
{% for type in domain.types %}
{% if "enum" in type %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ public:
using DispatcherClass = Dispatcher;
static const char domainName[];
static const char commandPrefix[];
static const char version[];
};

} // namespace {{domain.domain}}
Expand Down
6 changes: 6 additions & 0 deletions third_party/v8_inspector/platform/v8_inspector/PlatformSTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,10 @@ inline static int snprintf(char *buffer, size_t n, const char *format, ...)
} // namespace std
#endif // (_WIN32) && defined( _MSC_VER ) && (_MSC_VER < 1900)

#ifdef __sun
namespace std {
using ::snprintf;
} // namespace std
#endif // __sun

#endif // PlatformSTL_h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "platform/v8_inspector/V8InspectorImpl.h"
#include "platform/v8_inspector/V8ProfilerAgentImpl.h"
#include "platform/v8_inspector/V8RuntimeAgentImpl.h"
#include "platform/v8_inspector/V8SchemaAgentImpl.h"
#include "platform/v8_inspector/V8StringUtil.h"
#include "platform/v8_inspector/public/V8ContextInfo.h"
#include "platform/v8_inspector/public/V8InspectorClient.h"
Expand All @@ -27,7 +28,8 @@ bool V8InspectorSession::canDispatchMethod(const String16& method)
|| method.startsWith(protocol::Debugger::Metainfo::commandPrefix)
|| method.startsWith(protocol::Profiler::Metainfo::commandPrefix)
|| method.startsWith(protocol::HeapProfiler::Metainfo::commandPrefix)
|| method.startsWith(protocol::Console::Metainfo::commandPrefix);
|| method.startsWith(protocol::Console::Metainfo::commandPrefix)
|| method.startsWith(protocol::Schema::Metainfo::commandPrefix);
}

std::unique_ptr<V8InspectorSessionImpl> V8InspectorSessionImpl::create(V8InspectorImpl* inspector, int contextGroupId, protocol::FrontendChannel* channel, const String16* state)
Expand All @@ -46,6 +48,7 @@ V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector, int c
, m_heapProfilerAgent(nullptr)
, m_profilerAgent(nullptr)
, m_consoleAgent(nullptr)
, m_schemaAgent(nullptr)
{
if (savedState) {
std::unique_ptr<protocol::Value> state = protocol::parseJSON(*savedState);
Expand All @@ -72,6 +75,9 @@ V8InspectorSessionImpl::V8InspectorSessionImpl(V8InspectorImpl* inspector, int c
m_consoleAgent = wrapUnique(new V8ConsoleAgentImpl(this, channel, agentState(protocol::Console::Metainfo::domainName)));
protocol::Console::Dispatcher::wire(&m_dispatcher, m_consoleAgent.get());

m_schemaAgent = wrapUnique(new V8SchemaAgentImpl(this, channel, agentState(protocol::Schema::Metainfo::domainName)));
protocol::Schema::Dispatcher::wire(&m_dispatcher, m_schemaAgent.get());

if (savedState) {
m_runtimeAgent->restore();
m_debuggerAgent->restore();
Expand Down Expand Up @@ -262,6 +268,26 @@ String16 V8InspectorSessionImpl::stateJSON()
return m_state->toJSONString();
}

std::unique_ptr<protocol::Array<protocol::Schema::API::Domain>> V8InspectorSessionImpl::supportedDomains()
{
std::vector<std::unique_ptr<protocol::Schema::Domain>> domains = supportedDomainsImpl();
std::unique_ptr<protocol::Array<protocol::Schema::API::Domain>> result = protocol::Array<protocol::Schema::API::Domain>::create();
for (size_t i = 0; i < domains.size(); ++i)
result->addItem(std::move(domains[i]));
return result;
}

std::vector<std::unique_ptr<protocol::Schema::Domain>> V8InspectorSessionImpl::supportedDomainsImpl()
{
std::vector<std::unique_ptr<protocol::Schema::Domain>> result;
result.push_back(protocol::Schema::Domain::create().setName(protocol::Runtime::Metainfo::domainName).setVersion(protocol::Runtime::Metainfo::version).build());
result.push_back(protocol::Schema::Domain::create().setName(protocol::Debugger::Metainfo::domainName).setVersion(protocol::Debugger::Metainfo::version).build());
result.push_back(protocol::Schema::Domain::create().setName(protocol::Profiler::Metainfo::domainName).setVersion(protocol::Profiler::Metainfo::version).build());
result.push_back(protocol::Schema::Domain::create().setName(protocol::HeapProfiler::Metainfo::domainName).setVersion(protocol::HeapProfiler::Metainfo::version).build());
result.push_back(protocol::Schema::Domain::create().setName(protocol::Schema::Metainfo::domainName).setVersion(protocol::Schema::Metainfo::version).build());
return result;
}

void V8InspectorSessionImpl::addInspectedObject(std::unique_ptr<V8InspectorSession::Inspectable> inspectable)
{
m_inspectedObjects.insert(m_inspectedObjects.begin(), std::move(inspectable));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "platform/inspector_protocol/InspectorProtocol.h"
#include "platform/v8_inspector/protocol/Runtime.h"
#include "platform/v8_inspector/protocol/Schema.h"
#include "platform/v8_inspector/public/V8InspectorSession.h"

#include <v8.h>
Expand All @@ -23,6 +24,7 @@ class V8InspectorImpl;
class V8HeapProfilerAgentImpl;
class V8ProfilerAgentImpl;
class V8RuntimeAgentImpl;
class V8SchemaAgentImpl;

namespace protocol = blink::protocol;

Expand All @@ -35,6 +37,7 @@ class V8InspectorSessionImpl : public V8InspectorSession {
V8InspectorImpl* inspector() const { return m_inspector; }
V8ConsoleAgentImpl* consoleAgent() { return m_consoleAgent.get(); }
V8DebuggerAgentImpl* debuggerAgent() { return m_debuggerAgent.get(); }
V8SchemaAgentImpl* schemaAgent() { return m_schemaAgent.get(); }
V8ProfilerAgentImpl* profilerAgent() { return m_profilerAgent.get(); }
V8RuntimeAgentImpl* runtimeAgent() { return m_runtimeAgent.get(); }
int contextGroupId() const { return m_contextGroupId; }
Expand All @@ -47,10 +50,12 @@ class V8InspectorSessionImpl : public V8InspectorSession {
void setCustomObjectFormatterEnabled(bool);
std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(v8::Local<v8::Context>, v8::Local<v8::Value>, const String16& groupName, bool generatePreview);
std::unique_ptr<protocol::Runtime::RemoteObject> wrapTable(v8::Local<v8::Context>, v8::Local<v8::Value> table, v8::Local<v8::Value> columns);
std::vector<std::unique_ptr<protocol::Schema::Domain>> supportedDomainsImpl();

// V8InspectorSession implementation.
void dispatchProtocolMessage(const String16& message) override;
String16 stateJSON() override;
std::unique_ptr<protocol::Array<protocol::Schema::API::Domain>> supportedDomains() override;
void addInspectedObject(std::unique_ptr<V8InspectorSession::Inspectable>) override;
void schedulePauseOnNextStatement(const String16& breakReason, const String16& breakDetails) override;
void cancelPauseOnNextStatement() override;
Expand Down Expand Up @@ -82,6 +87,7 @@ class V8InspectorSessionImpl : public V8InspectorSession {
std::unique_ptr<V8HeapProfilerAgentImpl> m_heapProfilerAgent;
std::unique_ptr<V8ProfilerAgentImpl> m_profilerAgent;
std::unique_ptr<V8ConsoleAgentImpl> m_consoleAgent;
std::unique_ptr<V8SchemaAgentImpl> m_schemaAgent;
std::vector<std::unique_ptr<V8InspectorSession::Inspectable>> m_inspectedObjects;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ namespace {

std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> buildInspectorObjectForPositionTicks(const v8::CpuProfileNode* node)
{
std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> array = protocol::Array<protocol::Profiler::PositionTickInfo>::create();
unsigned lineCount = node->GetHitLineCount();
if (!lineCount)
return array;

return nullptr;
auto array = protocol::Array<protocol::Profiler::PositionTickInfo>::create();
std::vector<v8::CpuProfileNode::LineTick> entries(lineCount);
if (node->GetLineTicks(&entries[0], lineCount)) {
for (unsigned i = 0; i < lineCount; i++) {
Expand All @@ -42,42 +41,46 @@ std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> buildInsp
array->addItem(std::move(line));
}
}

return array;
}

std::unique_ptr<protocol::Profiler::CPUProfileNode> buildInspectorObjectFor(v8::Isolate* isolate, const v8::CpuProfileNode* node)
{
v8::HandleScope handleScope(isolate);

std::unique_ptr<protocol::Array<protocol::Profiler::PositionTickInfo>> positionTicks = buildInspectorObjectForPositionTicks(node);
std::unique_ptr<protocol::Runtime::CallFrame> callFrame = protocol::Runtime::CallFrame::create()
auto callFrame = protocol::Runtime::CallFrame::create()
.setFunctionName(toProtocolString(node->GetFunctionName()))
.setScriptId(String16::fromInteger(node->GetScriptId()))
.setUrl(toProtocolString(node->GetScriptResourceName()))
.setLineNumber(node->GetLineNumber() - 1)
.setColumnNumber(node->GetColumnNumber() - 1)
.build();
std::unique_ptr<protocol::Profiler::CPUProfileNode> result = protocol::Profiler::CPUProfileNode::create()
auto result = protocol::Profiler::CPUProfileNode::create()
.setCallFrame(std::move(callFrame))
.setHitCount(node->GetHitCount())
.setPositionTicks(std::move(positionTicks))
.setDeoptReason(node->GetBailoutReason())
.setId(node->GetNodeId()).build();

const int childrenCount = node->GetChildrenCount();
if (childrenCount) {
std::unique_ptr<protocol::Array<int>> children = protocol::Array<int>::create();
auto children = protocol::Array<int>::create();
for (int i = 0; i < childrenCount; i++)
children->addItem(node->GetChild(i)->GetNodeId());
result->setChildren(std::move(children));
}

const char* deoptReason = node->GetBailoutReason();
if (deoptReason && deoptReason[0] && strcmp(deoptReason, "no reason"))
result->setDeoptReason(deoptReason);

auto positionTicks = buildInspectorObjectForPositionTicks(node);
if (positionTicks)
result->setPositionTicks(std::move(positionTicks));

return result;
}

std::unique_ptr<protocol::Array<int>> buildInspectorObjectForSamples(v8::CpuProfile* v8profile)
{
std::unique_ptr<protocol::Array<int>> array = protocol::Array<int>::create();
auto array = protocol::Array<int>::create();
int count = v8profile->GetSamplesCount();
for (int i = 0; i < count; i++)
array->addItem(v8profile->GetSample(i)->GetNodeId());
Expand All @@ -86,7 +89,7 @@ std::unique_ptr<protocol::Array<int>> buildInspectorObjectForSamples(v8::CpuProf

std::unique_ptr<protocol::Array<int>> buildInspectorObjectForTimestamps(v8::CpuProfile* v8profile)
{
std::unique_ptr<protocol::Array<int>> array = protocol::Array<int>::create();
auto array = protocol::Array<int>::create();
int count = v8profile->GetSamplesCount();
uint64_t lastTime = v8profile->GetStartTime();
for (int i = 0; i < count; i++) {
Expand All @@ -107,10 +110,10 @@ void flattenNodesTree(v8::Isolate* isolate, const v8::CpuProfileNode* node, prot

std::unique_ptr<protocol::Profiler::CPUProfile> createCPUProfile(v8::Isolate* isolate, v8::CpuProfile* v8profile)
{
std::unique_ptr<protocol::Array<protocol::Profiler::CPUProfileNode>> nodes = protocol::Array<protocol::Profiler::CPUProfileNode>::create();
auto nodes = protocol::Array<protocol::Profiler::CPUProfileNode>::create();
flattenNodesTree(isolate, v8profile->GetTopDownRoot(), nodes.get());

std::unique_ptr<protocol::Profiler::CPUProfile> profile = protocol::Profiler::CPUProfile::create()
auto profile = protocol::Profiler::CPUProfile::create()
.setNodes(std::move(nodes))
.setStartTime(static_cast<double>(v8profile->GetStartTime()))
.setEndTime(static_cast<double>(v8profile->GetEndTime())).build();
Expand All @@ -122,7 +125,7 @@ std::unique_ptr<protocol::Profiler::CPUProfile> createCPUProfile(v8::Isolate* is
std::unique_ptr<protocol::Debugger::Location> currentDebugLocation(V8InspectorImpl* inspector)
{
std::unique_ptr<V8StackTrace> callStack = inspector->captureStackTrace(1);
std::unique_ptr<protocol::Debugger::Location> location = protocol::Debugger::Location::create()
auto location = protocol::Debugger::Location::create()
.setScriptId(callStack->topScriptId())
.setLineNumber(callStack->topLineNumber()).build();
location->setColumnNumber(callStack->topColumnNumber());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "platform/v8_inspector/V8SchemaAgentImpl.h"

#include "platform/v8_inspector/V8InspectorSessionImpl.h"

namespace v8_inspector {

V8SchemaAgentImpl::V8SchemaAgentImpl(V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel, protocol::DictionaryValue* state)
: m_session(session)
, m_frontend(frontendChannel)
{
}

V8SchemaAgentImpl::~V8SchemaAgentImpl()
{
}

void V8SchemaAgentImpl::getDomains(ErrorString*, std::unique_ptr<protocol::Array<protocol::Schema::Domain>>* result)
{
std::vector<std::unique_ptr<protocol::Schema::Domain>> domains = m_session->supportedDomainsImpl();
*result = protocol::Array<protocol::Schema::Domain>::create();
for (size_t i = 0; i < domains.size(); ++i)
(*result)->addItem(std::move(domains[i]));
}

} // namespace v8_inspector
33 changes: 33 additions & 0 deletions third_party/v8_inspector/platform/v8_inspector/V8SchemaAgentImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8SchemaAgentImpl_h
#define V8SchemaAgentImpl_h

#include "platform/inspector_protocol/InspectorProtocol.h"
#include "platform/v8_inspector/protocol/Schema.h"

namespace v8_inspector {

class V8InspectorSessionImpl;

namespace protocol = blink::protocol;

class V8SchemaAgentImpl : public protocol::Schema::Backend {
PROTOCOL_DISALLOW_COPY(V8SchemaAgentImpl);
public:
V8SchemaAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*, protocol::DictionaryValue* state);
~V8SchemaAgentImpl() override;

void getDomains(ErrorString*, std::unique_ptr<protocol::Array<protocol::Schema::Domain>>*) override;

private:
V8InspectorSessionImpl* m_session;
protocol::Schema::Frontend m_frontend;
};

} // namespace v8_inspector


#endif // !defined(V8SchemaAgentImpl_h)
34 changes: 31 additions & 3 deletions third_party/v8_inspector/platform/v8_inspector/js_protocol.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
{
"version": { "major": "1", "minor": "1" },
"domains": [{
"domains": [
{
"domain": "Schema",
"description": "Provides information about the protocol schema.",
"experimental": true,
"types": [
{
"id": "Domain",
"type": "object",
"description": "Description of the protocol domain.",
"exported": true,
"properties": [
{ "name": "name", "type": "string", "description": "Domain name." },
{ "name": "version", "type": "string", "description": "Domain version." }
]
}
],
"commands": [
{
"name": "getDomains",
"description": "Returns supported domains.",
"handlers": ["browser", "renderer"],
"returns": [
{ "name": "domains", "type": "array", "items": { "$ref": "Domain" }, "description": "List of supported domains." }
]
}
]
},
{
"domain": "Runtime",
"description": "Runtime domain exposes JavaScript runtime by means of remote evaluation and mirror objects. Evaluation results are returned as mirror object that expose object type, string representation and unique identifier that can be used for further object reference. Original objects are maintained in memory unless they are either explicitly released or are released along with the other objects in their object group.",
"types": [
Expand Down Expand Up @@ -781,8 +809,8 @@
{ "name": "callFrame", "$ref": "Runtime.CallFrame", "description": "Function location." },
{ "name": "hitCount", "type": "integer", "description": "Number of samples where this node was on top of the call stack." },
{ "name": "children", "type": "array", "items": { "type": "integer" }, "optional": true, "description": "Child node ids." },
{ "name": "deoptReason", "type": "string", "experimental": true, "description": "The reason of being not optimized. The function may be deoptimized or marked as don't optimize."},
{ "name": "positionTicks", "type": "array", "items": { "$ref": "PositionTickInfo" }, "experimental": true, "description": "An array of source position ticks." }
{ "name": "deoptReason", "type": "string", "optional": true, "description": "The reason of being not optimized. The function may be deoptimized or marked as don't optimize."},
{ "name": "positionTicks", "type": "array", "items": { "$ref": "PositionTickInfo" }, "optional": true, "experimental": true, "description": "An array of source position ticks." }
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
// found in the LICENSE file.

// This file is automatically generated. Do not modify.
#define V8_INSPECTOR_REVISION "3c58e3c966928309ada55f792a5cc43bcbdec8d2"
#define V8_INSPECTOR_REVISION "60cd6e859b9f557d2312f5bf532f6aec5f284980"
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "platform/inspector_protocol/InspectorProtocol.h"
#include "platform/v8_inspector/public/protocol/Debugger.h"
#include "platform/v8_inspector/public/protocol/Runtime.h"
#include "platform/v8_inspector/public/protocol/Schema.h"

#include <v8.h>

Expand All @@ -29,6 +30,7 @@ class PLATFORM_EXPORT V8InspectorSession {
static bool canDispatchMethod(const String16& method);
virtual void dispatchProtocolMessage(const String16& message) = 0;
virtual String16 stateJSON() = 0;
virtual std::unique_ptr<blink::protocol::Array<blink::protocol::Schema::API::Domain>> supportedDomains() = 0;

// Debugger actions.
virtual void schedulePauseOnNextStatement(const String16& breakReason, const String16& breakDetails) = 0;
Expand Down
Loading

0 comments on commit 55f21a5

Please sign in to comment.