Make it easy to log compile times for all optimizing tiers
authorfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 May 2018 00:41:58 +0000 (00:41 +0000)
committerfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 May 2018 00:41:58 +0000 (00:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185270

Reviewed by Keith Miller.

This makes --logPhaseTimes=true enable logging of phase times for DFG and B3 using a common
helper class, CompilerTimingScope. This used to be called B3::TimingScope and only B3 used
it.

This should help us reduce compile times by telling us where to look. So, far, it looks like
CFA is the worst.

* JavaScriptCore.xcodeproj/project.pbxproj:
* Sources.txt:
* b3/B3Common.cpp:
(JSC::B3::shouldMeasurePhaseTiming): Deleted.
* b3/B3Common.h:
* b3/B3TimingScope.cpp: Removed.
* b3/B3TimingScope.h:
(JSC::B3::TimingScope::TimingScope):
* dfg/DFGPhase.h:
(JSC::DFG::runAndLog):
* dfg/DFGPlan.cpp:
(JSC::DFG::Plan::compileInThread):
* tools/CompilerTimingScope.cpp: Added.
(JSC::CompilerTimingScope::CompilerTimingScope):
(JSC::CompilerTimingScope::~CompilerTimingScope):
* tools/CompilerTimingScope.h: Added.
* runtime/Options.cpp:
(JSC::recomputeDependentOptions):
* runtime/Options.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@231338 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/Sources.txt
Source/JavaScriptCore/b3/B3Common.cpp
Source/JavaScriptCore/b3/B3Common.h
Source/JavaScriptCore/b3/B3TimingScope.h
Source/JavaScriptCore/dfg/DFGPhase.h
Source/JavaScriptCore/dfg/DFGPlan.cpp
Source/JavaScriptCore/runtime/Options.cpp
Source/JavaScriptCore/runtime/Options.h
Source/JavaScriptCore/tools/CompilerTimingScope.cpp [moved from Source/JavaScriptCore/b3/B3TimingScope.cpp with 58% similarity]
Source/JavaScriptCore/tools/CompilerTimingScope.h [new file with mode: 0644]

index 8fd11de..91c668c 100644 (file)
@@ -1,5 +1,39 @@
 2018-05-03  Filip Pizlo  <fpizlo@apple.com>
 
+        Make it easy to log compile times for all optimizing tiers
+        https://bugs.webkit.org/show_bug.cgi?id=185270
+
+        Reviewed by Keith Miller.
+        
+        This makes --logPhaseTimes=true enable logging of phase times for DFG and B3 using a common
+        helper class, CompilerTimingScope. This used to be called B3::TimingScope and only B3 used
+        it.
+        
+        This should help us reduce compile times by telling us where to look. So, far, it looks like
+        CFA is the worst.
+
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * Sources.txt:
+        * b3/B3Common.cpp:
+        (JSC::B3::shouldMeasurePhaseTiming): Deleted.
+        * b3/B3Common.h:
+        * b3/B3TimingScope.cpp: Removed.
+        * b3/B3TimingScope.h:
+        (JSC::B3::TimingScope::TimingScope):
+        * dfg/DFGPhase.h:
+        (JSC::DFG::runAndLog):
+        * dfg/DFGPlan.cpp:
+        (JSC::DFG::Plan::compileInThread):
+        * tools/CompilerTimingScope.cpp: Added.
+        (JSC::CompilerTimingScope::CompilerTimingScope):
+        (JSC::CompilerTimingScope::~CompilerTimingScope):
+        * tools/CompilerTimingScope.h: Added.
+        * runtime/Options.cpp:
+        (JSC::recomputeDependentOptions):
+        * runtime/Options.h:
+
+2018-05-03  Filip Pizlo  <fpizlo@apple.com>
+
         Strings should not be allocated in a gigacage
         https://bugs.webkit.org/show_bug.cgi?id=185218
 
index 9ac883a..3783fd3 100644 (file)
                0F4D8C751FC7A97D001D32AC /* ConstraintParallelism.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4D8C731FC7A974001D32AC /* ConstraintParallelism.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0F4D8C781FCA3CFA001D32AC /* SimpleMarkingConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4D8C771FCA3CF3001D32AC /* SimpleMarkingConstraint.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0F4DE1CF1C4C1B54004D6C11 /* AirFixObviousSpills.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4DE1CD1C4C1B54004D6C11 /* AirFixObviousSpills.h */; };
+               0F4F11E8209BCDAB00709654 /* CompilerTimingScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4F11E6209BCDA100709654 /* CompilerTimingScope.h */; };
                0F4F29E018B6AD1C0057BC15 /* DFGStaticExecutionCountEstimationPhase.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4F29DE18B6AD1C0057BC15 /* DFGStaticExecutionCountEstimationPhase.h */; };
                0F4F82881E2FFDE00075184C /* JSSegmentedVariableObjectHeapCellType.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4F82861E2FFDDB0075184C /* JSSegmentedVariableObjectHeapCellType.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0F4F828C1E31B9760075184C /* StochasticSpaceTimeMutatorScheduler.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F4F828A1E31B9710075184C /* StochasticSpaceTimeMutatorScheduler.h */; };
                0F4570371BE44C910062A629 /* AirEliminateDeadCode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AirEliminateDeadCode.h; path = b3/air/AirEliminateDeadCode.h; sourceTree = "<group>"; };
                0F45703A1BE45F0A0062A629 /* AirReportUsedRegisters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AirReportUsedRegisters.cpp; path = b3/air/AirReportUsedRegisters.cpp; sourceTree = "<group>"; };
                0F45703B1BE45F0A0062A629 /* AirReportUsedRegisters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AirReportUsedRegisters.h; path = b3/air/AirReportUsedRegisters.h; sourceTree = "<group>"; };
-               0F45703E1BE584CA0062A629 /* B3TimingScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3TimingScope.cpp; path = b3/B3TimingScope.cpp; sourceTree = "<group>"; };
                0F45703F1BE584CA0062A629 /* B3TimingScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = B3TimingScope.h; path = b3/B3TimingScope.h; sourceTree = "<group>"; };
                0F46807F14BA572700BFE272 /* JITExceptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JITExceptions.cpp; sourceTree = "<group>"; };
                0F46808014BA572700BFE272 /* JITExceptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JITExceptions.h; sourceTree = "<group>"; };
                0F4DE1CC1C4C1B54004D6C11 /* AirFixObviousSpills.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AirFixObviousSpills.cpp; path = b3/air/AirFixObviousSpills.cpp; sourceTree = "<group>"; };
                0F4DE1CD1C4C1B54004D6C11 /* AirFixObviousSpills.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AirFixObviousSpills.h; path = b3/air/AirFixObviousSpills.h; sourceTree = "<group>"; };
                0F4DE1D01C4D764B004D6C11 /* B3OriginDump.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = B3OriginDump.cpp; path = b3/B3OriginDump.cpp; sourceTree = "<group>"; };
+               0F4F11E6209BCDA100709654 /* CompilerTimingScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CompilerTimingScope.h; sourceTree = "<group>"; };
+               0F4F11E7209BCDA100709654 /* CompilerTimingScope.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CompilerTimingScope.cpp; sourceTree = "<group>"; };
                0F4F29DD18B6AD1C0057BC15 /* DFGStaticExecutionCountEstimationPhase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGStaticExecutionCountEstimationPhase.cpp; path = dfg/DFGStaticExecutionCountEstimationPhase.cpp; sourceTree = "<group>"; };
                0F4F29DE18B6AD1C0057BC15 /* DFGStaticExecutionCountEstimationPhase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGStaticExecutionCountEstimationPhase.h; path = dfg/DFGStaticExecutionCountEstimationPhase.h; sourceTree = "<group>"; };
                0F4F82851E2FFDDB0075184C /* JSSegmentedVariableObjectHeapCellType.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSegmentedVariableObjectHeapCellType.cpp; sourceTree = "<group>"; };
                                0FEC84EE1BDACDAC0080FF74 /* B3SwitchCase.h */,
                                0FEC84EF1BDACDAC0080FF74 /* B3SwitchValue.cpp */,
                                0FEC84F01BDACDAC0080FF74 /* B3SwitchValue.h */,
-                               0F45703E1BE584CA0062A629 /* B3TimingScope.cpp */,
                                0F45703F1BE584CA0062A629 /* B3TimingScope.h */,
                                0FEC84F11BDACDAC0080FF74 /* B3Type.cpp */,
                                0FEC84F21BDACDAC0080FF74 /* B3Type.h */,
                                E178633F0D9BEC0000D74E75 /* InitializeThreading.h */,
                                E35E035D1B7AB43E0073AD2A /* InspectorInstrumentationObject.cpp */,
                                E35E035E1B7AB43E0073AD2A /* InspectorInstrumentationObject.h */,
+                               A7A8AF2B17ADB5F3005AB174 /* Int8Array.h */,
                                A7A8AF2C17ADB5F3005AB174 /* Int16Array.h */,
                                A7A8AF2D17ADB5F3005AB174 /* Int32Array.h */,
-                               A7A8AF2B17ADB5F3005AB174 /* Int8Array.h */,
                                BC9BB95B0E19680600DF8855 /* InternalFunction.cpp */,
                                BC11667A0E199C05008066DD /* InternalFunction.h */,
                                A1B9E2331B4E0D6700BC7FED /* IntlCollator.cpp */,
                                BC756FC60E2031B200DE7D12 /* JSGlobalObjectFunctions.cpp */,
                                BC756FC70E2031B200DE7D12 /* JSGlobalObjectFunctions.h */,
                                79B819921DD25CF500DDC714 /* JSGlobalObjectInlines.h */,
+                               0F2B66C917B6B5AB00A7AE3F /* JSInt8Array.h */,
                                0F2B66CA17B6B5AB00A7AE3F /* JSInt16Array.h */,
                                0F2B66CB17B6B5AB00A7AE3F /* JSInt32Array.h */,
-                               0F2B66C917B6B5AB00A7AE3F /* JSInt8Array.h */,
                                E33F507E1B8429A400413856 /* JSInternalPromise.cpp */,
                                E33F507F1B8429A400413856 /* JSInternalPromise.h */,
                                E33F50761B84225700413856 /* JSInternalPromiseConstructor.cpp */,
                                53F256E11B87E28000B4B768 /* JSTypedArrayViewPrototype.cpp */,
                                53917E7C1B791106000EBD33 /* JSTypedArrayViewPrototype.h */,
                                6507D2970E871E4A00D7D896 /* JSTypeInfo.h */,
-                               0F2B66D417B6B5AB00A7AE3F /* JSUint16Array.h */,
-                               0F2B66D517B6B5AB00A7AE3F /* JSUint32Array.h */,
                                0F2B66D217B6B5AB00A7AE3F /* JSUint8Array.h */,
                                0F2B66D317B6B5AB00A7AE3F /* JSUint8ClampedArray.h */,
+                               0F2B66D417B6B5AB00A7AE3F /* JSUint16Array.h */,
+                               0F2B66D517B6B5AB00A7AE3F /* JSUint32Array.h */,
                                A7CA3AE117DA41AE006538AF /* JSWeakMap.cpp */,
                                A7CA3AE217DA41AE006538AF /* JSWeakMap.h */,
                                709FB8611AE335C60039D069 /* JSWeakSet.cpp */,
                                0F2D4DE019832D91007D4B19 /* TypeProfilerLog.h */,
                                0F2D4DE319832D91007D4B19 /* TypeSet.cpp */,
                                0F2D4DE419832D91007D4B19 /* TypeSet.h */,
+                               A7A8AF3017ADB5F3005AB174 /* Uint8Array.h */,
+                               A7A8AF3117ADB5F3005AB174 /* Uint8ClampedArray.h */,
                                A7A8AF3217ADB5F3005AB174 /* Uint16Array.h */,
                                866739D113BFDE710023D87C /* Uint16WithFraction.h */,
                                A7A8AF3317ADB5F3005AB174 /* Uint32Array.h */,
-                               A7A8AF3017ADB5F3005AB174 /* Uint8Array.h */,
-                               A7A8AF3117ADB5F3005AB174 /* Uint8ClampedArray.h */,
                                0FE050231AA9095600D33B33 /* VarOffset.cpp */,
                                0FE050241AA9095600D33B33 /* VarOffset.h */,
                                E18E3A570DF9278C00D90B34 /* VM.cpp */,
                                86B5822F14D2373B00A9C306 /* CodeProfile.h */,
                                8603CEF214C7546400AE59E3 /* CodeProfiling.cpp */,
                                8603CEF314C7546400AE59E3 /* CodeProfiling.h */,
+                               0F4F11E7209BCDA100709654 /* CompilerTimingScope.cpp */,
+                               0F4F11E6209BCDA100709654 /* CompilerTimingScope.h */,
                                FE4BFF291AD476E700088F87 /* FunctionOverrides.cpp */,
                                FE4BFF2A1AD476E700088F87 /* FunctionOverrides.h */,
                                FEA0C4001CDD7D0E00481991 /* FunctionWhitelist.cpp */,
                                0F2B66AC17B6B53F00A7AE3F /* GCIncomingRefCounted.h in Headers */,
                                0F2B66AD17B6B54500A7AE3F /* GCIncomingRefCountedInlines.h in Headers */,
                                0F2B66AE17B6B54500A7AE3F /* GCIncomingRefCountedSet.h in Headers */,
+                               0F4F11E8209BCDAB00709654 /* CompilerTimingScope.h in Headers */,
                                0F2B66AF17B6B54500A7AE3F /* GCIncomingRefCountedSetInlines.h in Headers */,
                                2AABCDE718EF294200002096 /* GCLogging.h in Headers */,
                                0F9715311EB28BEE00A1645D /* GCRequest.h in Headers */,
index 4c35ed6..5229f3b 100644 (file)
@@ -159,7 +159,6 @@ b3/B3StackmapValue.cpp
 b3/B3StackSlot.cpp
 b3/B3SwitchCase.cpp
 b3/B3SwitchValue.cpp
-b3/B3TimingScope.cpp
 b3/B3Type.cpp
 b3/B3UpsilonValue.cpp
 b3/B3UseCounts.cpp
@@ -708,6 +707,7 @@ runtime/CommonIdentifiers.cpp
 runtime/CommonSlowPaths.cpp
 runtime/CommonSlowPathsExceptions.cpp
 runtime/CompilationResult.cpp
+tools/CompilerTimingScope.cpp
 runtime/Completion.cpp
 runtime/ConfigFile.cpp
 runtime/ConsoleClient.cpp
index 06639c9..661020e 100644 (file)
@@ -65,11 +65,6 @@ bool shouldSaveIRBeforePhase()
     return Options::verboseValidationFailure();
 }
 
-bool shouldMeasurePhaseTiming()
-{
-    return Options::logB3PhaseTimes();
-}
-
 std::optional<GPRReg> pinnedExtendedOffsetAddrRegister()
 {
 #if CPU(ARM64)
index d17a204..d0d7dd3 100644 (file)
@@ -45,7 +45,6 @@ bool shouldDumpIRAtEachPhase(B3ComplitationMode);
 bool shouldValidateIR();
 bool shouldValidateIRAtEachPhase();
 bool shouldSaveIRBeforePhase();
-bool shouldMeasurePhaseTiming();
 
 template<typename BitsType, typename InputType>
 inline bool isIdentical(InputType left, InputType right)
index f5beaaf..6589185 100644 (file)
 
 #if ENABLE(B3_JIT)
 
-#include <wtf/MonotonicTime.h>
-#include <wtf/Noncopyable.h>
+#include "CompilerTimingScope.h"
 
 namespace JSC { namespace B3 {
 
-class TimingScope {
-    WTF_MAKE_NONCOPYABLE(TimingScope);
+class TimingScope : public CompilerTimingScope {
 public:
-    TimingScope(const char* name);
-    ~TimingScope();
-
-private:
-    const char* m_name;
-    MonotonicTime m_before;
+    TimingScope(const char* name)
+        : CompilerTimingScope("B3", name)
+    {
+    }
 };
 
 } } // namespace JSC::B3
index 2d6180b..863e068 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2011-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -27,6 +27,7 @@
 
 #if ENABLE(DFG_JIT)
 
+#include "CompilerTimingScope.h"
 #include "DFGCommon.h"
 #include "DFGGraph.h"
 
@@ -76,17 +77,10 @@ private:
 template<typename PhaseType>
 bool runAndLog(PhaseType& phase)
 {
-    MonotonicTime before { };
-
-    if (UNLIKELY(Options::reportDFGPhaseTimes()))
-        before = MonotonicTime::now();
-
+    CompilerTimingScope timingScope("DFG", phase.name());
+    
     bool result = phase.run();
 
-    if (UNLIKELY(Options::reportDFGPhaseTimes())) {
-        MonotonicTime after = MonotonicTime::now();
-        dataLogF("Phase %s took %.4f ms\n", phase.name(), (after - before).milliseconds());
-    }
     if (result && logCompilationChanges(phase.graph().m_plan.mode))
         dataLogF("Phase %s changed the IR.\n", phase.name());
     return result;
index 549a9db..0ef21f6 100644 (file)
@@ -181,7 +181,7 @@ void Plan::compileInThread(ThreadData* threadData)
     
     CompilationScope compilationScope;
 
-    if (logCompilationChanges(mode) || Options::reportDFGPhaseTimes())
+    if (logCompilationChanges(mode) || Options::logPhaseTimes())
         dataLog("DFG(Plan) compiling ", *codeBlock, " with ", mode, ", number of instructions = ", codeBlock->instructionCount(), "\n");
 
     CompilationPath path = compileInThreadImpl();
index df98220..8628e80 100644 (file)
@@ -426,7 +426,7 @@ static void recomputeDependentOptions()
         || Options::reportBaselineCompileTimes()
         || Options::reportDFGCompileTimes()
         || Options::reportFTLCompileTimes()
-        || Options::reportDFGPhaseTimes()
+        || Options::logPhaseTimes()
         || Options::verboseCFA()
         || Options::verboseDFGFailure()
         || Options::verboseFTLFailure())
index c11d888..ee18e21 100644 (file)
@@ -205,7 +205,6 @@ constexpr bool enableWebAssemblyStreamingApi = false;
     v(bool, reportBaselineCompileTimes, false, Normal, "dumps JS function signature and the time it took to BaselineJIT compile") \
     v(bool, reportDFGCompileTimes, false, Normal, "dumps JS function signature and the time it took to DFG and FTL compile") \
     v(bool, reportFTLCompileTimes, false, Normal, "dumps JS function signature and the time it took to FTL compile") \
-    v(bool, reportDFGPhaseTimes, false, Normal, "dumps JS function name and the time is took for each DFG phase") \
     v(bool, reportTotalCompileTimes, false, Normal, nullptr) \
     v(bool, reportParseTimes, false, Normal, "dumps JS function signature and the time it took to parse") \
     v(bool, reportBytecodeCompileTimes, false, Normal, "dumps JS function signature and the time it took to bytecode compile") \
@@ -434,7 +433,7 @@ constexpr bool enableWebAssemblyStreamingApi = false;
     v(unsigned, fireOSRExitFuzzAt, 0, Normal, nullptr) \
     v(unsigned, fireOSRExitFuzzAtOrAfter, 0, Normal, nullptr) \
     \
-    v(bool, logB3PhaseTimes, false, Normal, nullptr) \
+    v(bool, logPhaseTimes, false, Normal, nullptr) \
     v(double, rareBlockPenalty, 0.001, Normal, nullptr) \
     v(bool, airLinearScanVerbose, false, Normal, nullptr) \
     v(bool, airLinearScanSpillsEverything, false, Normal, nullptr) \
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2018 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  */
 
 #include "config.h"
-#include "B3TimingScope.h"
+#include "CompilerTimingScope.h"
 
-#if ENABLE(B3_JIT)
-
-#include "B3Common.h"
+#include "Options.h"
 #include <wtf/DataLog.h>
 #include <wtf/HashMap.h>
 #include <wtf/Lock.h>
 
-namespace JSC { namespace B3 {
+namespace JSC {
 
 namespace {
 
-class State {
-    WTF_MAKE_NONCOPYABLE(State);
+class CompilerTimingScopeState {
+    WTF_MAKE_NONCOPYABLE(CompilerTimingScopeState);
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    State() { }
+    CompilerTimingScopeState() { }
     
-    Seconds addToTotal(const char* name, Seconds duration)
+    Seconds addToTotal(const char* compilerName, const char* name, Seconds duration)
     {
         auto locker = holdLock(lock);
-        return totals.add(name, Seconds(0)).iterator->value += duration;
+        return totals.add(std::make_pair(compilerName, name), Seconds(0)).iterator->value += duration;
     }
     
 private:
-    HashMap<const char*, Seconds> totals;
+    HashMap<std::pair<const char*, const char*>, Seconds> totals;
     Lock lock;
 };
 
-State& state()
+CompilerTimingScopeState& compilerTimingScopeState()
 {
-    static Atomic<State*> s_state;
-    return ensurePointer(s_state, [] { return new State(); });
+    static Atomic<CompilerTimingScopeState*> s_state;
+    return ensurePointer(s_state, [] { return new CompilerTimingScopeState(); });
 }
 
 } // anonymous namespace
 
-TimingScope::TimingScope(const char* name)
-    : m_name(name)
+CompilerTimingScope::CompilerTimingScope(const char* compilerName, const char* name)
+    : m_compilerName(compilerName)
+    , m_name(name)
 {
-    if (shouldMeasurePhaseTiming())
+    if (Options::logPhaseTimes())
         m_before = MonotonicTime::now();
 }
 
-TimingScope::~TimingScope()
+CompilerTimingScope::~CompilerTimingScope()
 {
-    if (shouldMeasurePhaseTiming()) {
+    if (Options::logPhaseTimes()) {
         Seconds duration = MonotonicTime::now() - m_before;
         dataLog(
-            "[B3] ", m_name, " took: ", duration.milliseconds(), " ms ",
-            "(total: ", state().addToTotal(m_name, duration).milliseconds(), " ms).\n");
+            "[", m_compilerName, "] ", m_name, " took: ", duration.milliseconds(), " ms ",
+            "(total: ", compilerTimingScopeState().addToTotal(m_compilerName, m_name, duration).milliseconds(),
+            " ms).\n");
     }
 }
 
-} } // namespace JSC::B3
+} // namespace JSC
 
-#endif // ENABLE(B3_JIT)
 
diff --git a/Source/JavaScriptCore/tools/CompilerTimingScope.h b/Source/JavaScriptCore/tools/CompilerTimingScope.h
new file mode 100644 (file)
index 0000000..52a4f6b
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2015-2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#pragma once
+
+#include <wtf/MonotonicTime.h>
+#include <wtf/Noncopyable.h>
+
+namespace JSC {
+
+// FIXME: We should find some way of reconciling the differences between WTF::TimingScope and this class. The differences
+// are:
+// - CompilerTimingScope knows to only do work when --logPhaseTimes=true, while TimingScope is unconditional.
+// - CompilerTimingScope reports totals on every run, while TimingScope reports averages periodically.
+
+class CompilerTimingScope {
+    WTF_MAKE_NONCOPYABLE(CompilerTimingScope);
+public:
+    CompilerTimingScope(const char* compilerName, const char* name);
+    ~CompilerTimingScope();
+
+private:
+    const char* m_compilerName;
+    const char* m_name;
+    MonotonicTime m_before;
+};
+
+} // namespace JSC
+