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 #include "src/profiler/profiler-stats.h" 6 7 #include <algorithm> 8 9 #include "src/base/platform/platform.h" 10 11 namespace v8 { 12 namespace internal { 13 AddReason(Reason reason)14void ProfilerStats::AddReason(Reason reason) { 15 counts_[reason].fetch_add(1, std::memory_order_relaxed); 16 } 17 Clear()18void ProfilerStats::Clear() { 19 for (int i = 0; i < Reason::kNumberOfReasons; i++) { 20 counts_[i].store(0, std::memory_order_relaxed); 21 } 22 } 23 Print() const24void ProfilerStats::Print() const { 25 base::OS::Print("ProfilerStats:\n"); 26 for (int i = 0; i < Reason::kNumberOfReasons; i++) { 27 base::OS::Print(" %-30s\t\t %d\n", ReasonToString(static_cast<Reason>(i)), 28 counts_[i].load(std::memory_order_relaxed)); 29 } 30 } 31 32 // static ReasonToString(Reason reason)33const char* ProfilerStats::ReasonToString(Reason reason) { 34 switch (reason) { 35 case kTickBufferFull: 36 return "kTickBufferFull"; 37 case kIsolateNotLocked: 38 return "kIsolateNotLocked"; 39 case kSimulatorFillRegistersFailed: 40 return "kSimulatorFillRegistersFailed"; 41 case kNoFrameRegion: 42 return "kNoFrameRegion"; 43 case kInCallOrApply: 44 return "kInCallOrApply"; 45 case kNoSymbolizedFrames: 46 return "kNoSymbolizedFrames"; 47 case kNullPC: 48 return "kNullPC"; 49 case kNumberOfReasons: 50 return "kNumberOfReasons"; 51 } 52 } 53 54 } // namespace internal 55 } // namespace v8 56