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

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

Issue 654013003: Implement invalidation tracking in devtools (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update test for landing Created 6 years, 2 months 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 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 /** 5 /**
6 * @constructor 6 * @constructor
7 * @extends {WebInspector.TimelineUIUtils} 7 * @extends {WebInspector.TimelineUIUtils}
8 */ 8 */
9 WebInspector.TracingTimelineUIUtils = function() 9 WebInspector.TracingTimelineUIUtils = function()
10 { 10 {
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 * @param {!WebInspector.TracingModel.Event} event 479 * @param {!WebInspector.TracingModel.Event} event
480 * @param {!WebInspector.TracingTimelineModel} model 480 * @param {!WebInspector.TracingTimelineModel} model
481 * @param {!WebInspector.Linkifier} linkifier 481 * @param {!WebInspector.Linkifier} linkifier
482 * @param {function(!DocumentFragment)} callback 482 * @param {function(!DocumentFragment)} callback
483 */ 483 */
484 WebInspector.TracingTimelineUIUtils.buildTraceEventDetails = function(event, mod el, linkifier, callback) 484 WebInspector.TracingTimelineUIUtils.buildTraceEventDetails = function(event, mod el, linkifier, callback)
485 { 485 {
486 var target = event.thread.target(); 486 var target = event.thread.target();
487 var relatedNode = null; 487 var relatedNode = null;
488 var barrier = new CallbackBarrier(); 488 var barrier = new CallbackBarrier();
489 if (!event.previewElement && target) { 489 if (!event.previewElement) {
490 if (event.imageURL) 490 if (event.imageURL)
491 WebInspector.DOMPresentationUtils.buildImagePreviewContents(target, event.imageURL, false, barrier.createCallback(saveImage)); 491 WebInspector.DOMPresentationUtils.buildImagePreviewContents(target, event.imageURL, false, barrier.createCallback(saveImage));
492 else if (event.picture) 492 else if (event.picture)
493 WebInspector.TracingTimelineUIUtils.buildPicturePreviewContent(event , barrier.createCallback(saveImage)); 493 WebInspector.TracingTimelineUIUtils.buildPicturePreviewContent(event , barrier.createCallback(saveImage));
494 } 494 }
495 if (event.backendNodeId && target) 495 if (event.backendNodeId)
496 target.domModel.pushNodesByBackendIdsToFrontend([event.backendNodeId], b arrier.createCallback(setRelatedNode)); 496 target.domModel.pushNodesByBackendIdsToFrontend([event.backendNodeId], b arrier.createCallback(setRelatedNode));
497 if (event.invalidationTrackingEvents)
498 WebInspector.TracingTimelineUIUtils._pushInvalidationNodeIdsToFrontend(e vent, barrier.createCallback(updateInvalidationNodeIds));
497 barrier.callWhenDone(callbackWrapper); 499 barrier.callWhenDone(callbackWrapper);
498 500
499 /** 501 /**
500 * @param {!Element=} element 502 * @param {!Element=} element
501 */ 503 */
502 function saveImage(element) 504 function saveImage(element)
503 { 505 {
504 event.previewElement = element || null; 506 event.previewElement = element || null;
505 } 507 }
506 508
507 /** 509 /**
508 * @param {?Array.<!DOMAgent.NodeId>} nodeIds 510 * @param {?Array.<!DOMAgent.NodeId>} nodeIds
509 */ 511 */
510 function setRelatedNode(nodeIds) 512 function setRelatedNode(nodeIds)
511 { 513 {
512 if (nodeIds) 514 if (nodeIds)
513 relatedNode = target.domModel.nodeForId(nodeIds[0]); 515 relatedNode = target.domModel.nodeForId(nodeIds[0]);
514 } 516 }
515 517
518 /**
519 * @param {?Array.<!DOMAgent.NodeId>} frontendNodeIds
520 */
521 function updateInvalidationNodeIds(frontendNodeIds, backendNodeIds)
522 {
523 if (!frontendNodeIds)
524 return;
525 if (frontendNodeIds.length !== backendNodeIds.length) {
526 console.error("Did not resolve the correct number of invalidation no de ids.");
527 return;
528 }
529
530 var backendToFrontendNodeIdMap = {};
531 backendNodeIds.forEach(function(backendNodeId, index) {
532 backendToFrontendNodeIdMap[backendNodeId] = frontendNodeIds[index];
533 });
534
535 if (event.nodeId)
536 event.frontendNodeId = backendToFrontendNodeIdMap[event.nodeId];
537 event.invalidationTrackingEvents.forEach(function(invalidation) {
538 if (invalidation.nodeId)
539 invalidation.frontendNodeId = backendToFrontendNodeIdMap[invalid ation.nodeId];
540 });
541 }
542
516 function callbackWrapper() 543 function callbackWrapper()
517 { 544 {
518 callback(WebInspector.TracingTimelineUIUtils._buildTraceEventDetailsSync hronously(event, model, linkifier, relatedNode)); 545 callback(WebInspector.TracingTimelineUIUtils._buildTraceEventDetailsSync hronously(event, model, linkifier, relatedNode));
519 } 546 }
520 } 547 }
521 548
522 /** 549 /**
523 * @param {!WebInspector.TracingModel.Event} event 550 * @param {!WebInspector.TracingModel.Event} event
524 * @param {!WebInspector.TracingTimelineModel} model 551 * @param {!WebInspector.TracingTimelineModel} model
525 * @param {!WebInspector.Linkifier} linkifier 552 * @param {!WebInspector.Linkifier} linkifier
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 693
667 var warning = event.warning; 694 var warning = event.warning;
668 if (warning) { 695 if (warning) {
669 var div = createElement("div"); 696 var div = createElement("div");
670 div.textContent = warning; 697 div.textContent = warning;
671 contentHelper.appendElementRow(WebInspector.UIString("Warning"), div); 698 contentHelper.appendElementRow(WebInspector.UIString("Warning"), div);
672 } 699 }
673 if (event.previewElement) 700 if (event.previewElement)
674 contentHelper.appendElementRow(WebInspector.UIString("Preview"), event.p reviewElement); 701 contentHelper.appendElementRow(WebInspector.UIString("Preview"), event.p reviewElement);
675 702
676 if (event.stackTrace || (event.initiator && event.initiator.stackTrace)) 703 if (event.stackTrace || (event.initiator && event.initiator.stackTrace) || e vent.invalidationTrackingEvents)
677 WebInspector.TracingTimelineUIUtils._generateCauses(event, contentHelper ); 704 WebInspector.TracingTimelineUIUtils._generateCauses(event, contentHelper );
678 705
679 fragment.appendChild(contentHelper.element); 706 fragment.appendChild(contentHelper.element);
680 return fragment; 707 return fragment;
681 } 708 }
682 709
683 /** 710 /**
684 * @param {!WebInspector.TracingModel.Event} event 711 * @param {!WebInspector.TracingModel.Event} event
685 * @param {!WebInspector.TimelineDetailsContentHelper} contentHelper 712 * @param {!WebInspector.TimelineDetailsContentHelper} contentHelper
686 */ 713 */
687 WebInspector.TracingTimelineUIUtils._generateCauses = function(event, contentHel per) 714 WebInspector.TracingTimelineUIUtils._generateCauses = function(event, contentHel per)
688 { 715 {
689 var recordTypes = WebInspector.TracingTimelineModel.RecordType; 716 var recordTypes = WebInspector.TracingTimelineModel.RecordType;
690 717
691 var callSiteStackLabel; 718 var callSiteStackLabel;
692 var stackLabel; 719 var stackLabel;
720 var initiator = event.initiator;
693 721
694 switch (event.name) { 722 switch (event.name) {
695 case recordTypes.TimerFire: 723 case recordTypes.TimerFire:
696 callSiteStackLabel = WebInspector.UIString("Timer installed"); 724 callSiteStackLabel = WebInspector.UIString("Timer installed");
697 break; 725 break;
698 case recordTypes.FireAnimationFrame: 726 case recordTypes.FireAnimationFrame:
699 callSiteStackLabel = WebInspector.UIString("Animation frame requested"); 727 callSiteStackLabel = WebInspector.UIString("Animation frame requested");
700 break; 728 break;
701 case recordTypes.RecalculateStyles: 729 case recordTypes.RecalculateStyles:
702 stackLabel = WebInspector.UIString("Stack when style recalculation was f orced"); 730 stackLabel = WebInspector.UIString("Stack when style recalculation was f orced");
703 break; 731 break;
704 case recordTypes.Layout: 732 case recordTypes.Layout:
705 callSiteStackLabel = WebInspector.UIString("First layout invalidation"); 733 callSiteStackLabel = WebInspector.UIString("First layout invalidation");
706 stackLabel = WebInspector.UIString("Stack when layout was forced"); 734 stackLabel = WebInspector.UIString("Stack when layout was forced");
707 break; 735 break;
708 } 736 }
709 737
710 // Direct cause. 738 // Direct cause.
711 if (event.stackTrace) 739 if (event.stackTrace)
712 contentHelper.appendStackTrace(stackLabel || WebInspector.UIString("Stac k when this event occurred"), event.stackTrace); 740 contentHelper.appendStackTrace(stackLabel || WebInspector.UIString("Stac k when this event occurred"), event.stackTrace);
713 741
714 // Indirect cause / invalidation. 742 // Indirect causes.
715 var initiator = event.initiator; 743 if (event.invalidationTrackingEvents) { // Full invalidation tracking (exper imental).
716 if (initiator && initiator.stackTrace) 744 WebInspector.TracingTimelineUIUtils._generateInvalidations(event, conten tHelper);
745 } else if (initiator && initiator.stackTrace) { // Partial invalidation trac king.
717 contentHelper.appendStackTrace(callSiteStackLabel || WebInspector.UIStri ng("Stack when first invalidated"), initiator.stackTrace); 746 contentHelper.appendStackTrace(callSiteStackLabel || WebInspector.UIStri ng("Stack when first invalidated"), initiator.stackTrace);
747 }
718 } 748 }
719 749
720 /** 750 /**
751 * @param {!WebInspector.TracingModel.Event} event
752 * @param {!WebInspector.TimelineDetailsContentHelper} contentHelper
753 */
754 WebInspector.TracingTimelineUIUtils._generateInvalidations = function(event, con tentHelper)
755 {
756 if (!event.invalidationTrackingEvents)
757 return;
758
759 var target = event.thread.target();
760 var invalidations = {};
761 event.invalidationTrackingEvents.forEach(function(invalidation) {
762 if (!invalidations[invalidation.type])
763 invalidations[invalidation.type] = [invalidation];
764 else
765 invalidations[invalidation.type].push(invalidation);
766 });
767
768 Object.keys(invalidations).forEach(function(type) {
769 WebInspector.TracingTimelineUIUtils._generateInvalidationsForType(
770 type, target, invalidations[type], contentHelper);
771 });
772 }
773
774 /**
775 * @param {string} type
776 * @param {?WebInspector.Target} target
777 * @param {!Object} invalidationEvents
778 * @param {!WebInspector.TimelineDetailsContentHelper} contentHelper
779 */
780 WebInspector.TracingTimelineUIUtils._generateInvalidationsForType = function(typ e, target, invalidationEvents, contentHelper)
781 {
782 var title;
783 switch (type) {
784 case WebInspector.TracingTimelineModel.RecordType.StyleRecalcInvalidationTra cking:
785 title = WebInspector.UIString("Style invalidations");
786 break;
787 case WebInspector.TracingTimelineModel.RecordType.LayoutInvalidationTracking :
788 title = WebInspector.UIString("Layout invalidations");
789 break;
790 default:
791 title = WebInspector.UIString("Other invalidations");
792 break;
793 }
794
795 var detailsNode = document.createElement("div");
796 detailsNode.className = "timeline-details-view-row";
797 var titleElement = detailsNode.createChild("span", "timeline-details-view-ro w-title");
798 titleElement.textContent = WebInspector.UIString("%s: ", title);
799 var eventsList = detailsNode.createChild("ol");
800 invalidationEvents.forEach(appendInvalidations);
801
802 contentHelper.element.appendChild(detailsNode);
803
804
805 function appendInvalidations(invalidation, index)
806 {
807 var row = eventsList.createChild("li");
808 var nodeRow = row.createChild("div");
809 var node = target.domModel.nodeForId(invalidation.frontendNodeId);
810 if (node)
811 nodeRow.appendChild(WebInspector.DOMPresentationUtils.linkifyNodeRef erence(node));
812 else if (invalidation.nodeName)
813 nodeRow.textContent = WebInspector.UIString("[ %s ]", invalidation.n odeName);
814 else
815 nodeRow.textContent = WebInspector.UIString("[ unknown node ]");
816
817 if (invalidation.reason) {
818 var reasonRow = row.createChild("div");
819 var reason = invalidation.reason;
820 // We should clean up invalidation strings so they are consistent: c rbug.com/424451.
821 if (!invalidation.reason.endsWith("."))
822 reason += ".";
823 reasonRow.textContent = WebInspector.UIString("Reason: %s", reason);
824 }
825
826 if (invalidation.stackTrace)
827 contentHelper.createChildStackTraceElement(row, invalidation.stackTr ace);
828 }
829 }
830
831 /**
832 * @param {!WebInspector.TracingModel.Event} event
833 * @param {function(!Array.<number>, !Array.<number>)} callback
834 */
835 WebInspector.TracingTimelineUIUtils._pushInvalidationNodeIdsToFrontend = functio n(event, callback)
836 {
837 var backendNodeIds = [];
838
839 var dedupedNodeIds = {};
840 if (event.nodeId) {
841 backendNodeIds.push(event.nodeId);
842 dedupedNodeIds[event.nodeId] = true;
843 }
844 event.invalidationTrackingEvents.forEach(function(invalidation) {
845 if (invalidation.nodeId && !dedupedNodeIds[invalidation.nodeId]) {
846 backendNodeIds.push(invalidation.nodeId);
847 dedupedNodeIds[invalidation.nodeId] = true;
848 }
849 });
850
851 var target = event.thread.target();
852 target.domModel.pushNodesByBackendIdsToFrontend(backendNodeIds, function(fro ntendNodeIds) {
853 callback(frontendNodeIds, backendNodeIds);
854 });
855 }
856
857 /**
721 * @param {!Object} total 858 * @param {!Object} total
722 * @param {!WebInspector.TracingTimelineModel} model 859 * @param {!WebInspector.TracingTimelineModel} model
723 * @param {!WebInspector.TracingModel.Event} event 860 * @param {!WebInspector.TracingModel.Event} event
724 * @return {boolean} 861 * @return {boolean}
725 */ 862 */
726 WebInspector.TracingTimelineUIUtils._aggregatedStatsForTraceEvent = function(tot al, model, event) 863 WebInspector.TracingTimelineUIUtils._aggregatedStatsForTraceEvent = function(tot al, model, event)
727 { 864 {
728 var events = model.inspectedTargetEvents(); 865 var events = model.inspectedTargetEvents();
729 /** 866 /**
730 * @param {number} startTime 867 * @param {number} startTime
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 return result; 983 return result;
847 } 984 }
848 985
849 /** 986 /**
850 * @return {!WebInspector.TracingTimelineModel.Filter} 987 * @return {!WebInspector.TracingTimelineModel.Filter}
851 */ 988 */
852 WebInspector.TracingTimelineUIUtils.hiddenEventsFilter = function() 989 WebInspector.TracingTimelineUIUtils.hiddenEventsFilter = function()
853 { 990 {
854 return new WebInspector.TracingTimelineModel.InclusiveEventNameFilter(WebIns pector.TracingTimelineUIUtils._visibleTypes()); 991 return new WebInspector.TracingTimelineModel.InclusiveEventNameFilter(WebIns pector.TracingTimelineUIUtils._visibleTypes());
855 } 992 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698