blob: ceffc2ebc19fcebc297d96e7aba4a63468abcdb9 [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// 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_COMPILATION_STATISTICS_H_
6#define V8_COMPILATION_STATISTICS_H_
7
8#include <map>
9#include <string>
10
11#include "src/allocation.h"
12#include "src/base/platform/time.h"
13
14namespace v8 {
15namespace internal {
16
17class CompilationInfo;
Ben Murdoch61f157c2016-09-16 13:49:30 +010018class CompilationStatistics;
19
20struct AsPrintableStatistics {
21 const CompilationStatistics& s;
22 const bool machine_output;
23};
Emily Bernierd0a1eb72015-03-24 16:35:39 -040024
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000025class CompilationStatistics final : public Malloced {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040026 public:
27 CompilationStatistics() {}
28
29 class BasicStats {
30 public:
31 BasicStats()
32 : total_allocated_bytes_(0),
33 max_allocated_bytes_(0),
34 absolute_max_allocated_bytes_(0) {}
35
36 void Accumulate(const BasicStats& stats);
37
38 base::TimeDelta delta_;
39 size_t total_allocated_bytes_;
40 size_t max_allocated_bytes_;
41 size_t absolute_max_allocated_bytes_;
42 std::string function_name_;
43 };
44
45 void RecordPhaseStats(const char* phase_kind_name, const char* phase_name,
46 const BasicStats& stats);
47
48 void RecordPhaseKindStats(const char* phase_kind_name,
49 const BasicStats& stats);
50
51 void RecordTotalStats(size_t source_size, const BasicStats& stats);
52
53 private:
54 class TotalStats : public BasicStats {
55 public:
56 TotalStats() : source_size_(0) {}
57 uint64_t source_size_;
58 };
59
60 class OrderedStats : public BasicStats {
61 public:
62 explicit OrderedStats(size_t insert_order) : insert_order_(insert_order) {}
63 size_t insert_order_;
64 };
65
66 class PhaseStats : public OrderedStats {
67 public:
68 PhaseStats(size_t insert_order, const char* phase_kind_name)
69 : OrderedStats(insert_order), phase_kind_name_(phase_kind_name) {}
70 std::string phase_kind_name_;
71 };
72
73 friend std::ostream& operator<<(std::ostream& os,
Ben Murdoch61f157c2016-09-16 13:49:30 +010074 const AsPrintableStatistics& s);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040075
76 typedef OrderedStats PhaseKindStats;
77 typedef std::map<std::string, PhaseKindStats> PhaseKindMap;
78 typedef std::map<std::string, PhaseStats> PhaseMap;
79
80 TotalStats total_stats_;
81 PhaseKindMap phase_kind_map_;
82 PhaseMap phase_map_;
83
84 DISALLOW_COPY_AND_ASSIGN(CompilationStatistics);
85};
86
Ben Murdoch61f157c2016-09-16 13:49:30 +010087std::ostream& operator<<(std::ostream& os, const AsPrintableStatistics& s);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040088
89} // namespace internal
90} // namespace v8
91
92#endif