1 // Copyright 2020 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_PROFILER_PROFILER_STATS_H_ 6 #define V8_PROFILER_PROFILER_STATS_H_ 7 8 #include <atomic> 9 10 namespace v8 { 11 namespace internal { 12 13 // Stats are used to diagnose the reasons for dropped or unnattributed frames. 14 class ProfilerStats { 15 public: 16 enum Reason { 17 // Reasons we fail to record a TickSample. 18 kTickBufferFull, 19 kIsolateNotLocked, 20 // These all generate a TickSample. 21 kSimulatorFillRegistersFailed, 22 kNoFrameRegion, 23 kInCallOrApply, 24 kNoSymbolizedFrames, 25 kNullPC, 26 27 kNumberOfReasons, 28 }; 29 Instance()30 static ProfilerStats* Instance() { 31 static ProfilerStats stats; 32 return &stats; 33 } 34 35 void AddReason(Reason reason); 36 void Clear(); 37 void Print() const; 38 39 private: 40 ProfilerStats() = default; 41 static const char* ReasonToString(Reason reason); 42 43 std::atomic_int counts_[Reason::kNumberOfReasons] = {}; 44 }; 45 46 } // namespace internal 47 } // namespace v8 48 49 #endif // V8_PROFILER_PROFILER_STATS_H_ 50