[JSC] Add samplingProfilerIgnoreExternalSourceID option
https://bugs.webkit.org/show_bug.cgi?id=227985

Reviewed by Mark Lam.

We can ignore sourceID when aggregating samples. By doing so, we can open Speedometer2 style iframes
and still aggregate all the functions even though each script in iframe has different source ID.

* runtime/OptionsList.h:
* runtime/SamplingProfiler.cpp:
(JSC::SamplingProfiler::StackFrame::sourceID):
(JSC::SamplingProfiler::reportTopFunctions):
* runtime/SamplingProfiler.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@279955 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/runtime/SamplingProfiler.cpp b/Source/JavaScriptCore/runtime/SamplingProfiler.cpp
index 44159e5..73db61c 100644
--- a/Source/JavaScriptCore/runtime/SamplingProfiler.cpp
+++ b/Source/JavaScriptCore/runtime/SamplingProfiler.cpp
@@ -905,16 +905,16 @@
     case FrameType::Host:
     case FrameType::C:
     case FrameType::Wasm:
-        return -1;
+        return internalSourceID;
 
     case FrameType::Executable:
         if (executable->isHostFunction())
-            return -1;
+            return internalSourceID;
 
         return static_cast<ScriptExecutable*>(executable)->sourceID();
     }
     RELEASE_ASSERT_NOT_REACHED();
-    return -1;
+    return internalSourceID;
 }
 
 String SamplingProfiler::StackFrame::url()
@@ -1052,7 +1052,12 @@
             hash = stream.toString();
         } else
             hash = "<nil>"_s;
-        auto frameDescription = makeString(frame.displayName(m_vm), '#', hash, ':', frame.sourceID());
+        intptr_t sourceID = frame.sourceID();
+        if (Options::samplingProfilerIgnoreExternalSourceID()) {
+            if (sourceID != internalSourceID)
+                sourceID = aggregatedExternalSourceID;
+        }
+        auto frameDescription = makeString(frame.displayName(m_vm), '#', hash, ':', sourceID);
         functionCounts.add(frameDescription, 0).iterator->value++;
         totalSamples++;
     }