2010-05-03 Abhishek Arya <inferno@chromium.org>
[WebKit-https.git] / LayoutTests / inspector / timeline-test.js
index 7d040fc..6e50b35 100644 (file)
@@ -1,45 +1,69 @@
-// Used to mark timeline records as belonging to the test framework.
-var timelineOverheadMark = "***Overhead***";
-
-// TimelineAgent record type definitions from the inspector
 var timelineAgentRecordType = {};
 
 // Scrub values when printing out these properties in the record or data field.
 var timelineNonDeterministicProps = { 
     children : 1,
     endTime : 1, 
+    height : 1,
+    identifier : 1,
     startTime : 1,
-    url : 1
+    width : 1,
+    callerScriptName: 1,
+    callerScriptLine: 1,
+    callerFunctionName: 1,
+    url : 1,
+    usedHeapSize: 1,
+    totalHeapSize: 1,
+    mimeType : 1
 };
 
-// Call this function from the doit() function in the main test page.
-// Pass a function that will get an array of timeline data to process.
-function retrieveTimelineData(analyzeFunction)
+function printTimelineRecords(performActions, typeName, formatter)
 {
+    if (performActions) {
+        if (window.layoutTestController)
+            layoutTestController.setTimelineProfilingEnabled(true);
+        performActions();
+    }
+
     evaluateInWebInspector("WebInspector.TimelineAgent.RecordType", function(result) {
         timelineAgentRecordType = result;
     });
 
-    evaluateInWebInspector("frontend_getTimelineResults()", function(timelineRecords) {
-        if (typeof(timelineRecords) === "string")
-            output("Error fetching Timeline results: " + timelineRecords);
-        else 
-            analyzeFunction(timelineRecords);
-        notifyDone();
+    evaluateInWebInspector("frontend_getTimelineResults", function(timelineRecords) {
+        try {
+            if (typeof(timelineRecords) === "string")
+                output("Error fetching Timeline results: " + timelineRecords);
+            else {
+                for (var i = 0; i < timelineRecords.length; ++i) {
+                    var record = timelineRecords[i];
+                    if (typeName && record.type === timelineAgentRecordType[typeName])
+                        printTimelineRecordProperties(record);
+                    if (formatter)
+                        formatter(record);
+                }
+            }
+            if (window.layoutTestController)
+                layoutTestController.setTimelineProfilingEnabled(false);
+            notifyDone();
+        } catch (e) {
+            console.log("An exception was caught: " + e.toString());
+            notifyDone(e.toString());
+        }
     });
-    markTimelineRecordAsOverhead("onload" + (ignoreLoad ? ":ignoreLoad": ""));
 }
 
 // Dump just the record name, indenting output on separate lines for subrecords
 function dumpTimelineRecord(record, level) 
 {
+    if (typeof level !== "number")
+        level = 0;
     var prefix = "";
     var suffix = "";
     for (var i = 0; i < level ; ++i)
         prefix = "----" + prefix;
     if (level > 0)
         prefix = prefix + "> ";
-    if (record.type == timelineAgentRecordType.MarkTimeline) {
+    if (record.type === timelineAgentRecordType.MarkTimeline) {
         suffix = " : " + record.data.message;
     }
     output(prefix + timelineAgentTypeToString(record.type) + suffix);
@@ -49,18 +73,11 @@ function dumpTimelineRecord(record, level)
         dumpTimelineRecord(record.children[i], level + 1);
 }
 
-// Dumps an entire list of records, culling out those marked as overhead
 function dumpTimelineRecords(timelineRecords) {
-    var numRecords = timelineRecords.length;
-    for (var i = 0; i < numRecords; ++i) {
-        var record = timelineRecords[i];
-        if (!isTimelineOverheadRecord(record))
-            dumpTimelineRecord(record, 0);
-    }
+    for (var i = 0; i < timelineRecords.length; ++i)
+        dumpTimelineRecord(timelineRecords[i], 0);
 }
 
-// Sort the fields, then strip out startTime and endTime, they are not deterministic.
-// Also remove children - that field isn't important for the printout.
 function printTimelineRecordProperties(record)
 {
     output(timelineAgentTypeToString(record.type) + " Properties:");
@@ -75,7 +92,7 @@ function isNonDeterministicProp(propName)
     return false;
 }
 
-function printProps (record, level)
+function printProps(record, level)
 {
     var props = new Array();
     for (var prop in record) {
@@ -102,55 +119,27 @@ function printProps (record, level)
     }
 }
 
-// Records that have been marked with console.markTimeline(timelineMark)
-// are a part of the test framework and not a part of the test being performed
-function isTimelineOverheadRecord(record) {
-    if (record.type === 11 && record.data.message.indexOf(timelineOverheadMark) !== -1)
-        return true;
-    var numChildren = record.children ?  record.children.length : 0;
-    for (var i = 0; i < numChildren; ++i) {
-        if (isTimelineOverheadRecord(record.children[i]))
-            return true;
-    }
-    return false;
-}
-
-// This mark will help the test analysis cull out records that are overhead.
-function markTimelineRecordAsOverhead(arg)
-{
-    var suffix = '';
-    if (arg)
-        suffix = ": " + arg;
-    console.markTimeline(timelineOverheadMark + suffix);
-}
-
 function timelineAgentTypeToString(numericType)
 {
     for (var prop in timelineAgentRecordType) {
-        if (timelineAgentRecordType[prop] == numericType)
+        if (timelineAgentRecordType[prop] === numericType)
             return prop;
     }
     return undefined;
 }
 
 // Injected into Inspector window
-function frontend_startTimelineProfiler()
-{
-    window.timelineResults = new Array();
-    window.WebInspector.addRecordToTimeline = function(arg) {
-        window.timelineResults.push(arg);
-    };
-    window.InspectorController.startTimelineProfiler();
-    return 'done';
-}
-
-// Injected into Inspector window
 function frontend_getTimelineResults() {
-    return window.timelineResults;
-}
-
-// Injected into Inspector window
-// frontend_setup always gets called before the page is reloaded.
-function frontend_setup() {
-    frontend_startTimelineProfiler();
+    var result = [];
+    function addRecords(records)
+    {
+        if (!records)
+            return;
+        for (var i = 0; i < records.length; ++i) {
+            result.push(records[i].originalRecordForTests);
+            addRecords(records[i].children);
+        }
+    }
+    addRecords(WebInspector.panels.timeline._rootRecord.children);
+    return result;
 }