Chromium Code Reviews| Index: Source/core/inspector/InspectorTimelineAgent.cpp |
| diff --git a/Source/core/inspector/InspectorTimelineAgent.cpp b/Source/core/inspector/InspectorTimelineAgent.cpp |
| index 96b64140e24b0f97cf17cccfae35143959ebbcdf..6d6b39d2c58337e89a8f3eb4b652b527218f9f07 100644 |
| --- a/Source/core/inspector/InspectorTimelineAgent.cpp |
| +++ b/Source/core/inspector/InspectorTimelineAgent.cpp |
| @@ -48,6 +48,7 @@ |
| #include "core/page/DOMWindow.h" |
| #include "core/page/Frame.h" |
| #include "core/page/FrameView.h" |
| +#include "core/page/PageConsole.h" |
| #include "core/platform/MemoryUsageSupport.h" |
| #include "core/platform/chromium/TraceEvent.h" |
| #include "core/platform/network/ResourceRequest.h" |
| @@ -60,7 +61,9 @@ |
| namespace WebCore { |
| namespace TimelineAgentState { |
| -static const char timelineAgentEnabled[] = "timelineAgentEnabled"; |
| +static const char enabled[] = "enabled"; |
| +static const char started[] = "started"; |
| +static const char startedFromProtocol[] = "startedFromProtocol"; |
| static const char timelineMaxCallStackDepth[] = "timelineMaxCallStackDepth"; |
| static const char includeDomCounters[] = "includeDomCounters"; |
| static const char includeNativeMemoryStatistics[] = "includeNativeMemoryStatistics"; |
| @@ -189,25 +192,44 @@ void InspectorTimelineAgent::clearFrontend() |
| { |
| ErrorString error; |
| stop(&error); |
| + disable(&error); |
| releaseNodeIds(); |
| m_frontend = 0; |
| } |
| void InspectorTimelineAgent::restore() |
| { |
| - if (m_state->getBoolean(TimelineAgentState::timelineAgentEnabled)) { |
| - m_maxCallStackDepth = m_state->getLong(TimelineAgentState::timelineMaxCallStackDepth); |
| - ErrorString error; |
| - bool includeDomCounters = m_state->getBoolean(TimelineAgentState::includeDomCounters); |
| - bool includeNativeMemoryStatistics = m_state->getBoolean(TimelineAgentState::includeNativeMemoryStatistics); |
| - start(&error, &m_maxCallStackDepth, &includeDomCounters, &includeNativeMemoryStatistics); |
| + if (m_state->getBoolean(TimelineAgentState::startedFromProtocol)) { |
| + innerStart(false); |
|
caseq
2013/09/13 15:00:23
This will send a duplicate notification to front-e
pfeldman
2013/09/13 15:21:03
Done.
|
| + } else if (isStarted()) { |
| + // Timeline was started from console.timeline, it is not restored. |
| + // Tell front-end timline is no longer collecting. |
| + m_state->setBoolean(TimelineAgentState::started, false); |
| + bool fromConsole = true; |
| + m_frontend->stopped(&fromConsole); |
| } |
| } |
| -void InspectorTimelineAgent::start(ErrorString*, const int* maxCallStackDepth, const bool* includeDomCounters, const bool* includeNativeMemoryStatistics) |
| +void InspectorTimelineAgent::enable(ErrorString*) |
| +{ |
| + m_state->setBoolean(TimelineAgentState::enabled, true); |
| +} |
| + |
| +void InspectorTimelineAgent::disable(ErrorString*) |
| +{ |
| + m_state->setBoolean(TimelineAgentState::enabled, false); |
| +} |
| + |
| +void InspectorTimelineAgent::start(ErrorString* errorString, const int* maxCallStackDepth, const bool* includeDomCounters, const bool* includeNativeMemoryStatistics) |
| { |
| if (!m_frontend) |
| return; |
| + m_state->setBoolean(TimelineAgentState::startedFromProtocol, true); |
| + |
| + if (isStarted()) { |
| + *errorString = "Timeline is already started."; |
|
caseq
2013/09/13 15:00:23
nit: please no terminating punctuation in error me
pfeldman
2013/09/13 15:21:03
Done.
|
| + return; |
| + } |
| releaseNodeIds(); |
| if (maxCallStackDepth && *maxCallStackDepth >= 0) |
| @@ -217,19 +239,38 @@ void InspectorTimelineAgent::start(ErrorString*, const int* maxCallStackDepth, c |
| m_state->setLong(TimelineAgentState::timelineMaxCallStackDepth, m_maxCallStackDepth); |
| m_state->setBoolean(TimelineAgentState::includeDomCounters, includeDomCounters && *includeDomCounters); |
| m_state->setBoolean(TimelineAgentState::includeNativeMemoryStatistics, includeNativeMemoryStatistics && *includeNativeMemoryStatistics); |
| - m_timeConverter.reset(); |
| + innerStart(false); |
| +} |
| +bool InspectorTimelineAgent::isStarted() |
| +{ |
| + return m_state->getBoolean(TimelineAgentState::started); |
| +} |
| + |
| +void InspectorTimelineAgent::innerStart(bool fromConsole) |
| +{ |
| + m_state->setBoolean(TimelineAgentState::started, true); |
| + m_timeConverter.reset(); |
| m_instrumentingAgents->setInspectorTimelineAgent(this); |
| ScriptGCEvent::addEventListener(this); |
| - m_state->setBoolean(TimelineAgentState::timelineAgentEnabled, true); |
| if (m_client && m_pageAgent) |
| m_traceEventProcessor = adoptRef(new TimelineTraceEventProcessor(m_weakFactory.createWeakPtr(), m_client)); |
| + m_frontend->started(&fromConsole); |
| } |
| -void InspectorTimelineAgent::stop(ErrorString*) |
| +void InspectorTimelineAgent::stop(ErrorString* errorString) |
| { |
| - if (!m_state->getBoolean(TimelineAgentState::timelineAgentEnabled)) |
| + m_state->setBoolean(TimelineAgentState::startedFromProtocol, false); |
| + if (!isStarted()) { |
| + *errorString = "Timeline was not started"; |
| return; |
| + } |
| + innerStop(false); |
| +} |
| + |
| +void InspectorTimelineAgent::innerStop(bool fromConsole) |
| +{ |
| + m_state->setBoolean(TimelineAgentState::started, false); |
| if (m_traceEventProcessor) { |
| m_traceEventProcessor->shutdown(); |
| @@ -242,7 +283,13 @@ void InspectorTimelineAgent::stop(ErrorString*) |
| clearRecordStack(); |
| m_gcEvents.clear(); |
| - m_state->setBoolean(TimelineAgentState::timelineAgentEnabled, false); |
| + for (size_t i = 0; i < m_consoleTimelines.size(); ++i) { |
| + String message = String::format("Timeline '%s' terminated.", m_consoleTimelines[i].utf8().data()); |
| + page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel, message); |
| + } |
| + m_consoleTimelines.clear(); |
| + |
| + m_frontend->stopped(&fromConsole); |
| } |
| void InspectorTimelineAgent::didBeginFrame() |
| @@ -566,23 +613,53 @@ void InspectorTimelineAgent::didFailLoading(unsigned long identifier, DocumentLo |
| didFinishLoadingResource(identifier, true, 0, loader->frame()); |
| } |
| -void InspectorTimelineAgent::consoleTimeStamp(ScriptExecutionContext* context, PassRefPtr<ScriptArguments> arguments) |
| +void InspectorTimelineAgent::consoleTimeStamp(ScriptExecutionContext* context, const String& title) |
| { |
| - String message; |
| - arguments->getFirstArgumentAsString(message); |
| - appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRecordType::TimeStamp, true, frameForScriptExecutionContext(context)); |
| + appendRecord(TimelineRecordFactory::createTimeStampData(title), TimelineRecordType::TimeStamp, true, frameForScriptExecutionContext(context)); |
| } |
| -void InspectorTimelineAgent::startConsoleTiming(ScriptExecutionContext* context, const String& message) |
| +void InspectorTimelineAgent::consoleTime(ScriptExecutionContext* context, const String& message) |
| { |
| appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRecordType::Time, true, frameForScriptExecutionContext(context)); |
| } |
| -void InspectorTimelineAgent::stopConsoleTiming(ScriptExecutionContext* context, const String& message, PassRefPtr<ScriptCallStack> stack) |
| +void InspectorTimelineAgent::consoleTimeEnd(ScriptExecutionContext* context, const String& message, ScriptState*) |
| { |
| appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRecordType::TimeEnd, true, frameForScriptExecutionContext(context)); |
| } |
| +void InspectorTimelineAgent::consoleTimeline(ScriptExecutionContext* context, const String& title, ScriptState* state) |
| +{ |
| + if (!m_state->getBoolean(TimelineAgentState::enabled)) |
| + return; |
| + |
| + String message = String::format("Timeline '%s' started.", title.utf8().data()); |
| + page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel, message, String(), 0, 0, 0, state); |
| + m_consoleTimelines.append(title); |
| + if (!isStarted()) |
| + innerStart(true); |
| + appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRecordType::TimeStamp, true, frameForScriptExecutionContext(context)); |
|
caseq
2013/09/13 15:00:23
I'm not sure if passing formatted message rather t
pfeldman
2013/09/13 15:21:03
That's because timestamps are rendered as event ma
|
| +} |
| + |
| +void InspectorTimelineAgent::consoleTimelineEnd(ScriptExecutionContext* context, const String& title, ScriptState* state) |
| +{ |
| + if (!m_state->getBoolean(TimelineAgentState::enabled)) |
| + return; |
| + |
| + size_t index = m_consoleTimelines.find(title); |
| + if (index == notFound) { |
| + String message = String::format("Timeline '%s' was not started.", title.utf8().data()); |
| + page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel, message, String(), 0, 0, 0, state); |
| + return; |
| + } |
| + |
| + String message = String::format("Timeline '%s' finished.", title.utf8().data()); |
| + appendRecord(TimelineRecordFactory::createTimeStampData(message), TimelineRecordType::TimeStamp, true, frameForScriptExecutionContext(context)); |
|
caseq
2013/09/13 15:00:23
Ditto.
|
| + m_consoleTimelines.remove(index); |
| + if (!m_consoleTimelines.size() && isStarted() && !m_state->getBoolean(TimelineAgentState::startedFromProtocol)) |
| + innerStop(true); |
| + page()->console().addMessage(ConsoleAPIMessageSource, DebugMessageLevel, message, String(), 0, 0, 0, state); |
| +} |
| void InspectorTimelineAgent::domContentLoadedEventFired(Frame* frame) |
| { |