• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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_DIAGNOSTICS_COMPILATION_STATISTICS_H_
6 #define V8_DIAGNOSTICS_COMPILATION_STATISTICS_H_
7 
8 #include <map>
9 #include <string>
10 
11 #include "src/base/platform/time.h"
12 #include "src/utils/allocation.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 class OptimizedCompilationInfo;
18 class CompilationStatistics;
19 
20 struct AsPrintableStatistics {
21   const CompilationStatistics& s;
22   const bool machine_output;
23 };
24 
25 class CompilationStatistics final : public Malloced {
26  public:
27   CompilationStatistics() = default;
28   CompilationStatistics(const CompilationStatistics&) = delete;
29   CompilationStatistics& operator=(const CompilationStatistics&) = delete;
30 
31   class BasicStats {
32    public:
BasicStats()33     BasicStats()
34         : total_allocated_bytes_(0),
35           max_allocated_bytes_(0),
36           absolute_max_allocated_bytes_(0) {}
37 
38     void Accumulate(const BasicStats& stats);
39 
40     std::string AsJSON();
41 
42     base::TimeDelta delta_;
43     size_t total_allocated_bytes_;
44     size_t max_allocated_bytes_;
45     size_t absolute_max_allocated_bytes_;
46     std::string function_name_;
47   };
48 
49   void RecordPhaseStats(const char* phase_kind_name, const char* phase_name,
50                         const BasicStats& stats);
51 
52   void RecordPhaseKindStats(const char* phase_kind_name,
53                             const BasicStats& stats);
54 
55   void RecordTotalStats(const BasicStats& stats);
56 
57  private:
58   class TotalStats : public BasicStats {
59    public:
TotalStats()60     TotalStats() : source_size_(0) {}
61     uint64_t source_size_;
62   };
63 
64   class OrderedStats : public BasicStats {
65    public:
OrderedStats(size_t insert_order)66     explicit OrderedStats(size_t insert_order) : insert_order_(insert_order) {}
67     size_t insert_order_;
68   };
69 
70   class PhaseStats : public OrderedStats {
71    public:
PhaseStats(size_t insert_order,const char * phase_kind_name)72     PhaseStats(size_t insert_order, const char* phase_kind_name)
73         : OrderedStats(insert_order), phase_kind_name_(phase_kind_name) {}
74     std::string phase_kind_name_;
75   };
76 
77   friend std::ostream& operator<<(std::ostream& os,
78                                   const AsPrintableStatistics& s);
79 
80   using PhaseKindStats = OrderedStats;
81   using PhaseKindMap = std::map<std::string, PhaseKindStats>;
82   using PhaseMap = std::map<std::string, PhaseStats>;
83 
84   TotalStats total_stats_;
85   PhaseKindMap phase_kind_map_;
86   PhaseMap phase_map_;
87   base::Mutex record_mutex_;
88 };
89 
90 std::ostream& operator<<(std::ostream& os, const AsPrintableStatistics& s);
91 
92 }  // namespace internal
93 }  // namespace v8
94 
95 #endif  // V8_DIAGNOSTICS_COMPILATION_STATISTICS_H_
96