Bug 1214867 - Add HeapSnapshot.prototype.creationTime; r=bholley

This commit is contained in:
Nick Fitzgerald 2015-10-20 10:55:49 +05:30
parent 10c27956bd
commit a74e3db448
4 changed files with 46 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#include "mozilla/ErrorResult.h"
#include "mozilla/devtools/DeserializedNode.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/Nullable.h"
#include "mozilla/HashFunctions.h"
#include "mozilla/Maybe.h"
#include "mozilla/RefCounted.h"
@ -139,6 +140,15 @@ public:
void TakeCensus(JSContext* cx, JS::HandleObject options,
JS::MutableHandleValue rval, ErrorResult& rv);
dom::Nullable<uint64_t> GetCreationTime() {
static const uint64_t maxTime = uint64_t(1) << 53;
if (timestamp.isSome() && timestamp.ref() <= maxTime) {
return dom::Nullable<uint64_t>(timestamp.ref());
}
return dom::Nullable<uint64_t>();
}
};
// A `CoreDumpWriter` is given the data we wish to save in a core dump and

View File

@ -0,0 +1,29 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// HeapSnapshot.prototype.creationTime returns the expected time.
function waitForTenMilliseconds() {
const start = Date.now();
while (Date.now() - start < 10) ;
}
function run_test() {
const start = Date.now() * 1000;
do_print("start = " + start);
// Because Date.now() is less precise than the snapshot's time stamp, give it
// a little bit of head room.
waitForTenMilliseconds();
const path = ChromeUtils.saveHeapSnapshot({ runtime: true });
waitForTenMilliseconds();
const end = Date.now() * 1000;
do_print("end = " + end);
const snapshot = ChromeUtils.readHeapSnapshot(path);
do_print("snapshot.creationTime = " + snapshot.creationTime);
ok(snapshot.creationTime >= start);
ok(snapshot.creationTime <= end);
}

View File

@ -25,6 +25,7 @@ support-files =
[test_HeapAnalyses_takeCensus_03.js]
[test_HeapAnalyses_takeCensus_04.js]
[test_HeapAnalyses_takeCensus_05.js]
[test_HeapSnapshot_creationTime_01.js]
[test_HeapSnapshot_takeCensus_01.js]
[test_HeapSnapshot_takeCensus_02.js]
[test_HeapSnapshot_takeCensus_03.js]

View File

@ -9,6 +9,12 @@
*/
[ChromeOnly, Exposed=(Window,System,Worker)]
interface HeapSnapshot {
/**
* A time stamp of when the heap snapshot was taken, if available. Units are
* microseconds since midnight (00:00:00) 1 January 1970 UTC.
*/
readonly attribute unsigned long long? creationTime;
/**
* Take a census of the heap snapshot.
*