Skip to content

Commit

Permalink
Log timer identifiers in systrace
Browse files Browse the repository at this point in the history
Reviewed By: davidaurelio

Differential Revision: D3819518

fbshipit-source-id: 98e9ed4af93c9c02f4bb8d9152b19556566b81f1
  • Loading branch information
javache authored and Facebook Github Bot 4 committed Sep 6, 2016
1 parent 66ce129 commit a1f31d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Libraries/JavaScriptAppEngine/System/JSTimers/JSTimers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// in dependencies. NativeModules > BatchedBridge > MessageQueue > JSTimersExecution
const RCTTiming = require('NativeModules').Timing;
const JSTimersExecution = require('JSTimersExecution');
const parseErrorStack = require('parseErrorStack');

// Returns a free index if one is available, and the next consecutive index otherwise.
function _getFreeIndex(): number {
Expand All @@ -31,6 +32,14 @@ function _allocateCallback(func: Function, type: $Keys<typeof JSTimersExecution.
JSTimersExecution.timerIDs[freeIndex] = id;
JSTimersExecution.callbacks[freeIndex] = func;
JSTimersExecution.types[freeIndex] = type;
if (__DEV__) {
const e = (new Error() : any);
e.framesToPop = 1;
const stack = parseErrorStack(e);
if (stack) {
JSTimersExecution.identifiers[freeIndex] = stack.shift();
}
}
return id;
}

Expand Down
11 changes: 11 additions & 0 deletions Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const JSTimersExecution = {
timerIDs: [],
immediates: [],
requestIdleCallbacks: [],
identifiers: ([] : [{methodName: string}]),

errors: (null : ?[Error]),

Expand Down Expand Up @@ -78,6 +79,11 @@ const JSTimersExecution = {
return;
}

if (__DEV__) {
const identifier = JSTimersExecution.identifiers[timerIndex] || {};
Systrace.beginEvent('Systrace.callTimer: ' + identifier.methodName);
}

// Clear the metadata
if (type === JSTimersExecution.Type.setTimeout ||
type === JSTimersExecution.Type.setImmediate ||
Expand Down Expand Up @@ -113,6 +119,10 @@ const JSTimersExecution = {
JSTimersExecution.errors.push(e);
}
}

if (__DEV__) {
Systrace.endEvent();
}
},

/**
Expand Down Expand Up @@ -228,6 +238,7 @@ const JSTimersExecution = {
JSTimersExecution.timerIDs[i] = null;
JSTimersExecution.callbacks[i] = null;
JSTimersExecution.types[i] = null;
JSTimersExecution.identifiers[i] = null;
},
};

Expand Down

0 comments on commit a1f31d1

Please sign in to comment.