Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: Source/devtools/front_end/timeline/TimelineModel.js

Issue 724013003: DevTools: Connect worker cpu profiles to worker tracing threads. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Addressing comments. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 return "disabled-by-default-" + category; 397 return "disabled-by-default-" + category;
398 } 398 }
399 var categoriesArray = [ 399 var categoriesArray = [
400 "-*", 400 "-*",
401 disabledByDefault("devtools.timeline"), 401 disabledByDefault("devtools.timeline"),
402 disabledByDefault("devtools.timeline.frame"), 402 disabledByDefault("devtools.timeline.frame"),
403 WebInspector.TracingModel.ConsoleEventCategory 403 WebInspector.TracingModel.ConsoleEventCategory
404 ]; 404 ];
405 if (captureCauses || enableJSSampling) 405 if (captureCauses || enableJSSampling)
406 categoriesArray.push(disabledByDefault("devtools.timeline.stack")); 406 categoriesArray.push(disabledByDefault("devtools.timeline.stack"));
407 if (enableJSSampling)
408 this._startCpuProfilingOnAllTargets();
409 if (captureCauses && Runtime.experiments.isEnabled("timelineInvalidation Tracking")) 407 if (captureCauses && Runtime.experiments.isEnabled("timelineInvalidation Tracking"))
410 categoriesArray.push(disabledByDefault("devtools.timeline.invalidati onTracking")); 408 categoriesArray.push(disabledByDefault("devtools.timeline.invalidati onTracking"));
411 if (capturePictures) { 409 if (capturePictures) {
412 categoriesArray = categoriesArray.concat([ 410 categoriesArray = categoriesArray.concat([
413 disabledByDefault("devtools.timeline.layers"), 411 disabledByDefault("devtools.timeline.layers"),
414 disabledByDefault("devtools.timeline.picture"), 412 disabledByDefault("devtools.timeline.picture"),
415 disabledByDefault("blink.graphics_context_annotations")]); 413 disabledByDefault("blink.graphics_context_annotations")]);
416 } 414 }
417 var categories = categoriesArray.join(","); 415 var categories = categoriesArray.join(",");
418 this._startRecordingWithCategories(categories); 416 this._startRecordingWithCategories(categories, enableJSSampling);
419 }, 417 },
420 418
421 stopRecording: function() 419 stopRecording: function()
422 { 420 {
423 this._stopCallbackBarrier = new CallbackBarrier(); 421 this._stopCallbackBarrier = new CallbackBarrier();
424 this._stopProfilingOnAllTargets(); 422 this._stopProfilingOnAllTargets();
425 this._tracingManager.stop(); 423 this._tracingManager.stop();
426 }, 424 },
427 425
428 /** 426 /**
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 547
550 function didChangeInterval(error) 548 function didChangeInterval(error)
551 { 549 {
552 if (error) 550 if (error)
553 WebInspector.console.error(error); 551 WebInspector.console.error(error);
554 } 552 }
555 }, 553 },
556 554
557 /** 555 /**
558 * @param {string} categories 556 * @param {string} categories
557 * @param {boolean=} enableJSSampling
559 */ 558 */
560 _startRecordingWithCategories: function(categories) 559 _startRecordingWithCategories: function(categories, enableJSSampling)
561 { 560 {
561 if (enableJSSampling)
562 this._startCpuProfilingOnAllTargets();
562 this._tracingManager.start(categories, ""); 563 this._tracingManager.start(categories, "");
563 }, 564 },
564 565
565 _onTracingStarted: function() 566 _onTracingStarted: function()
566 { 567 {
567 this._startCollectingTraceEvents(false); 568 this._startCollectingTraceEvents(false);
568 }, 569 },
569 570
570 /** 571 /**
571 * @param {boolean} fromFile 572 * @param {boolean} fromFile
(...skipping 27 matching lines...) Expand all
599 /** 600 /**
600 * @param {!WebInspector.Target} target 601 * @param {!WebInspector.Target} target
601 * @param {?Protocol.Error} error 602 * @param {?Protocol.Error} error
602 * @param {?ProfilerAgent.CPUProfile} cpuProfile 603 * @param {?ProfilerAgent.CPUProfile} cpuProfile
603 */ 604 */
604 _didStopRecordingJSSamples: function(target, error, cpuProfile) 605 _didStopRecordingJSSamples: function(target, error, cpuProfile)
605 { 606 {
606 if (error) 607 if (error)
607 WebInspector.console.error(error); 608 WebInspector.console.error(error);
608 if (!this._cpuProfiles) 609 if (!this._cpuProfiles)
609 this._cpuProfiles = {}; 610 this._cpuProfiles = new Map();
610 this._cpuProfiles[target.id()] = cpuProfile; 611 this._cpuProfiles.set(target.id(), cpuProfile);
611 }, 612 },
612 613
613 _didStopRecordingTraceEvents: function() 614 _didStopRecordingTraceEvents: function()
614 { 615 {
615 this._tracingModel.tracingComplete(); 616 this._tracingModel.tracingComplete();
616 617
617 var events = this._tracingModel.devtoolsPageMetadataEvents(); 618 var metaEvents = this._tracingModel.devtoolsPageMetadataEvents();
618 var workerMetadataEvents = this._tracingModel.devtoolsWorkerMetadataEven ts(); 619 var workerMetadataEvents = this._tracingModel.devtoolsWorkerMetadataEven ts();
619 620
620 this._resetProcessingState(); 621 this._resetProcessingState();
621 for (var i = 0, length = events.length; i < length; i++) { 622 for (var i = 0, length = metaEvents.length; i < length; i++) {
622 var event = events[i]; 623 var metaEvent = metaEvents[i];
623 var process = event.thread.process(); 624 var process = metaEvent.thread.process();
624 var startTime = event.startTime; 625 var startTime = metaEvent.startTime;
625 626
626 var endTime = Infinity; 627 var endTime = Infinity;
627 if (i + 1 < length) 628 if (i + 1 < length)
628 endTime = events[i + 1].startTime; 629 endTime = metaEvents[i + 1].startTime;
629 630
630 var threads = process.sortedThreads(); 631 var threads = process.sortedThreads();
631 for (var j = 0; j < threads.length; j++) { 632 for (var j = 0; j < threads.length; j++) {
632 var thread = threads[j]; 633 var thread = threads[j];
633 if (thread.name() === "WebCore: Worker" && workerMetadataEvents. every(function(e) { return e.args["data"]["workerThreadId"] !== thread.id(); })) 634 var workerId = 0;
634 continue; 635 if (thread.name() === "WebCore: Worker") {
635 this._processThreadEvents(startTime, endTime, event.thread, thre ad); 636 for (var k = 0; k < workerMetadataEvents.length; ++k) {
637 var eventData = workerMetadataEvents[k].args["data"];
638 if (eventData["workerThreadId"] === thread.id()) {
639 workerId = eventData["workerId"];
640 break;
641 }
642 }
643 if (!workerId)
644 continue;
645 }
646 this._processThreadEvents(startTime, endTime, metaEvent.thread, thread, workerId);
636 } 647 }
637 } 648 }
638 this._resetProcessingState(); 649 this._resetProcessingState();
639 650
640 this._inspectedTargetEvents.sort(WebInspector.TracingModel.Event.compare StartTime); 651 this._inspectedTargetEvents.sort(WebInspector.TracingModel.Event.compare StartTime);
641 652
642 this._cpuProfiles = null; 653 this._cpuProfiles = null;
643 654
644 this._buildTimelineRecords(); 655 this._buildTimelineRecords();
645 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin gStopped); 656 this.dispatchEventToListeners(WebInspector.TimelineModel.Events.Recordin gStopped);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 this._lastRecalculateStylesEvent = null; 766 this._lastRecalculateStylesEvent = null;
756 this._currentScriptEvent = null; 767 this._currentScriptEvent = null;
757 this._eventStack = []; 768 this._eventStack = [];
758 }, 769 },
759 770
760 /** 771 /**
761 * @param {number} startTime 772 * @param {number} startTime
762 * @param {?number} endTime 773 * @param {?number} endTime
763 * @param {!WebInspector.TracingModel.Thread} mainThread 774 * @param {!WebInspector.TracingModel.Thread} mainThread
764 * @param {!WebInspector.TracingModel.Thread} thread 775 * @param {!WebInspector.TracingModel.Thread} thread
776 * @param {number} workerId
765 */ 777 */
766 _processThreadEvents: function(startTime, endTime, mainThread, thread) 778 _processThreadEvents: function(startTime, endTime, mainThread, thread, worke rId)
767 { 779 {
768 var events = thread.events(); 780 var events = thread.events();
769 var length = events.length; 781 var length = events.length;
770 var i = events.lowerBound(startTime, function (time, event) { return tim e - event.startTime }); 782 var i = events.lowerBound(startTime, function (time, event) { return tim e - event.startTime });
771 783
772 var threadEvents; 784 var threadEvents;
773 var virtualThread = null; 785 var virtualThread = null;
774 if (thread === mainThread) { 786 if (thread === mainThread) {
775 threadEvents = this._mainThreadEvents; 787 threadEvents = this._mainThreadEvents;
776 this._mainThreadAsyncEvents = this._mainThreadAsyncEvents.concat(thr ead.asyncEvents()); 788 this._mainThreadAsyncEvents = this._mainThreadAsyncEvents.concat(thr ead.asyncEvents());
777 } else { 789 } else {
778 virtualThread = new WebInspector.TimelineModel.VirtualThread(thread. name()); 790 virtualThread = new WebInspector.TimelineModel.VirtualThread(thread. name());
779 threadEvents = virtualThread.events; 791 threadEvents = virtualThread.events;
780 virtualThread.asyncEvents = virtualThread.asyncEvents.concat(thread. asyncEvents()); 792 virtualThread.asyncEvents = virtualThread.asyncEvents.concat(thread. asyncEvents());
781 this._virtualThreads.push(virtualThread); 793 this._virtualThreads.push(virtualThread);
782 } 794 }
783 795
784 this._eventStack = []; 796 this._eventStack = [];
785 for (; i < length; i++) { 797 for (; i < length; i++) {
786 var event = events[i]; 798 var event = events[i];
787 if (endTime && event.startTime >= endTime) 799 if (endTime && event.startTime >= endTime)
788 break; 800 break;
789 this._processEvent(event); 801 this._processEvent(event);
790 threadEvents.push(event); 802 threadEvents.push(event);
791 this._inspectedTargetEvents.push(event); 803 this._inspectedTargetEvents.push(event);
792 } 804 }
793 805
794 if (this._cpuProfiles && thread.target()) { 806 if (!this._cpuProfiles)
795 var cpuProfile = this._cpuProfiles[thread.target().id()]; 807 return;
796 if (cpuProfile) { 808 var target = thread === mainThread ? WebInspector.targetManager.mainTarg et() : WebInspector.workerTargetManager.targetByWorkerId(workerId);
797 var jsSamples = WebInspector.TimelineJSProfileProcessor.generate TracingEventsFromCpuProfile(cpuProfile, thread); 809 if (!target)
798 var mergedEvents = threadEvents.mergeOrdered(jsSamples, WebInspe ctor.TracingModel.Event.orderedCompareStartTime); 810 return;
799 var jsFrameEvents = WebInspector.TimelineJSProfileProcessor.gene rateJSFrameEvents(mergedEvents); 811 var cpuProfile = this._cpuProfiles.get(target.id());
800 mergedEvents = jsFrameEvents.mergeOrdered(mergedEvents, WebInspe ctor.TracingModel.Event.orderedCompareStartTime); 812 if (!cpuProfile)
801 if (virtualThread) 813 return;
802 virtualThread.events = mergedEvents; 814 this._cpuProfiles.delete(target.id());
803 else 815 var jsSamples = WebInspector.TimelineJSProfileProcessor.generateTracingE ventsFromCpuProfile(cpuProfile, thread);
804 this._mainThreadEvents = mergedEvents; 816 var mergedEvents = threadEvents.mergeOrdered(jsSamples, WebInspector.Tra cingModel.Event.orderedCompareStartTime);
805 this._inspectedTargetEvents = this._inspectedTargetEvents.concat (jsSamples, jsFrameEvents); 817 var jsFrameEvents = WebInspector.TimelineJSProfileProcessor.generateJSFr ameEvents(mergedEvents);
806 } 818 mergedEvents = jsFrameEvents.mergeOrdered(mergedEvents, WebInspector.Tra cingModel.Event.orderedCompareStartTime);
807 } 819 if (virtualThread)
820 virtualThread.events = mergedEvents;
821 else
822 this._mainThreadEvents = mergedEvents;
823 this._inspectedTargetEvents = this._inspectedTargetEvents.concat(jsSampl es, jsFrameEvents);
808 }, 824 },
809 825
810 /** 826 /**
811 * @param {!WebInspector.TracingModel.Event} event 827 * @param {!WebInspector.TracingModel.Event} event
812 */ 828 */
813 _processEvent: function(event) 829 _processEvent: function(event)
814 { 830 {
815 var recordTypes = WebInspector.TimelineModel.RecordType; 831 var recordTypes = WebInspector.TimelineModel.RecordType;
816 832
817 var eventStack = this._eventStack; 833 var eventStack = this._eventStack;
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 _initializePerFrameState: function() 1713 _initializePerFrameState: function()
1698 { 1714 {
1699 /** @type {!Array.<!WebInspector.InvalidationTrackingEvent>} */ 1715 /** @type {!Array.<!WebInspector.InvalidationTrackingEvent>} */
1700 this._invalidationEvents = []; 1716 this._invalidationEvents = [];
1701 this._lastStyleRecalcEventIndex = 0; 1717 this._lastStyleRecalcEventIndex = 0;
1702 this._lastLayoutEventIndex = 0; 1718 this._lastLayoutEventIndex = 0;
1703 this._lastPaintWithLayer = undefined; 1719 this._lastPaintWithLayer = undefined;
1704 this._didPaint = false; 1720 this._didPaint = false;
1705 } 1721 }
1706 } 1722 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698