pipeline-statistics.cc 3.65 KB
Newer Older
1 2 3 4
// 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.

5 6
#include <memory>

7
#include "src/codegen/optimized-compilation-info.h"
8
#include "src/compiler/pipeline-statistics.h"
9
#include "src/compiler/zone-stats.h"
10
#include "src/objects/shared-function-info.h"
11
#include "src/objects/string.h"
12
#include "src/tracing/trace-event.h"
13 14 15 16 17

namespace v8 {
namespace internal {
namespace compiler {

18 19 20
namespace {

// We log detailed phase information about the pipeline
21
// in both the v8.turbofan and the v8.wasm.detailed categories.
22
constexpr const char kTraceCategory[] =           // --
23
    TRACE_DISABLED_BY_DEFAULT("v8.turbofan") ","  // --
24
    TRACE_DISABLED_BY_DEFAULT("v8.wasm.detailed");
25 26 27

}  // namespace

28 29
void PipelineStatistics::CommonStats::Begin(
    PipelineStatistics* pipeline_stats) {
30
  DCHECK(!scope_);
31
  scope_.reset(new ZoneStats::StatsScope(pipeline_stats->zone_stats_));
32 33
  timer_.Start();
  outer_zone_initial_size_ = pipeline_stats->OuterZoneSize();
34 35 36
  allocated_bytes_at_start_ =
      outer_zone_initial_size_ -
      pipeline_stats->total_stats_.outer_zone_initial_size_ +
37
      pipeline_stats->zone_stats_->GetCurrentAllocatedBytes();
38 39 40 41 42 43
}


void PipelineStatistics::CommonStats::End(
    PipelineStatistics* pipeline_stats,
    CompilationStatistics::BasicStats* diff) {
44
  DCHECK(scope_);
45 46 47 48 49
  diff->function_name_ = pipeline_stats->function_name_;
  diff->delta_ = timer_.Elapsed();
  size_t outer_zone_diff =
      pipeline_stats->OuterZoneSize() - outer_zone_initial_size_;
  diff->max_allocated_bytes_ = outer_zone_diff + scope_->GetMaxAllocatedBytes();
50 51
  diff->absolute_max_allocated_bytes_ =
      diff->max_allocated_bytes_ + allocated_bytes_at_start_;
52 53
  diff->total_allocated_bytes_ =
      outer_zone_diff + scope_->GetTotalAllocatedBytes();
54
  scope_.reset();
55 56 57
  timer_.Stop();
}

58
PipelineStatistics::PipelineStatistics(OptimizedCompilationInfo* info,
59 60 61
                                       CompilationStatistics* compilation_stats,
                                       ZoneStats* zone_stats)
    : outer_zone_(info->zone()),
62
      zone_stats_(zone_stats),
63
      compilation_stats_(compilation_stats),
64 65
      phase_kind_name_(nullptr),
      phase_name_(nullptr) {
66
  if (info->has_shared_info()) {
67
    std::unique_ptr<char[]> name = info->shared_info()->DebugName().ToCString();
68 69 70 71 72 73 74 75 76 77
    function_name_ = name.get();
  }
  total_stats_.Begin(this);
}


PipelineStatistics::~PipelineStatistics() {
  if (InPhaseKind()) EndPhaseKind();
  CompilationStatistics::BasicStats diff;
  total_stats_.End(this, &diff);
78
  compilation_stats_->RecordTotalStats(diff);
79 80 81 82 83 84
}


void PipelineStatistics::BeginPhaseKind(const char* phase_kind_name) {
  DCHECK(!InPhase());
  if (InPhaseKind()) EndPhaseKind();
85
  TRACE_EVENT_BEGIN0(kTraceCategory, phase_kind_name);
86 87 88 89 90 91 92 93 94
  phase_kind_name_ = phase_kind_name;
  phase_kind_stats_.Begin(this);
}

void PipelineStatistics::EndPhaseKind() {
  DCHECK(!InPhase());
  CompilationStatistics::BasicStats diff;
  phase_kind_stats_.End(this, &diff);
  compilation_stats_->RecordPhaseKindStats(phase_kind_name_, diff);
95
  TRACE_EVENT_END0(kTraceCategory, phase_kind_name_);
96 97
}

98 99
void PipelineStatistics::BeginPhase(const char* phase_name) {
  TRACE_EVENT_BEGIN0(kTraceCategory, phase_name);
100
  DCHECK(InPhaseKind());
101
  phase_name_ = phase_name;
102 103 104 105 106 107 108 109
  phase_stats_.Begin(this);
}

void PipelineStatistics::EndPhase() {
  DCHECK(InPhaseKind());
  CompilationStatistics::BasicStats diff;
  phase_stats_.End(this, &diff);
  compilation_stats_->RecordPhaseStats(phase_kind_name_, phase_name_, diff);
110
  TRACE_EVENT_END0(kTraceCategory, phase_name_);
111 112 113 114 115
}

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