Created
November 14, 2016 21:12
-
-
Save gregtatum/5826cf542ae3d505319946d54920e70a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| clear() | |
| var profiler = Components.classes["@mozilla.org/tools/profiler;1"] | |
| .getService(Components.interfaces.nsIProfiler); | |
| var settings = { | |
| entries: 1000000, | |
| interval: 0.4, | |
| features: ["js", "stackwalk", "threads", "leaf"], | |
| threads: ["GeckoMain", "Compositor"] | |
| } | |
| profiler.StartProfiler( | |
| settings.entries, | |
| settings.interval, | |
| settings.features, | |
| settings.features.length, | |
| settings.threads, | |
| settings.threads.length | |
| ); | |
| var data, samples | |
| setTimeout(() => { | |
| console.log("getProfile", JSON.parse(profiler.GetProfile())); | |
| data = profiler.getProfileData(); | |
| data.libs = JSON.parse(data.libs); | |
| console.log(data) | |
| profiler.StopProfiler(); | |
| filledThreads = data.threads.map(thread => { | |
| const frameTable = applySchema(thread.frameTable) | |
| frameTable.forEach(stringTableApplier(thread.stringTable, "location")) | |
| frameTable.forEach(stringTableApplier(thread.stringTable, "implementation")); | |
| const stackTable = applySchema(thread.stackTable); | |
| const samples = applySchema(thread.samples) //.map(stackApplier(stackTable)); | |
| const markers = applySchema(thread.markers); | |
| return Object.assign({}, thread, {frameTable, stackTable, samples, markers}); | |
| }) | |
| console.log(filledThreads); | |
| }, 1000); | |
| // Mutates the object by applying the string table. | |
| function stringTableApplier (stringTable, key) { | |
| return (obj) => { | |
| const stringTableIndex = obj[key]; | |
| if (stringTableIndex >= 0) { | |
| obj[key] = stringTable[stringTableIndex]; | |
| } | |
| } | |
| } | |
| function schemaFiller (schema) { | |
| const schemaLookup = []; | |
| for (let key in schema) { | |
| if (schema.hasOwnProperty(key)) { | |
| const index = schema[key] | |
| schemaLookup[index] = key; | |
| } | |
| } | |
| return tuple => { | |
| return tuple.reduce((obj, value, i) => { | |
| obj[schemaLookup[i]] = value; | |
| return obj; | |
| }, {}) | |
| } | |
| } | |
| function applySchema ({schema, data}) { | |
| const fillSchema = schemaFiller(schema) | |
| return data.map(fillSchema) | |
| } | |
| /* | |
| const CATEGORY_MAPPINGS = { | |
| // js::ProfileEntry::Category::OTHER | |
| "16": CATEGORIES[0], | |
| // js::ProfileEntry::Category::CSS | |
| "32": CATEGORIES[1], | |
| // js::ProfileEntry::Category::JS | |
| "64": CATEGORIES[2], | |
| // js::ProfileEntry::Category::GC | |
| "128": CATEGORIES[3], | |
| // js::ProfileEntry::Category::CC | |
| "256": CATEGORIES[3], | |
| // js::ProfileEntry::Category::NETWORK | |
| "512": CATEGORIES[4], | |
| // js::ProfileEntry::Category::GRAPHICS | |
| "1024": CATEGORIES[5], | |
| // js::ProfileEntry::Category::STORAGE | |
| "2048": CATEGORIES[6], | |
| // js::ProfileEntry::Category::EVENTS | |
| "4096": CATEGORIES[7], | |
| // non-bitmasks for specially-assigned categories | |
| "9000": CATEGORIES[8], | |
| }; | |
| function applyCategores () { | |
| } | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment