Browse Source

fix(profiling): Reset is_search_result before drawing (#34032)

When rendering the flamegraph without search results, make sure to clear
is_search_result. It may contain a 1 from a previous earch result which can
cause every frame to be highlighted.
Tony Xiao 2 years ago
parent
commit
851bb2a4cd

+ 12 - 1
static/app/components/profiling/flamegraphSearch.tsx

@@ -30,11 +30,13 @@ function frameSearch(
   query: string,
   frames: ReadonlyArray<FlamegraphFrame>,
   index: Fuse<FlamegraphFrame>
-): Record<string, FlamegraphFrame> {
+): Record<string, FlamegraphFrame> | null {
   const results = {};
   if (isRegExpString(query)) {
     const [_, lookup, flags] = parseRegExp(query) ?? [];
 
+    let matches = 0;
+
     try {
       if (!lookup) {
         throw new Error('Invalid RegExp');
@@ -51,17 +53,26 @@ function frameSearch(
               String(frame.start)
             }`
           ] = frame;
+          matches += 1;
         }
       }
     } catch (e) {
       Sentry.captureMessage(e.message);
     }
 
+    if (matches <= 0) {
+      return null;
+    }
+
     return results;
   }
 
   const fuseResults = index.search(query);
 
+  if (fuseResults.length <= 0) {
+    return null;
+  }
+
   for (let i = 0; i < fuseResults.length; i++) {
     const frame = fuseResults[i];
 

+ 1 - 0
static/app/utils/profiling/renderers/flamegraphRenderer.tsx

@@ -609,6 +609,7 @@ class FlamegraphRenderer {
         this.gl.drawArrays(this.gl.TRIANGLES, vertexOffset, VERTICES);
       }
     } else {
+      this.gl.uniform1i(this.uniforms.u_is_search_result, 0);
       for (let i = 0; i < length; i++) {
         const vertexOffset = i * VERTICES;