Skip to content

Commit

Permalink
[UserTiming] Correct measure where start is undefined
Browse files Browse the repository at this point in the history
According to spec, if start is undefined for performance.measure(), 0 will be
used as the start time. However, the current implementation treats undefined as
"null".

This CL doesn't solve all the problems. For backward compatibility, L2 should
treat undefined passed to start/end as empty, null as a string 'null'. As a
temporary fix, we treat both null and undefined as undefined, which is safer
than as 'null'.

Bug: 876324

Change-Id: I7d74d6be9552d090ab7f28342be9a739017bf59b
Reviewed-on: https://chromium-review.googlesource.com/1180345
Commit-Queue: Liquan (Max) Gǔ <maxlg@chromium.org>
Reviewed-by: Yoav Weiss <yoav@yoav.ws>
Reviewed-by: Nicolás Peña Moreno <npm@chromium.org>
Reviewed-by: Paul Irish <paulirish@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585103}
  • Loading branch information
maxlgu authored and chromium-wpt-export-bot committed Aug 23, 2018
1 parent cd356d3 commit 5452599
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions user-timing/measure.html
Expand Up @@ -57,6 +57,18 @@
order: undefined,
found: false
},
{
name: "measure_no_start_end",
startMark: undefined,
endMark: "mark_end",
startTime: undefined,
duration: undefined,
entryType: "measure",
entryMatch: undefined,
order: undefined,
found: false
},
// intentional duplicate of the first measure, used to confirm names can be re-used
{
name: "measure_no_start_no_end",
startMark: undefined,
Expand All @@ -69,6 +81,8 @@
found: false
}
];
// the index of the duplicate "measure_no_start_no_end"
const duplicate_index = TEST_MEASURES.map(m=>m.name).lastIndexOf('measure_no_start_no_end');

setup({explicit_done: true});

Expand Down Expand Up @@ -150,9 +164,26 @@
scenario.startTime = startMarkValue;

// when endMark is provided to the measure() call, the value of the mark whose name is
// provided is used for the startMark
// provided is used for the endMark
scenario.duration = endMarkValue - startMarkValue;
}
else if (scenario.startMark == undefined && scenario.endMark != undefined)
{
// endMark is defined but startMark is undefined, provide both parameters
window.performance.measure(scenario.name, scenario.startMark, scenario.endMark);

// when startMark isn't provided to the measure() call, a DOMHighResTimeStamp corresponding
// to the navigationStart attribute with a timebase of the same attribute is used; this is
// equivalent to 0
scenario.startTime = 0;

// when endMark is provided to the measure() call, the value of the mark whose name is
// provided is used for the endMark
scenario.duration = endMarkValue;
} else
{
test_true(false, 'Test measure scenario unhandled');
}
}

// test that expected measures are returned by getEntriesByName
Expand All @@ -162,23 +193,23 @@
// for all test measures, the test will be validate the test measure against the first entry returned
// by getEntriesByName(), except for the last measure, where since it is a duplicate measure, the test
// will validate it against the second entry returned by getEntriesByName()
test_measure(entries[(i == 3 ? 1 : 0)],
test_measure(entries[(i == duplicate_index ? 1 : 0)],
"window.performance.getEntriesByName(\"" + TEST_MEASURES[i].name + "\")[" +
(i == 3 ? 1 : 0) + "]",
(i == duplicate_index ? 1 : 0) + "]",
TEST_MEASURES[i].name,
TEST_MEASURES[i].startTime,
TEST_MEASURES[i].duration);
TEST_MEASURES[i].entryMatch = entries[(i == 3 ? 1 : 0)];
TEST_MEASURES[i].entryMatch = entries[(i == duplicate_index ? 1 : 0)];
}

// test that expected measures are returned by getEntriesByName with the entryType parameter provided
for (var i in TEST_MEASURES)
{
entries = window.performance.getEntriesByName(TEST_MEASURES[i].name, "measure");

test_true(match_entries(entries[(i == 3 ? 1 : 0)], TEST_MEASURES[i].entryMatch),
test_true(match_entries(entries[(i == duplicate_index ? 1 : 0)], TEST_MEASURES[i].entryMatch),
"window.performance.getEntriesByName(\"" + TEST_MEASURES[i].name + "\", \"measure\")[" +
(i == 3 ? 1 : 0) + "] returns an object containing the \"" + TEST_MEASURES[i].name +
(i == duplicate_index ? 1 : 0) + "] returns an object containing the \"" + TEST_MEASURES[i].name +
"\" measure in the correct order, and its value matches the \"" + TEST_MEASURES[i].name +
"\" measure returned by window.performance.getEntriesByName(\"" + TEST_MEASURES[i].name +
"\")");
Expand Down Expand Up @@ -260,7 +291,7 @@
measureEntryListCommand + " returns an object containing the \"" +
measureScenarios[i].name + "\" measure, and it's value matches the measure " +
"returned by window.performance.getEntriesByName(\"" + measureScenarios[i].name +
"\")[" + (i == 3 ? 1 : 0) + "].");
"\")[" + (i == duplicate_index ? 1 : 0) + "].");

measureEntryList[j].found = true;
measureScenarios[i].found = true;
Expand Down Expand Up @@ -318,6 +349,7 @@ <h1>Description</h1>
provided</li>
<li>"measure_start_no_end": created using a measure() call with only the startMark provided</li>
<li>"measure_start_end": created using a measure() call with both a startMark or endMark provided</li>
<li>"measure_no_start_end": created using a measure() call with only the endMark provided</li>
<li>"measure_no_start_no_end": duplicate of the first measure, used to confirm names can be re-used</li>
</ul>
After creating each measure, the existence of these measures is validated by calling
Expand Down

0 comments on commit 5452599

Please sign in to comment.