Changeset 143580 in webkit


Ignore:
Timestamp:
Feb 21, 2013 3:39:17 AM (11 years ago)
Author:
eustas@chromium.org
Message:

Web Inspector: [Console] Add console API message types for profile/profileEnd.
https://bugs.webkit.org/show_bug.cgi?id=109790

Reviewed by Pavel Feldman.

With profile/profileEnd message types we will gain more control over
output messages.

  • English.lproj/localizedStrings.js: Added corresponging strings.
  • inspector/ConsoleAPITypes.h: Added enum members.
  • inspector/Inspector.json: Ditto.
  • inspector/front-end/ConsoleModel.js: Ditto.
  • inspector/ConsoleMessage.cpp:

(WebCore::messageTypeValue): Added cases.

  • inspector/InspectorProfilerAgent.cpp: Adopted changes.
  • inspector/front-end/inspector.js: Ditto.
  • inspector/front-end/ConsoleMessage.js:

Added message generators for introduced message types.

  • inspector/front-end/ProfilesPanel.js:

Turned showProfileForURL(url) to showProfile(typeId, uid).

  • inspector/front-end/ProfilesPanelDescriptor.js:

(WebInspector.ProfilesPanelDescriptor.resolveProfileTitle): Added.

  • inspector/front-end/ResourceUtils.js: Removed linkifier plugins.
Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/inspector/profiler/canvas2d/canvas-replay-log-grid.html

    r143324 r143580  
    5656    {
    5757        profileHeader = profilesPanel.getProfiles(WebInspector.CanvasProfileType.TypeId)[0];
    58         profilesPanel.showProfile(profileHeader);
     58        profilesPanel._showProfile(profileHeader);
    5959        InspectorTest.addSniffer(profileHeader, "_updateCapturingStatus", didReceiveFirstFrame);
    6060        InspectorTest.evaluateInConsole("doSomeCanvasCalls(2)");
  • trunk/LayoutTests/inspector/profiler/heap-snapshot-inspect-dom-wrapper.html

    r142460 r143580  
    2020    {
    2121        var profiles = WebInspector.panels.profiles.getProfiles("HEAP");
    22         WebInspector.panels.profiles.showProfile(profiles[profiles.length - 1]);
     22        WebInspector.panels.profiles._showProfile(profiles[profiles.length - 1]);
    2323        InspectorTest.addSniffer(WebInspector.panels.profiles, "_finishHeapSnapshot", step1);
    2424    }
  • trunk/LayoutTests/inspector/profiler/heap-snapshot-loader.html

    r142460 r143580  
    4646
    4747        InspectorTest.override(HeapProfilerAgent, "getHeapSnapshot", getHeapSnapshotMock);
    48         panel.showProfile(profileHeader);
     48        panel._showProfile(profileHeader);
    4949    }
    5050
  • trunk/LayoutTests/inspector/profiler/heap-snapshot-test.js

    r143159 r143580  
    739739    InspectorTest._takeAndOpenSnapshotCallback = callback;
    740740    WebInspector.panels.profiles.addProfileHeader(profile);
    741     WebInspector.panels.profiles.showProfile(profile);
     741    WebInspector.panels.profiles._showProfile(profile);
    742742};
    743743
  • trunk/LayoutTests/inspector/profiler/profiler-test.js

    r103803 r143580  
    6767{
    6868    if (InspectorTest._showProfileWhenAdded === profile.title) {
    69         WebInspector.panels.profiles.showProfile(profile);
     69        WebInspector.panels.profiles._showProfile(profile);
    7070    }
    7171};
  • trunk/PerformanceTests/inspector/heap-snapshot-performance-test.js

    r142460 r143580  
    3535            transferTimerCookie = timer.start("transfer-snapshot");
    3636            var profiles = WebInspector.panels.profiles.getProfiles("HEAP");
    37             WebInspector.panels.profiles.showProfile(profiles[profiles.length - 1]);
     37            WebInspector.panels.profiles._showProfile(profiles[profiles.length - 1]);
    3838            InspectorTest.addSniffer(WebInspector.panels.profiles, "_finishHeapSnapshot", step1);
    3939        }
  • trunk/Source/WebCore/ChangeLog

    r143578 r143580  
     12013-02-19  Eugene Klyuchnikov  <eustas@chromium.org>
     2
     3        Web Inspector: [Console] Add console API message types for profile/profileEnd.
     4        https://bugs.webkit.org/show_bug.cgi?id=109790
     5
     6        Reviewed by Pavel Feldman.
     7
     8        With profile/profileEnd message types we will gain more control over
     9        output messages.
     10
     11        * English.lproj/localizedStrings.js: Added corresponging strings.
     12        * inspector/ConsoleAPITypes.h: Added enum members.
     13        * inspector/Inspector.json: Ditto.
     14        * inspector/front-end/ConsoleModel.js: Ditto.
     15        * inspector/ConsoleMessage.cpp:
     16        (WebCore::messageTypeValue): Added cases.
     17        * inspector/InspectorProfilerAgent.cpp: Adopted changes.
     18        * inspector/front-end/inspector.js: Ditto.
     19        * inspector/front-end/ConsoleMessage.js:
     20        Added message generators for introduced message types.
     21        * inspector/front-end/ProfilesPanel.js:
     22        Turned showProfileForURL(url) to showProfile(typeId, uid).
     23        * inspector/front-end/ProfilesPanelDescriptor.js:
     24        (WebInspector.ProfilesPanelDescriptor.resolveProfileTitle): Added.
     25        * inspector/front-end/ResourceUtils.js: Removed linkifier plugins.
     26
    1272013-02-21  Tamas Czene  <tczene@inf.u-szeged.hu>
    228
  • trunk/Source/WebCore/English.lproj/localizedStrings.js

    r143573 r143580  
    312312localizedStrings["Pausing"] = "Pausing";
    313313localizedStrings["Preview"] = "Preview";
     314localizedStrings["Profile '%s' started."] = "Profile '%s' started.";
     315localizedStrings["Profile '%s' finished."] = "Profile '%s' finished.";
    314316localizedStrings["Profiles"] = "Profiles";
    315317localizedStrings["Profiling disabled. Click to enable."] = "Profiling disabled. Click to enable.";
  • trunk/Source/WebCore/inspector/ConsoleAPITypes.h

    r143186 r143580  
    3939    ClearMessageType,
    4040    AssertMessageType,
    41     TimingMessageType
     41    TimingMessageType,
     42    ProfileMessageType,
     43    ProfileEndMessageType
    4244};
    4345
  • trunk/Source/WebCore/inspector/ConsoleMessage.cpp

    r143186 r143580  
    162162    case AssertMessageType: return TypeBuilder::Console::ConsoleMessage::Type::Assert;
    163163    case TimingMessageType: return TypeBuilder::Console::ConsoleMessage::Type::Timing;
     164    case ProfileMessageType: return TypeBuilder::Console::ConsoleMessage::Type::Profile;
     165    case ProfileEndMessageType: return TypeBuilder::Console::ConsoleMessage::Type::ProfileEnd;
    164166    }
    165167    return TypeBuilder::Console::ConsoleMessage::Type::Log;
  • trunk/Source/WebCore/inspector/Inspector.json

    r143574 r143580  
    772772                    { "name": "level", "type": "string", "enum": ["tip", "log", "warning", "error", "debug"], "description": "Message severity." },
    773773                    { "name": "text", "type": "string", "description": "Message text." },
    774                     { "name": "type", "type": "string", "optional": true, "enum": ["log", "dir", "dirxml", "table", "trace", "clear", "startGroup", "startGroupCollapsed", "endGroup", "assert", "timing"], "description": "Console message type." },
     774                    { "name": "type", "type": "string", "optional": true, "enum": ["log", "dir", "dirxml", "table", "trace", "clear", "startGroup", "startGroupCollapsed", "endGroup", "assert", "timing", "profile", "profileEnd"], "description": "Console message type." },
    775775                    { "name": "url", "type": "string", "optional": true, "description": "URL of the message origin." },
    776776                    { "name": "line", "type": "integer", "optional": true, "description": "Line number in the resource that generated this message." },
     
    34903490                    { "name": "result", "$ref": "CallArgument", "optional": true },
    34913491                    { "name": "isDrawingCall", "type": "boolean", "optional": true },
    3492                     { "name": "isFrameEndCall", "type": "boolean", "optional": true },
    34933492                    { "name": "property", "type": "string", "optional": true },
    34943493                    { "name": "value", "$ref": "CallArgument", "optional": true },
  • trunk/Source/WebCore/inspector/InspectorProfilerAgent.cpp

    r143449 r143580  
    165165        return;
    166166    RefPtr<ScriptProfile> profile = prpProfile;
    167     String title = profile->title();
    168     String message = makeString("Profile \"webkit-profile://", CPUProfileType, '/', encodeWithURLEscapeSequences(title), '#', String::number(profile->uid()), "\" finished.");
    169     m_consoleAgent->addMessageToConsole(ConsoleAPIMessageSource, LogMessageType, DebugMessageLevel, message, sourceURL, lineNumber);
     167    String message = makeString(profile->title(), '#', String::number(profile->uid()));
     168    m_consoleAgent->addMessageToConsole(ConsoleAPIMessageSource, ProfileEndMessageType, DebugMessageLevel, message, sourceURL, lineNumber);
    170169}
    171170
     
    174173    if (!m_frontend)
    175174        return;
    176     String message = makeString("Profile \"webkit-profile://", CPUProfileType, '/', encodeWithURLEscapeSequences(title), "#0\" started.");
    177     m_consoleAgent->addMessageToConsole(ConsoleAPIMessageSource, LogMessageType, DebugMessageLevel, message, sourceURL, lineNumber);
     175    m_consoleAgent->addMessageToConsole(ConsoleAPIMessageSource, ProfileMessageType, DebugMessageLevel, title, sourceURL, lineNumber);
    178176}
    179177
  • trunk/Source/WebCore/inspector/front-end/ConsoleMessage.js

    r143186 r143580  
    112112                    this._messageElement = this._format(args);
    113113                    break;
     114                case WebInspector.ConsoleMessage.MessageType.Profile:
     115                    var title = WebInspector.ProfilesPanelDescriptor.resolveProfileTitle(this._messageText);
     116                    this._messageElement = document.createTextNode(WebInspector.UIString("Profile '%s' started.", title));
     117                    break;
     118                case WebInspector.ConsoleMessage.MessageType.ProfileEnd:
     119                    var hashIndex = this._messageText.lastIndexOf("#");
     120                    var title = WebInspector.ProfilesPanelDescriptor.resolveProfileTitle(this._messageText.substring(0, hashIndex));
     121                    var uid = this._messageText.substring(hashIndex + 1);
     122                    var format = WebInspector.UIString("Profile '%s' finished.", "%_");
     123                    var link = WebInspector.linkifyURLAsNode("webkit-profile://CPU/" + uid, title);
     124                    this._messageElement = document.createElement("span");
     125                    this._formatWithSubstitutionString(format, [link], this._messageElement);
     126                    break;
    114127                default:
    115128                    var args = this._parameters || [this._messageText];
     
    248261        if (shouldFormatMessage) {
    249262            // Multiple parameters with the first being a format string. Save unused substitutions.
    250             var result = this._formatWithSubstitutionString(parameters, formattedResult);
     263            var result = this._formatWithSubstitutionString(parameters[0].description, parameters.slice(1), formattedResult);
    251264            parameters = result.unusedSubstitutions;
    252265            if (parameters.length)
     
    566579    },
    567580
    568     _formatWithSubstitutionString: function(parameters, formattedResult)
     581    _formatWithSubstitutionString: function(format, parameters, formattedResult)
    569582    {
    570583        var formatters = {};
     
    592605                return "NaN";
    593606            return Math.floor(obj.value);
     607        }
     608
     609        function bypassFormatter(obj)
     610        {
     611            return (obj instanceof Node) ? obj : "";
    594612        }
    595613
     
    630648        // Support %O to force object formatting, instead of the type-based %o formatting.
    631649        formatters.O = parameterFormatter.bind(this, true);
     650
     651        formatters._ = bypassFormatter;
    632652
    633653        function append(a, b)
     
    650670
    651671        // String.format does treat formattedResult like a Builder, result is an object.
    652         return String.format(parameters[0].description, parameters.slice(1), formatters, formattedResult, append);
     672        return String.format(format, parameters, formatters, formattedResult, append);
    653673    },
    654674
     
    821841                typeString = "Result";
    822842                break;
     843            case WebInspector.ConsoleMessage.MessageType.Profile:
     844            case WebInspector.ConsoleMessage.MessageType.ProfileEnd:
     845                typeString = "Profiling";
     846                break;
    823847        }
    824848
  • trunk/Source/WebCore/inspector/front-end/ConsoleModel.js

    r143186 r143580  
    238238    EndGroup: "endGroup",
    239239    Assert: "assert",
    240     Result: "result"
     240    Result: "result",
     241    Profile: "profile",
     242    ProfileEnd: "profileEnd"
    241243}
    242244
  • trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js

    r143159 r143580  
    603603        if (!profile.isTemporary) {
    604604            if (!this.visibleView)
    605                 this.showProfile(profile);
     605                this._showProfile(profile);
    606606            this.dispatchEventToListeners("profile added", {
    607607                type: typeId
     
    651651     * @param {WebInspector.ProfileHeader} profile
    652652     */
    653     showProfile: function(profile)
     653    _showProfile: function(profile)
    654654    {
    655655        if (!profile || profile.isTemporary)
     
    705705            // TODO: allow to choose snapshot if there are several options.
    706706            if (profile.maxJSObjectId >= snapshotObjectId) {
    707                 this.showProfile(profile);
     707                this._showProfile(profile);
    708708                profile.view().changeView(viewName, function() {
    709709                    profile.view().dataGrid.highlightObjectByHeapSnapshotId(snapshotObjectId);
     
    774774    showView: function(view)
    775775    {
    776         this.showProfile(view.profile);
     776        this._showProfile(view.profile);
    777777    },
    778778
     
    786786
    787787    /**
    788      * @param {string} url
    789      */
    790     showProfileForURL: function(url)
    791     {
    792         var match = url.match(WebInspector.ProfilesPanelDescriptor.ProfileURLRegExp);
    793         if (!match)
    794             return;
    795         this.showProfile(this._profilesIdMap[this._makeKey(Number(match[3]), match[1])]);
     788     * @param {string} typeId
     789     * @param {string} uid
     790     */
     791    showProfile: function(typeId, uid)
     792    {
     793        this._showProfile(this._profilesIdMap[this._makeKey(Number(uid), typeId)]);
    796794    },
    797795
     
    801799            this.visibleView.detach();
    802800        delete this.visibleView;
    803     },
    804 
    805     /**
    806      * @param {string} title
    807      * @param {string} typeId
    808      */
    809     displayTitleForProfileLink: function(title, typeId)
    810     {
    811         title = unescape(title);
    812         if (title.startsWith(UserInitiatedProfileName)) {
    813             title = WebInspector.UIString("Profile %d", title.substring(UserInitiatedProfileName.length + 1));
    814         } else {
    815             var titleKey = this._makeTitleKey(title, typeId);
    816             if (!(titleKey in this._profileGroupsForLinks))
    817                 this._profileGroupsForLinks[titleKey] = 0;
    818 
    819             var groupNumber = ++this._profileGroupsForLinks[titleKey];
    820 
    821             if (groupNumber > 2)
    822                 // The title is used in the console message announcing that a profile has started so it gets
    823                 // incremented twice as often as it's displayed
    824                 title += " " + WebInspector.UIString("Run %d", (groupNumber + 1) / 2);
    825         }
    826 
    827         return title;
    828801    },
    829802
     
    14081381    {
    14091382        if (!this._suppressOnSelect)
    1410             this.treeOutline.panel.showProfile(this.profile);
     1383            this.treeOutline.panel._showProfile(this.profile);
    14111384    },
    14121385
     
    14841457    {
    14851458        if (this.children.length > 0)
    1486             WebInspector.ProfilesPanel._instance.showProfile(this.children[this.children.length - 1].profile);
     1459            WebInspector.ProfilesPanel._instance._showProfile(this.children[this.children.length - 1].profile);
    14871460    },
    14881461
  • trunk/Source/WebCore/inspector/front-end/ProfilesPanelDescriptor.js

    r143159 r143580  
    6565    return parseInt(suffix, 10);
    6666}
     67
     68/**
     69 * @param {string} title
     70 * @return {string}
     71 */
     72WebInspector.ProfilesPanelDescriptor.resolveProfileTitle = function(title)
     73{
     74    if (!WebInspector.ProfilesPanelDescriptor.isUserInitiatedProfile(title))
     75        return title;
     76    return WebInspector.UIString("Profile %d", WebInspector.ProfilesPanelDescriptor.userInitiatedProfileIndex(title));
     77}
  • trunk/Source/WebCore/inspector/front-end/ResourceUtils.js

    r143448 r143580  
    124124}
    125125
    126 WebInspector._linkifierPlugins = [];
    127 
    128 /**
    129  * @param {function(string):string} plugin
    130  */
    131 WebInspector.registerLinkifierPlugin = function(plugin)
    132 {
    133     WebInspector._linkifierPlugins.push(plugin);
    134 }
    135 
    136126/**
    137127 * @param {string} string
     
    148138    function linkifier(title, url, lineNumber)
    149139    {
    150         for (var i = 0; i < WebInspector._linkifierPlugins.length; ++i)
    151             title = WebInspector._linkifierPlugins[i](title);
    152 
    153140        var isExternal = !WebInspector.resourceForURL(url);
    154141        var urlNode = WebInspector.linkifyURLAsNode(url, title, undefined, isExternal);
  • trunk/Source/WebCore/inspector/front-end/inspector.js

    r143448 r143580  
    273273    },
    274274
    275     _profilesLinkifier: function(title)
    276     {
    277         var profileStringMatches = WebInspector.ProfilesPanelDescriptor.ProfileURLRegExp.exec(title);
    278         if (profileStringMatches) {
    279             var profilesPanel = /** @ type {WebInspector.ProfilesPanel} */ WebInspector.panel("profiles");
    280             title = WebInspector.ProfilesPanel._instance.displayTitleForProfileLink(profileStringMatches[2], profileStringMatches[1]);
    281         }
    282         return title;
    283     },
    284 
    285275    _debuggerPaused: function()
    286276    {
     
    469459
    470460    this.addMainEventListeners(document);
    471     WebInspector.registerLinkifierPlugin(this._profilesLinkifier.bind(this));
    472461
    473462    window.addEventListener("resize", this.windowResize.bind(this), true);
     
    584573{
    585574    var anchor = event.target.enclosingNodeOrSelfWithNodeName("a");
    586     if (!anchor || (anchor.target === "_blank" && !WebInspector.ProfilesPanelDescriptor.ProfileURLRegExp.exec(anchor.href)))
     575    if (!anchor || (anchor.target === "_blank"))
    587576        return;
    588577
     
    597586        const profileMatch = WebInspector.ProfilesPanelDescriptor.ProfileURLRegExp.exec(anchor.href);
    598587        if (profileMatch) {
    599             WebInspector.showProfileForURL(anchor.href);
     588            WebInspector.showPanel("profiles").showProfile(profileMatch[1], profileMatch[2]);
    600589            return;
    601590        }
     
    985974}
    986975
    987 WebInspector.showProfileForURL = function(url)
    988 {
    989     WebInspector.showPanel("profiles").showProfileForURL(url);
    990 }
    991 
    992976WebInspector.evaluateInConsole = function(expression, showResultOnly)
    993977{
Note: See TracChangeset for help on using the changeset viewer.