| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 namespace WebCore { | 65 namespace WebCore { |
| 66 | 66 |
| 67 namespace TimelineAgentState { | 67 namespace TimelineAgentState { |
| 68 static const char enabled[] = "enabled"; | 68 static const char enabled[] = "enabled"; |
| 69 static const char started[] = "started"; | 69 static const char started[] = "started"; |
| 70 static const char startedFromProtocol[] = "startedFromProtocol"; | 70 static const char startedFromProtocol[] = "startedFromProtocol"; |
| 71 static const char timelineMaxCallStackDepth[] = "timelineMaxCallStackDepth"; | 71 static const char timelineMaxCallStackDepth[] = "timelineMaxCallStackDepth"; |
| 72 static const char includeCounters[] = "includeCounters"; | 72 static const char includeCounters[] = "includeCounters"; |
| 73 static const char includeGPUEvents[] = "includeGPUEvents"; | 73 static const char includeGPUEvents[] = "includeGPUEvents"; |
| 74 static const char bufferEvents[] = "bufferEvents"; | |
| 75 static const char liveEvents[] = "liveEvents"; | 74 static const char liveEvents[] = "liveEvents"; |
| 76 } | 75 } |
| 77 | 76 |
| 78 // Must be kept in sync with WebInspector.TimelineModel.RecordType in TimelineMo
del.js | 77 // Must be kept in sync with WebInspector.TimelineModel.RecordType in TimelineMo
del.js |
| 79 namespace TimelineRecordType { | 78 namespace TimelineRecordType { |
| 80 static const char Program[] = "Program"; | 79 static const char Program[] = "Program"; |
| 81 | 80 |
| 82 static const char EventDispatch[] = "EventDispatch"; | 81 static const char EventDispatch[] = "EventDispatch"; |
| 83 static const char ScheduleStyleRecalculation[] = "ScheduleStyleRecalculation"; | 82 static const char ScheduleStyleRecalculation[] = "ScheduleStyleRecalculation"; |
| 84 static const char RecalculateStyles[] = "RecalculateStyles"; | 83 static const char RecalculateStyles[] = "RecalculateStyles"; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 ErrorString error; | 270 ErrorString error; |
| 272 RefPtr<TypeBuilder::Array<TimelineEvent> > events; | 271 RefPtr<TypeBuilder::Array<TimelineEvent> > events; |
| 273 stop(&error, events); | 272 stop(&error, events); |
| 274 disable(&error); | 273 disable(&error); |
| 275 m_frontend = 0; | 274 m_frontend = 0; |
| 276 } | 275 } |
| 277 | 276 |
| 278 void InspectorTimelineAgent::restore() | 277 void InspectorTimelineAgent::restore() |
| 279 { | 278 { |
| 280 if (m_state->getBoolean(TimelineAgentState::startedFromProtocol)) { | 279 if (m_state->getBoolean(TimelineAgentState::startedFromProtocol)) { |
| 281 if (m_state->getBoolean(TimelineAgentState::bufferEvents)) | |
| 282 m_bufferedEvents = TypeBuilder::Array<TimelineEvent>::create(); | |
| 283 | |
| 284 setLiveEvents(m_state->getString(TimelineAgentState::liveEvents)); | 280 setLiveEvents(m_state->getString(TimelineAgentState::liveEvents)); |
| 285 innerStart(); | 281 innerStart(); |
| 286 } else if (isStarted()) { | 282 } else if (isStarted()) { |
| 287 // Timeline was started from console.timeline, it is not restored. | 283 // Timeline was started from console.timeline, it is not restored. |
| 288 // Tell front-end timline is no longer collecting. | 284 // Tell front-end timline is no longer collecting. |
| 289 m_state->setBoolean(TimelineAgentState::started, false); | 285 m_state->setBoolean(TimelineAgentState::started, false); |
| 290 bool fromConsole = true; | 286 bool fromConsole = true; |
| 291 m_frontend->stopped(&fromConsole); | 287 m_frontend->stopped(&fromConsole, nullptr); |
| 292 } | 288 } |
| 293 } | 289 } |
| 294 | 290 |
| 295 void InspectorTimelineAgent::enable(ErrorString*) | 291 void InspectorTimelineAgent::enable(ErrorString*) |
| 296 { | 292 { |
| 297 m_state->setBoolean(TimelineAgentState::enabled, true); | 293 m_state->setBoolean(TimelineAgentState::enabled, true); |
| 298 } | 294 } |
| 299 | 295 |
| 300 void InspectorTimelineAgent::disable(ErrorString*) | 296 void InspectorTimelineAgent::disable(ErrorString*) |
| 301 { | 297 { |
| 302 m_state->setBoolean(TimelineAgentState::enabled, false); | 298 m_state->setBoolean(TimelineAgentState::enabled, false); |
| 303 } | 299 } |
| 304 | 300 |
| 305 void InspectorTimelineAgent::start(ErrorString* errorString, const int* maxCallS
tackDepth, const bool* bufferEvents, const String* liveEvents, const bool* inclu
deCounters, const bool* includeGPUEvents) | 301 void InspectorTimelineAgent::start(ErrorString* errorString, const int* maxCallS
tackDepth, const String* liveEvents, const bool* includeCounters, const bool* in
cludeGPUEvents) |
| 306 { | 302 { |
| 307 if (!m_frontend) | 303 if (!m_frontend) |
| 308 return; | 304 return; |
| 309 m_state->setBoolean(TimelineAgentState::startedFromProtocol, true); | 305 m_state->setBoolean(TimelineAgentState::startedFromProtocol, true); |
| 310 | 306 |
| 311 if (isStarted()) { | 307 if (isStarted()) { |
| 312 *errorString = "Timeline is already started"; | 308 *errorString = "Timeline is already started"; |
| 313 return; | 309 return; |
| 314 } | 310 } |
| 315 | 311 |
| 316 if (maxCallStackDepth && *maxCallStackDepth >= 0) | 312 if (maxCallStackDepth && *maxCallStackDepth >= 0) |
| 317 m_maxCallStackDepth = *maxCallStackDepth; | 313 m_maxCallStackDepth = *maxCallStackDepth; |
| 318 else | 314 else |
| 319 m_maxCallStackDepth = 5; | 315 m_maxCallStackDepth = 5; |
| 320 | 316 |
| 321 if (bufferEvents && *bufferEvents) { | 317 m_lastProgressTimestamp = timestamp(); |
| 322 m_bufferedEvents = TypeBuilder::Array<TimelineEvent>::create(); | |
| 323 m_lastProgressTimestamp = timestamp(); | |
| 324 } | |
| 325 | 318 |
| 326 if (liveEvents) | 319 if (liveEvents) |
| 327 setLiveEvents(*liveEvents); | 320 setLiveEvents(*liveEvents); |
| 328 | 321 |
| 329 m_state->setLong(TimelineAgentState::timelineMaxCallStackDepth, m_maxCallSta
ckDepth); | 322 m_state->setLong(TimelineAgentState::timelineMaxCallStackDepth, m_maxCallSta
ckDepth); |
| 330 m_state->setBoolean(TimelineAgentState::includeCounters, includeCounters &&
*includeCounters); | 323 m_state->setBoolean(TimelineAgentState::includeCounters, includeCounters &&
*includeCounters); |
| 331 m_state->setBoolean(TimelineAgentState::includeGPUEvents, includeGPUEvents &
& *includeGPUEvents); | 324 m_state->setBoolean(TimelineAgentState::includeGPUEvents, includeGPUEvents &
& *includeGPUEvents); |
| 332 m_state->setBoolean(TimelineAgentState::bufferEvents, bufferEvents && *buffe
rEvents); | |
| 333 m_state->setString(TimelineAgentState::liveEvents, liveEvents ? *liveEvents
: ""); | 325 m_state->setString(TimelineAgentState::liveEvents, liveEvents ? *liveEvents
: ""); |
| 334 | 326 |
| 335 innerStart(); | 327 innerStart(); |
| 336 bool fromConsole = false; | 328 bool fromConsole = false; |
| 337 m_frontend->started(&fromConsole); | 329 m_frontend->started(&fromConsole); |
| 338 } | 330 } |
| 339 | 331 |
| 340 bool InspectorTimelineAgent::isStarted() | 332 bool InspectorTimelineAgent::isStarted() |
| 341 { | 333 { |
| 342 return m_state->getBoolean(TimelineAgentState::started); | 334 return m_state->getBoolean(TimelineAgentState::started); |
| 343 } | 335 } |
| 344 | 336 |
| 345 void InspectorTimelineAgent::innerStart() | 337 void InspectorTimelineAgent::innerStart() |
| 346 { | 338 { |
| 339 m_bufferedEvents = TypeBuilder::Array<TimelineEvent>::create(); |
| 340 |
| 347 if (m_overlay) | 341 if (m_overlay) |
| 348 m_overlay->startedRecordingProfile(); | 342 m_overlay->startedRecordingProfile(); |
| 349 m_state->setBoolean(TimelineAgentState::started, true); | 343 m_state->setBoolean(TimelineAgentState::started, true); |
| 350 m_instrumentingAgents->setInspectorTimelineAgent(this); | 344 m_instrumentingAgents->setInspectorTimelineAgent(this); |
| 351 ScriptGCEvent::addEventListener(this); | 345 ScriptGCEvent::addEventListener(this); |
| 352 if (m_client) { | 346 if (m_client) { |
| 353 TraceEventDispatcher* dispatcher = TraceEventDispatcher::instance(); | 347 TraceEventDispatcher* dispatcher = TraceEventDispatcher::instance(); |
| 354 dispatcher->addListener(InstrumentationEvents::BeginFrame, TRACE_EVENT_P
HASE_INSTANT, this, &InspectorTimelineAgent::onBeginImplSideFrame, m_client); | 348 dispatcher->addListener(InstrumentationEvents::BeginFrame, TRACE_EVENT_P
HASE_INSTANT, this, &InspectorTimelineAgent::onBeginImplSideFrame, m_client); |
| 355 dispatcher->addListener(InstrumentationEvents::PaintSetup, TRACE_EVENT_P
HASE_BEGIN, this, &InspectorTimelineAgent::onPaintSetupBegin, m_client); | 349 dispatcher->addListener(InstrumentationEvents::PaintSetup, TRACE_EVENT_P
HASE_BEGIN, this, &InspectorTimelineAgent::onPaintSetupBegin, m_client); |
| 356 dispatcher->addListener(InstrumentationEvents::PaintSetup, TRACE_EVENT_P
HASE_END, this, &InspectorTimelineAgent::onPaintSetupEnd, m_client); | 350 dispatcher->addListener(InstrumentationEvents::PaintSetup, TRACE_EVENT_P
HASE_END, this, &InspectorTimelineAgent::onPaintSetupEnd, m_client); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 372 if (m_state->getBoolean(TimelineAgentState::includeGPUEvents)) { | 366 if (m_state->getBoolean(TimelineAgentState::includeGPUEvents)) { |
| 373 m_pendingGPURecord.clear(); | 367 m_pendingGPURecord.clear(); |
| 374 m_client->startGPUEventsRecording(); | 368 m_client->startGPUEventsRecording(); |
| 375 } | 369 } |
| 376 } | 370 } |
| 377 } | 371 } |
| 378 | 372 |
| 379 void InspectorTimelineAgent::stop(ErrorString* errorString, RefPtr<TypeBuilder::
Array<TimelineEvent> >& events) | 373 void InspectorTimelineAgent::stop(ErrorString* errorString, RefPtr<TypeBuilder::
Array<TimelineEvent> >& events) |
| 380 { | 374 { |
| 381 m_state->setBoolean(TimelineAgentState::startedFromProtocol, false); | 375 m_state->setBoolean(TimelineAgentState::startedFromProtocol, false); |
| 382 m_state->setBoolean(TimelineAgentState::bufferEvents, false); | |
| 383 m_state->setString(TimelineAgentState::liveEvents, ""); | 376 m_state->setString(TimelineAgentState::liveEvents, ""); |
| 384 | 377 |
| 385 if (!isStarted()) { | 378 if (!isStarted()) { |
| 386 *errorString = "Timeline was not started"; | 379 *errorString = "Timeline was not started"; |
| 387 return; | 380 return; |
| 388 } | 381 } |
| 389 innerStop(false); | 382 innerStop(false); |
| 390 if (m_bufferedEvents) | |
| 391 events = m_bufferedEvents.release(); | |
| 392 m_liveEvents.clear(); | 383 m_liveEvents.clear(); |
| 393 } | 384 } |
| 394 | 385 |
| 395 void InspectorTimelineAgent::innerStop(bool fromConsole) | 386 void InspectorTimelineAgent::innerStop(bool fromConsole) |
| 396 { | 387 { |
| 397 m_state->setBoolean(TimelineAgentState::started, false); | 388 m_state->setBoolean(TimelineAgentState::started, false); |
| 398 | 389 |
| 399 if (m_client) { | 390 if (m_client) { |
| 400 TraceEventDispatcher::instance()->removeAllListeners(this, m_client); | 391 TraceEventDispatcher::instance()->removeAllListeners(this, m_client); |
| 401 if (m_state->getBoolean(TimelineAgentState::includeGPUEvents)) | 392 if (m_state->getBoolean(TimelineAgentState::includeGPUEvents)) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 412 m_imageBeingPainted = 0; | 403 m_imageBeingPainted = 0; |
| 413 m_paintSetupStart = 0; | 404 m_paintSetupStart = 0; |
| 414 m_mayEmitFirstPaint = false; | 405 m_mayEmitFirstPaint = false; |
| 415 | 406 |
| 416 for (size_t i = 0; i < m_consoleTimelines.size(); ++i) { | 407 for (size_t i = 0; i < m_consoleTimelines.size(); ++i) { |
| 417 String message = String::format("Timeline '%s' terminated.", m_consoleTi
melines[i].utf8().data()); | 408 String message = String::format("Timeline '%s' terminated.", m_consoleTi
melines[i].utf8().data()); |
| 418 mainFrame()->console().addMessage(JSMessageSource, DebugMessageLevel, me
ssage); | 409 mainFrame()->console().addMessage(JSMessageSource, DebugMessageLevel, me
ssage); |
| 419 } | 410 } |
| 420 m_consoleTimelines.clear(); | 411 m_consoleTimelines.clear(); |
| 421 | 412 |
| 422 m_frontend->stopped(&fromConsole); | 413 m_frontend->stopped(&fromConsole, m_bufferedEvents.release()); |
| 423 if (m_overlay) | 414 if (m_overlay) |
| 424 m_overlay->finishedRecordingProfile(); | 415 m_overlay->finishedRecordingProfile(); |
| 425 } | 416 } |
| 426 | 417 |
| 427 void InspectorTimelineAgent::didBeginFrame(int frameId) | 418 void InspectorTimelineAgent::didBeginFrame(int frameId) |
| 428 { | 419 { |
| 429 TraceEventDispatcher::instance()->processBackgroundEvents(); | 420 TraceEventDispatcher::instance()->processBackgroundEvents(); |
| 430 m_pendingFrameRecord = TimelineRecordFactory::createGenericRecord(timestamp(
), 0, TimelineRecordType::BeginFrame, TimelineRecordFactory::createFrameData(fra
meId)); | 421 m_pendingFrameRecord = TimelineRecordFactory::createGenericRecord(timestamp(
), 0, TimelineRecordType::BeginFrame, TimelineRecordFactory::createFrameData(fra
meId)); |
| 431 } | 422 } |
| 432 | 423 |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 void InspectorTimelineAgent::onEmbedderCallbackEnd(const TraceEventDispatcher::T
raceEvent& event) | 1042 void InspectorTimelineAgent::onEmbedderCallbackEnd(const TraceEventDispatcher::T
raceEvent& event) |
| 1052 { | 1043 { |
| 1053 TimelineThreadState& state = threadState(event.threadIdentifier()); | 1044 TimelineThreadState& state = threadState(event.threadIdentifier()); |
| 1054 state.recordStack.closeScopedRecord(event.timestamp() * msPerSecond); | 1045 state.recordStack.closeScopedRecord(event.timestamp() * msPerSecond); |
| 1055 } | 1046 } |
| 1056 | 1047 |
| 1057 void InspectorTimelineAgent::addRecordToTimeline(PassRefPtr<TimelineEvent> recor
d, double ts) | 1048 void InspectorTimelineAgent::addRecordToTimeline(PassRefPtr<TimelineEvent> recor
d, double ts) |
| 1058 { | 1049 { |
| 1059 commitFrameRecord(); | 1050 commitFrameRecord(); |
| 1060 innerAddRecordToTimeline(record); | 1051 innerAddRecordToTimeline(record); |
| 1061 if (m_bufferedEvents && ts - m_lastProgressTimestamp > 300) { | 1052 if (ts - m_lastProgressTimestamp > 300) { |
| 1062 m_lastProgressTimestamp = ts; | 1053 m_lastProgressTimestamp = ts; |
| 1063 m_frontend->progress(m_bufferedEvents->length()); | 1054 m_frontend->progress(m_bufferedEvents->length()); |
| 1064 } | 1055 } |
| 1065 } | 1056 } |
| 1066 | 1057 |
| 1067 void InspectorTimelineAgent::innerAddRecordToTimeline(PassRefPtr<TimelineEvent>
record) | 1058 void InspectorTimelineAgent::innerAddRecordToTimeline(PassRefPtr<TimelineEvent>
record) |
| 1068 { | 1059 { |
| 1069 if (m_recordStack.isEmpty()) { | 1060 if (m_recordStack.isEmpty()) { |
| 1070 TraceEventDispatcher::instance()->processBackgroundEvents(); | 1061 TraceEventDispatcher::instance()->processBackgroundEvents(); |
| 1071 sendEvent(record); | 1062 sendEvent(record); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 { | 1162 { |
| 1172 double ts = timestamp(); | 1163 double ts = timestamp(); |
| 1173 RefPtr<TimelineEvent> record = TimelineRecordFactory::createGenericRecord(ts
, captureCallStack ? m_maxCallStackDepth : 0, type, data); | 1164 RefPtr<TimelineEvent> record = TimelineRecordFactory::createGenericRecord(ts
, captureCallStack ? m_maxCallStackDepth : 0, type, data); |
| 1174 setFrameIdentifier(record.get(), frame); | 1165 setFrameIdentifier(record.get(), frame); |
| 1175 addRecordToTimeline(record.release(), ts); | 1166 addRecordToTimeline(record.release(), ts); |
| 1176 } | 1167 } |
| 1177 | 1168 |
| 1178 void InspectorTimelineAgent::sendEvent(PassRefPtr<TimelineEvent> record) | 1169 void InspectorTimelineAgent::sendEvent(PassRefPtr<TimelineEvent> record) |
| 1179 { | 1170 { |
| 1180 RefPtr<TimelineEvent> retain = record; | 1171 RefPtr<TimelineEvent> retain = record; |
| 1181 if (m_bufferedEvents) { | 1172 m_bufferedEvents->addItem(retain); |
| 1182 m_bufferedEvents->addItem(retain); | 1173 if (!m_liveEvents.contains(TimelineRecordFactory::type(retain.get()))) |
| 1183 if (!m_liveEvents.contains(TimelineRecordFactory::type(retain.get()))) | 1174 return; |
| 1184 return; | |
| 1185 } | |
| 1186 m_frontend->eventRecorded(retain.release()); | 1175 m_frontend->eventRecorded(retain.release()); |
| 1187 } | 1176 } |
| 1188 | 1177 |
| 1189 void InspectorTimelineAgent::pushCurrentRecord(PassRefPtr<JSONObject> data, cons
t String& type, bool captureCallStack, LocalFrame* frame, bool hasLowLevelDetail
s) | 1178 void InspectorTimelineAgent::pushCurrentRecord(PassRefPtr<JSONObject> data, cons
t String& type, bool captureCallStack, LocalFrame* frame, bool hasLowLevelDetail
s) |
| 1190 { | 1179 { |
| 1191 commitFrameRecord(); | 1180 commitFrameRecord(); |
| 1192 RefPtr<TimelineEvent> record = TimelineRecordFactory::createGenericRecord(ti
mestamp(), captureCallStack ? m_maxCallStackDepth : 0, type, data.get()); | 1181 RefPtr<TimelineEvent> record = TimelineRecordFactory::createGenericRecord(ti
mestamp(), captureCallStack ? m_maxCallStackDepth : 0, type, data.get()); |
| 1193 setFrameIdentifier(record.get(), frame); | 1182 setFrameIdentifier(record.get(), frame); |
| 1194 m_recordStack.append(TimelineRecordEntry(record.release(), data, TypeBuilder
::Array<TimelineEvent>::create(), type)); | 1183 m_recordStack.append(TimelineRecordEntry(record.release(), data, TypeBuilder
::Array<TimelineEvent>::create(), type)); |
| 1195 if (hasLowLevelDetails && !m_platformInstrumentationClientInstalledAtStackDe
pth && !PlatformInstrumentation::hasClient()) { | 1184 if (hasLowLevelDetails && !m_platformInstrumentationClientInstalledAtStackDe
pth && !PlatformInstrumentation::hasClient()) { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 | 1295 |
| 1307 #ifndef NDEBUG | 1296 #ifndef NDEBUG |
| 1308 bool TimelineRecordStack::isOpenRecordOfType(const String& type) | 1297 bool TimelineRecordStack::isOpenRecordOfType(const String& type) |
| 1309 { | 1298 { |
| 1310 return !m_stack.isEmpty() && m_stack.last().type == type; | 1299 return !m_stack.isEmpty() && m_stack.last().type == type; |
| 1311 } | 1300 } |
| 1312 #endif | 1301 #endif |
| 1313 | 1302 |
| 1314 } // namespace WebCore | 1303 } // namespace WebCore |
| 1315 | 1304 |
| OLD | NEW |