pipeline-statistics.h 2.62 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_COMPILER_PIPELINE_STATISTICS_H_
#define V8_COMPILER_PIPELINE_STATISTICS_H_

8
#include <memory>
9 10
#include <string>

11
#include "src/base/platform/elapsed-timer.h"
12
#include "src/compiler/zone-stats.h"
13
#include "src/diagnostics/compilation-statistics.h"
14 15 16 17 18 19 20 21 22

namespace v8 {
namespace internal {
namespace compiler {

class PhaseScope;

class PipelineStatistics : public Malloced {
 public:
23 24
  PipelineStatistics(OptimizedCompilationInfo* info,
                     CompilationStatistics* turbo_stats, ZoneStats* zone_stats);
25
  ~PipelineStatistics();
26 27
  PipelineStatistics(const PipelineStatistics&) = delete;
  PipelineStatistics& operator=(const PipelineStatistics&) = delete;
28 29

  void BeginPhaseKind(const char* phase_kind_name);
30
  void EndPhaseKind();
31 32 33 34 35 36 37 38 39

 private:
  size_t OuterZoneSize() {
    return static_cast<size_t>(outer_zone_->allocation_size());
  }

  class CommonStats {
   public:
    CommonStats() : outer_zone_initial_size_(0) {}
40 41
    CommonStats(const CommonStats&) = delete;
    CommonStats& operator=(const CommonStats&) = delete;
42 43 44 45 46

    void Begin(PipelineStatistics* pipeline_stats);
    void End(PipelineStatistics* pipeline_stats,
             CompilationStatistics::BasicStats* diff);

47
    std::unique_ptr<ZoneStats::StatsScope> scope_;
48 49
    base::ElapsedTimer timer_;
    size_t outer_zone_initial_size_;
50
    size_t allocated_bytes_at_start_;
51 52
  };

53
  bool InPhaseKind() { return !!phase_kind_stats_.scope_; }
54 55

  friend class PhaseScope;
56
  bool InPhase() { return !!phase_stats_.scope_; }
57 58 59 60
  void BeginPhase(const char* name);
  void EndPhase();

  Zone* outer_zone_;
61
  ZoneStats* zone_stats_;
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
  CompilationStatistics* compilation_stats_;
  std::string function_name_;

  // Stats for the entire compilation.
  CommonStats total_stats_;

  // Stats for phase kind.
  const char* phase_kind_name_;
  CommonStats phase_kind_stats_;

  // Stats for phase.
  const char* phase_name_;
  CommonStats phase_stats_;
};

77
class V8_NODISCARD PhaseScope {
78 79 80
 public:
  PhaseScope(PipelineStatistics* pipeline_stats, const char* name)
      : pipeline_stats_(pipeline_stats) {
81
    if (pipeline_stats_ != nullptr) pipeline_stats_->BeginPhase(name);
82 83
  }
  ~PhaseScope() {
84
    if (pipeline_stats_ != nullptr) pipeline_stats_->EndPhase();
85
  }
86 87
  PhaseScope(const PhaseScope&) = delete;
  PhaseScope& operator=(const PhaseScope&) = delete;
88 89 90 91 92 93 94 95 96

 private:
  PipelineStatistics* const pipeline_stats_;
};

}  // namespace compiler
}  // namespace internal
}  // namespace v8

97
#endif  // V8_COMPILER_PIPELINE_STATISTICS_H_