[Profiling] Add span for decoding stacktraces (#143054)

This commit is contained in:
Dario Gieselaar 2022-10-11 15:25:39 +02:00 committed by GitHub
parent 9fce7b599d
commit 7ed94ad679
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -283,34 +283,38 @@ export async function mgetStackTraces({
const executableDocIDs = new Set<string>();
const t0 = Date.now();
// flatMap() is significantly slower than an explicit for loop
for (const res of stackResponses) {
for (const trace of res.docs) {
if ('error' in trace) {
continue;
}
// Sometimes we don't find the trace.
// This is due to ES delays writing (data is not immediately seen after write).
// Also, ES doesn't know about transactions.
if (trace.found) {
const traceid = trace._id as StackTraceID;
let stackTrace = traceLRU.get(traceid) as StackTrace;
if (!stackTrace) {
stackTrace = decodeStackTrace(trace._source as EncodedStackTrace);
traceLRU.set(traceid, stackTrace);
}
totalFrames += stackTrace.FrameIDs.length;
stackTraces.set(traceid, stackTrace);
for (const frameID of stackTrace.FrameIDs) {
stackFrameDocIDs.add(frameID);
await withProfilingSpan('decode_stacktraces', async () => {
// flatMap() is significantly slower than an explicit for loop
for (const res of stackResponses) {
for (const trace of res.docs) {
if ('error' in trace) {
continue;
}
for (const fileID of stackTrace.FileIDs) {
executableDocIDs.add(fileID);
// Sometimes we don't find the trace.
// This is due to ES delays writing (data is not immediately seen after write).
// Also, ES doesn't know about transactions.
if (trace.found) {
const traceid = trace._id as StackTraceID;
let stackTrace = traceLRU.get(traceid) as StackTrace;
if (!stackTrace) {
stackTrace = decodeStackTrace(trace._source as EncodedStackTrace);
traceLRU.set(traceid, stackTrace);
}
totalFrames += stackTrace.FrameIDs.length;
stackTraces.set(traceid, stackTrace);
for (const frameID of stackTrace.FrameIDs) {
stackFrameDocIDs.add(frameID);
}
for (const fileID of stackTrace.FileIDs) {
executableDocIDs.add(fileID);
}
}
}
}
}
});
logger.info(`processing data took ${Date.now() - t0} ms`);
if (stackTraces.size !== 0) {