Skip to content

Commit

Permalink
Change how to find the trace start event (#21)
Browse files Browse the repository at this point in the history
* feat(google_search_feature.js): change how to find the trace start event

* chore(google_search_features.js): remove trailing comma
  • Loading branch information
mkamakura authored and ebidel committed Dec 17, 2018
1 parent 93cf709 commit 850be1f
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion google_search_features.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async function collectFeatureTraceEvents(browser) {

// Filter out all trace events that aren't 1. blink feature usage
// and 2. from the same process/thread id as our test page's main thread.
const traceStartEvent = trace.traceEvents.find(e => e.name === 'TracingStartedInPage');
const traceStartEvent = findTraceStartEvent(trace.traceEvents);
const events = trace.traceEvents.filter(e => {
return e.cat === 'disabled-by-default-blink.feature_usage' &&
e.pid === traceStartEvent.pid && e.tid === traceStartEvent.tid;
Expand All @@ -207,6 +207,37 @@ async function collectFeatureTraceEvents(browser) {
return events;
}

/**
* @param {Array} events
* @return {Object}
*/
function findTraceStartEvent(events) {
const startedInBrowserEvt = events.find(e => e.name === 'TracingStartedInBrowser');
if (startedInBrowserEvt && startedInBrowserEvt.args.data && startedInBrowserEvt.args.data.frames) {
const mainFrame = startedInBrowserEvt.args.data.frames.find(frame => !frame.parent);
const pid = mainFrame && mainFrame.processId;
const threadNameEvt = events.find(e => e.pid === pid && e.ph === 'M' &&
e.cat === '__metadata' && e.name === 'thread_name' && e.args.name === 'CrRendererMain');

const tid = threadNameEvt && threadNameEvt.tid;
if (pid && tid) {
return {
pid,
tid
};
}
}

// // Support legacy browser versions
const startedInPageEvt = events.find(e => e.name === 'TracingStartedInPage');
if (startedInPageEvt && startedInPageEvt.args && startedInPageEvt.args.data) {
return {
pid: startedInPageEvt.pid,
tid: startedInPageEvt.tid
};
}
}

/**
* @param {!Object} feature
*/
Expand Down

0 comments on commit 850be1f

Please sign in to comment.