Bug 1590115 - Add getSymbolsFromThisBrowser back r=canaltinova

This function is used in several locations and at least two files, so
it's useful to have it exist as a named and exported function.

Differential Revision: https://phabricator.services.mozilla.com/D49945

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Julien Wajsberg 2019-10-21 17:00:28 +00:00
Родитель 74ec329cc9
Коммит efcb99116b
1 изменённых файлов: 45 добавлений и 41 удалений

Просмотреть файл

@ -83,6 +83,49 @@ const lazyReceiveProfile = requireLazy(() => {
return browserModule.receiveProfile;
});
/**
* This Map caches the symbols from the shared libraries.
* @type {Map<string, { path: string, debugPath: string }>}
*/
const symbolCache = new Map();
async function getSymbolsFromThisBrowser(debugName, breakpadId) {
if (symbolCache.size === 0) {
// Prime the symbols cache.
for (const lib of Services.profiler.sharedLibraries) {
symbolCache.set(`${lib.debugName}/${lib.breakpadId}`, {
path: lib.path,
debugPath: lib.debugPath,
});
}
}
const cachedLibInfo = symbolCache.get(`${debugName}/${breakpadId}`);
if (!cachedLibInfo) {
throw new Error(
`The library ${debugName} ${breakpadId} is not in the ` +
"Services.profiler.sharedLibraries list, so the local path for it is not known " +
"and symbols for it can not be obtained. This usually happens if a content " +
"process uses a library that's not used in the parent process - " +
"Services.profiler.sharedLibraries only knows about libraries in the " +
"parent process."
);
}
const { path, debugPath } = cachedLibInfo;
const { OS } = lazyOS();
if (!OS.Path.split(path).absolute) {
throw new Error(
"Services.profiler.sharedLibraries did not contain an absolute path for " +
`the library ${debugName} ${breakpadId}, so symbols for this library can not ` +
"be obtained."
);
}
const { ProfilerGetSymbols } = lazyProfilerGetSymbols();
return ProfilerGetSymbols.getSymbolTable(path, debugPath, breakpadId);
}
/**
* @type {() => Promise<void>}
*/
@ -104,48 +147,8 @@ async function captureProfile() {
}
);
// This Map caches the symbols from the shared libraries.
const _symbolCache = new Map();
const receiveProfile = lazyReceiveProfile();
receiveProfile(profile, async function getSymbols(debugName, breakpadId) {
if (_symbolCache.size === 0) {
// Prime the symbols cache.
for (const lib of Services.profiler.sharedLibraries) {
_symbolCache.set(`${lib.debugName}/${lib.breakpadId}`, {
path: lib.path,
debugPath: lib.debugPath,
});
}
}
const cachedLibInfo = _symbolCache.get(`${debugName}/${breakpadId}`);
if (!cachedLibInfo) {
throw new Error(
`The library ${debugName} ${breakpadId} is not in the ` +
"Services.profiler.sharedLibraries list, so the local path for it is not known " +
"and symbols for it can not be obtained. This usually happens if a content " +
"process uses a library that's not used in the parent process - " +
"Services.profiler.sharedLibraries only knows about libraries in the " +
"parent process."
);
}
const { path, debugPath } = cachedLibInfo;
const { OS } = lazyOS();
if (!OS.Path.split(path).absolute) {
throw new Error(
"Services.profiler.sharedLibraries did not contain an absolute path for " +
`the library ${debugName} ${breakpadId}, so symbols for this library can not ` +
"be obtained."
);
}
const { ProfilerGetSymbols } = lazyProfilerGetSymbols();
return ProfilerGetSymbols.getSymbolTable(path, debugPath, breakpadId);
});
receiveProfile(profile, getSymbolsFromThisBrowser);
Services.profiler.StopProfiler();
}
@ -346,6 +349,7 @@ var EXPORTED_SYMBOLS = [
"restartProfiler",
"toggleProfiler",
"platform",
"getSymbolsFromThisBrowser",
"getDefaultRecordingSettings",
"getRecordingPreferencesFromBrowser",
"setRecordingPreferencesOnBrowser",