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

Side by Side Diff: Source/devtools/front_end/profiler/CPUProfileView.js

Issue 360053003: DevTools: Basic support of multiple targets for CPU profiler (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Migrate to events Created 6 years, 5 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
« no previous file with comments | « no previous file | Source/devtools/front_end/sdk/CPUProfilerModel.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 this.excludeButton = new WebInspector.StatusBarButton(WebInspector.UIString( "Exclude selected function."), "exclude-profile-node-status-bar-item"); 66 this.excludeButton = new WebInspector.StatusBarButton(WebInspector.UIString( "Exclude selected function."), "exclude-profile-node-status-bar-item");
67 this.excludeButton.setEnabled(false); 67 this.excludeButton.setEnabled(false);
68 this.excludeButton.addEventListener("click", this._excludeClicked, this); 68 this.excludeButton.addEventListener("click", this._excludeClicked, this);
69 this._statusBarButtonsElement.appendChild(this.excludeButton.element); 69 this._statusBarButtonsElement.appendChild(this.excludeButton.element);
70 70
71 this.resetButton = new WebInspector.StatusBarButton(WebInspector.UIString("R estore all functions."), "reset-profile-status-bar-item"); 71 this.resetButton = new WebInspector.StatusBarButton(WebInspector.UIString("R estore all functions."), "reset-profile-status-bar-item");
72 this.resetButton.visible = false; 72 this.resetButton.visible = false;
73 this.resetButton.addEventListener("click", this._resetClicked, this); 73 this.resetButton.addEventListener("click", this._resetClicked, this);
74 this._statusBarButtonsElement.appendChild(this.resetButton.element); 74 this._statusBarButtonsElement.appendChild(this.resetButton.element);
75 75
76 this._profileHeader = profileHeader; 76 this._target = profileHeader.target();
77 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultFormatter(30)); 77 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultFormatter(30));
78 78
79 this.profile = new WebInspector.CPUProfileDataModel(profileHeader._profile | | profileHeader.protocolProfile()); 79 this.profile = new WebInspector.CPUProfileDataModel(profileHeader._profile | | profileHeader.protocolProfile());
80 80
81 this._changeView(); 81 this._changeView();
82 if (this._flameChart) 82 if (this._flameChart)
83 this._flameChart.update(); 83 this._flameChart.update();
84 } 84 }
85 85
86 WebInspector.CPUProfileView._TypeFlame = "Flame"; 86 WebInspector.CPUProfileView._TypeFlame = "Flame";
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 return; 345 return;
346 346
347 var profileNode = searchResult.profileNode; 347 var profileNode = searchResult.profileNode;
348 profileNode.revealAndSelect(); 348 profileNode.revealAndSelect();
349 }, 349 },
350 350
351 _ensureFlameChartCreated: function() 351 _ensureFlameChartCreated: function()
352 { 352 {
353 if (this._flameChart) 353 if (this._flameChart)
354 return; 354 return;
355 this._dataProvider = new WebInspector.CPUFlameChartDataProvider(this.pro file, this._profileHeader.target()); 355 this._dataProvider = new WebInspector.CPUFlameChartDataProvider(this.pro file, this._target);
356 this._flameChart = new WebInspector.CPUProfileFlameChart(this._dataProvi der); 356 this._flameChart = new WebInspector.CPUProfileFlameChart(this._dataProvi der);
357 this._flameChart.addEventListener(WebInspector.FlameChart.Events.EntrySe lected, this._onEntrySelected.bind(this)); 357 this._flameChart.addEventListener(WebInspector.FlameChart.Events.EntrySe lected, this._onEntrySelected.bind(this));
358 }, 358 },
359 359
360 /** 360 /**
361 * @param {!WebInspector.Event} event 361 * @param {!WebInspector.Event} event
362 */ 362 */
363 _onEntrySelected: function(event) 363 _onEntrySelected: function(event)
364 { 364 {
365 var entryIndex = event.data; 365 var entryIndex = event.data;
366 var node = this._dataProvider._entryNodes[entryIndex]; 366 var node = this._dataProvider._entryNodes[entryIndex];
367 if (!node || !node.scriptId) 367 if (!node || !node.scriptId || !this._target)
368 return; 368 return;
369 var script = WebInspector.debuggerModel.scriptForId(node.scriptId) 369 var script = this._target.debuggerModel.scriptForId(node.scriptId)
370 if (!script) 370 if (!script)
371 return; 371 return;
372 WebInspector.Revealer.reveal(script.rawLocationToUILocation(node.lineNum ber)); 372 WebInspector.Revealer.reveal(script.rawLocationToUILocation(node.lineNum ber));
373 }, 373 },
374 374
375 _changeView: function() 375 _changeView: function()
376 { 376 {
377 if (!this.profile) 377 if (!this.profile)
378 return; 378 return;
379 379
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 474
475 this.refresh(); 475 this.refresh();
476 }, 476 },
477 477
478 __proto__: WebInspector.VBox.prototype 478 __proto__: WebInspector.VBox.prototype
479 } 479 }
480 480
481 /** 481 /**
482 * @constructor 482 * @constructor
483 * @extends {WebInspector.ProfileType} 483 * @extends {WebInspector.ProfileType}
484 * @implements {WebInspector.CPUProfilerModel.Delegate} 484 * @implements {WebInspector.TargetManager.Observer}
485 */ 485 */
486 WebInspector.CPUProfileType = function() 486 WebInspector.CPUProfileType = function()
487 { 487 {
488 WebInspector.ProfileType.call(this, WebInspector.CPUProfileType.TypeId, WebI nspector.UIString("Collect JavaScript CPU Profile")); 488 WebInspector.ProfileType.call(this, WebInspector.CPUProfileType.TypeId, WebI nspector.UIString("Collect JavaScript CPU Profile"));
489 this._recording = false; 489 this._recording = false;
490 490
491 this._nextAnonymousConsoleProfileNumber = 1; 491 this._nextAnonymousConsoleProfileNumber = 1;
492 this._anonymousConsoleProfileIdToTitle = {}; 492 this._anonymousConsoleProfileIdToTitle = {};
493 493
494 WebInspector.CPUProfileType.instance = this; 494 WebInspector.CPUProfileType.instance = this;
495 WebInspector.cpuProfilerModel.setDelegate(this); 495 WebInspector.targetManager.observeTargets(this);
496 } 496 }
497 497
498 WebInspector.CPUProfileType.TypeId = "CPU"; 498 WebInspector.CPUProfileType.TypeId = "CPU";
499 499
500 WebInspector.CPUProfileType.prototype = { 500 WebInspector.CPUProfileType.prototype = {
501 /** 501 /**
502 * @param {!WebInspector.Target} target
503 */
504 targetAdded: function(target)
505 {
506 target.cpuProfilerModel.addEventListener(WebInspector.CPUProfilerModel.E ventTypes.ConsoleProfileStarted, this._consoleProfileStarted, this);
507 target.cpuProfilerModel.addEventListener(WebInspector.CPUProfilerModel.E ventTypes.ConsoleProfileFinished, this._consoleProfileFinished, this);
508 },
509
510 /**
511 * @param {!WebInspector.Target} target
512 */
513 targetRemoved: function(target)
514 {
515 target.cpuProfilerModel.removeEventListener(WebInspector.CPUProfilerMode l.EventTypes.ConsoleProfileStarted, this._consoleProfileStarted, this);
516 target.cpuProfilerModel.removeEventListener(WebInspector.CPUProfilerMode l.EventTypes.ConsoleProfileFinished, this._consoleProfileFinished, this);
517 },
518
519 /**
502 * @override 520 * @override
503 * @return {string} 521 * @return {string}
504 */ 522 */
505 fileExtension: function() 523 fileExtension: function()
506 { 524 {
507 return ".cpuprofile"; 525 return ".cpuprofile";
508 }, 526 },
509 527
510 get buttonTooltip() 528 get buttonTooltip()
511 { 529 {
(...skipping 19 matching lines...) Expand all
531 { 549 {
532 return WebInspector.UIString("CPU PROFILES"); 550 return WebInspector.UIString("CPU PROFILES");
533 }, 551 },
534 552
535 get description() 553 get description()
536 { 554 {
537 return WebInspector.UIString("CPU profiles show where the execution time is spent in your page's JavaScript functions."); 555 return WebInspector.UIString("CPU profiles show where the execution time is spent in your page's JavaScript functions.");
538 }, 556 },
539 557
540 /** 558 /**
541 * @param {string} id 559 * @param {!WebInspector.Event} event
542 * @param {!WebInspector.DebuggerModel.Location} scriptLocation
543 * @param {string=} title
544 */ 560 */
545 consoleProfileStarted: function(id, scriptLocation, title) 561 _consoleProfileStarted: function(event)
546 { 562 {
547 var resolvedTitle = title; 563 var data = /** @type {{protocolId: string, scriptLocation: !WebInspector .DebuggerModel.Location, title: (string|undefined)}} */ (event.data);
564 var resolvedTitle = data.title;
548 if (!resolvedTitle) { 565 if (!resolvedTitle) {
549 resolvedTitle = WebInspector.UIString("Profile %s", this._nextAnonym ousConsoleProfileNumber++); 566 resolvedTitle = WebInspector.UIString("Profile %s", this._nextAnonym ousConsoleProfileNumber++);
550 this._anonymousConsoleProfileIdToTitle[id] = resolvedTitle; 567 this._anonymousConsoleProfileIdToTitle[data.protocolId] = resolvedTi tle;
551 } 568 }
552 this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profil e, scriptLocation, WebInspector.UIString("Profile '%s' started.", resolvedTitle) ); 569 this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profil e, data.scriptLocation, WebInspector.UIString("Profile '%s' started.", resolvedT itle));
553 }, 570 },
554 571
555 /** 572 /**
556 * @param {string} protocolId 573 * @param {!WebInspector.Event} event
557 * @param {!WebInspector.DebuggerModel.Location} scriptLocation
558 * @param {!ProfilerAgent.CPUProfile} cpuProfile
559 * @param {string=} title
560 */ 574 */
561 consoleProfileFinished: function(protocolId, scriptLocation, cpuProfile, tit le) 575 _consoleProfileFinished: function(event)
562 { 576 {
563 var resolvedTitle = title; 577 var data = /** @type {{protocolId: string, scriptLocation: !WebInspector .DebuggerModel.Location, cpuProfile: !ProfilerAgent.CPUProfile, title: (string|u ndefined)}} */ (event.data);
vsevik 2014/07/02 09:08:49 Consider casting each field separately instead.
sergeyv 2014/07/02 12:45:42 Done.
564 if (typeof title === "undefined") { 578 var resolvedTitle = data.title;
565 resolvedTitle = this._anonymousConsoleProfileIdToTitle[protocolId]; 579 if (typeof data.title === "undefined") {
566 delete this._anonymousConsoleProfileIdToTitle[protocolId]; 580 resolvedTitle = this._anonymousConsoleProfileIdToTitle[data.protocol Id];
581 delete this._anonymousConsoleProfileIdToTitle[data.protocolId];
567 } 582 }
568 583
569 var target = /** @type {!WebInspector.Target} */ (WebInspector.targetMan ager.activeTarget()); 584 var profile = new WebInspector.CPUProfileHeader(data.scriptLocation.targ et(), this, resolvedTitle);
570 var profile = new WebInspector.CPUProfileHeader(target, this, resolvedTi tle); 585 profile.setProtocolProfile(data.cpuProfile);
571 profile.setProtocolProfile(cpuProfile);
572 this.addProfile(profile); 586 this.addProfile(profile);
573 this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profil eEnd, scriptLocation, WebInspector.UIString("Profile '%s' finished.", resolvedTi tle)); 587 this._addMessageToConsole(WebInspector.ConsoleMessage.MessageType.Profil eEnd, data.scriptLocation, WebInspector.UIString("Profile '%s' finished.", resol vedTitle));
574 }, 588 },
575 589
576 /** 590 /**
577 * @param {string} type 591 * @param {string} type
578 * @param {!WebInspector.DebuggerModel.Location} scriptLocation 592 * @param {!WebInspector.DebuggerModel.Location} scriptLocation
579 * @param {string} messageText 593 * @param {string} messageText
580 */ 594 */
581 _addMessageToConsole: function(type, scriptLocation, messageText) 595 _addMessageToConsole: function(type, scriptLocation, messageText)
582 { 596 {
583 var script = scriptLocation.script(); 597 var script = scriptLocation.script();
598 var target = scriptLocation.target();
584 var message = new WebInspector.ConsoleMessage( 599 var message = new WebInspector.ConsoleMessage(
585 WebInspector.console.target(), 600 target,
586 WebInspector.ConsoleMessage.MessageSource.ConsoleAPI, 601 WebInspector.ConsoleMessage.MessageSource.ConsoleAPI,
587 WebInspector.ConsoleMessage.MessageLevel.Debug, 602 WebInspector.ConsoleMessage.MessageLevel.Debug,
588 messageText, 603 messageText,
589 type, 604 type,
590 undefined, 605 undefined,
591 undefined, 606 undefined,
592 undefined, 607 undefined,
593 undefined, 608 undefined,
594 undefined, 609 undefined,
595 [{ 610 [{
596 functionName: "", 611 functionName: "",
597 scriptId: scriptLocation.scriptId, 612 scriptId: scriptLocation.scriptId,
598 url: script ? script.contentURL() : "", 613 url: script ? script.contentURL() : "",
599 lineNumber: scriptLocation.lineNumber, 614 lineNumber: scriptLocation.lineNumber,
600 columnNumber: scriptLocation.columnNumber || 0 615 columnNumber: scriptLocation.columnNumber || 0
601 }]); 616 }]);
602 617
603 WebInspector.console.addMessage(message); 618 target.consoleModel.addMessage(message);
604 }, 619 },
605 620
606 /** 621 /**
607 * @return {boolean} 622 * @return {boolean}
608 */ 623 */
609 isRecordingProfile: function() 624 isRecordingProfile: function()
vsevik 2014/07/02 09:08:49 I think this method and hence the field is never u
sergeyv 2014/07/02 12:45:42 Done. Method is indeed unused, but the field is u
610 { 625 {
611 return this._recording; 626 return this._recording;
612 }, 627 },
613 628
614 startRecordingProfile: function() 629 startRecordingProfile: function()
615 { 630 {
616 if (this._profileBeingRecorded) 631 var target = WebInspector.context.flavor(WebInspector.Target);
632 if (this._profileBeingRecorded || !target)
617 return; 633 return;
618 var target = /** @type {!WebInspector.Target} */ (WebInspector.targetMan ager.activeTarget());
619 var profile = new WebInspector.CPUProfileHeader(target, this); 634 var profile = new WebInspector.CPUProfileHeader(target, this);
620 this.setProfileBeingRecorded(profile); 635 this.setProfileBeingRecorded(profile);
621 this.addProfile(profile); 636 this.addProfile(profile);
622 profile.updateStatus(WebInspector.UIString("Recording\u2026")); 637 profile.updateStatus(WebInspector.UIString("Recording\u2026"));
623 this._recording = true; 638 this._recording = true;
624 WebInspector.cpuProfilerModel.setRecording(true); 639 target.cpuProfilerModel.startRecording();
625 WebInspector.userMetrics.ProfilesCPUProfileTaken.record();
626 ProfilerAgent.start();
627 }, 640 },
628 641
629 stopRecordingProfile: function() 642 stopRecordingProfile: function()
630 { 643 {
631 this._recording = false; 644 this._recording = false;
632 WebInspector.cpuProfilerModel.setRecording(false); 645 if (!this._profileBeingRecorded || !this._profileBeingRecorded.target())
646 return;
633 647
634 /** 648 /**
635 * @param {?string} error 649 * @param {?string} error
636 * @param {?ProfilerAgent.CPUProfile} profile 650 * @param {?ProfilerAgent.CPUProfile} profile
637 * @this {WebInspector.CPUProfileType} 651 * @this {WebInspector.CPUProfileType}
638 */ 652 */
639 function didStopProfiling(error, profile) 653 function didStopProfiling(error, profile)
640 { 654 {
641 if (!this._profileBeingRecorded) 655 if (!this._profileBeingRecorded)
642 return; 656 return;
643 this._profileBeingRecorded.setProtocolProfile(profile); 657 this._profileBeingRecorded.setProtocolProfile(profile);
644 this._profileBeingRecorded.updateStatus(""); 658 this._profileBeingRecorded.updateStatus("");
645 var recordedProfile = this._profileBeingRecorded; 659 var recordedProfile = this._profileBeingRecorded;
646 this.setProfileBeingRecorded(null); 660 this.setProfileBeingRecorded(null);
647 this.dispatchEventToListeners(WebInspector.ProfileType.Events.Profil eComplete, recordedProfile); 661 this.dispatchEventToListeners(WebInspector.ProfileType.Events.Profil eComplete, recordedProfile);
648 } 662 }
649 ProfilerAgent.stop(didStopProfiling.bind(this)); 663 this._profileBeingRecorded.target().cpuProfilerModel.stopRecording(didSt opProfiling.bind(this));
650 }, 664 },
651 665
652 /** 666 /**
653 * @override 667 * @override
654 * @param {string} title 668 * @param {string} title
655 * @return {!WebInspector.ProfileHeader} 669 * @return {!WebInspector.ProfileHeader}
656 */ 670 */
657 createProfileLoadedFromFile: function(title) 671 createProfileLoadedFromFile: function(title)
658 { 672 {
659 return new WebInspector.CPUProfileHeader(null, this, title); 673 return new WebInspector.CPUProfileHeader(null, this, title);
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 _notifyTempFileReady: function() 901 _notifyTempFileReady: function()
888 { 902 {
889 if (this._onTempFileReady) { 903 if (this._onTempFileReady) {
890 this._onTempFileReady(); 904 this._onTempFileReady();
891 this._onTempFileReady = null; 905 this._onTempFileReady = null;
892 } 906 }
893 }, 907 },
894 908
895 __proto__: WebInspector.ProfileHeader.prototype 909 __proto__: WebInspector.ProfileHeader.prototype
896 } 910 }
OLDNEW
« no previous file with comments | « no previous file | Source/devtools/front_end/sdk/CPUProfilerModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698