chromium/third_party/blink/renderer/platform/bindings/runtime_call_stats.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/platform/bindings/runtime_call_stats.h"

#include <inttypes.h>

#include <algorithm>

#include "base/logging.h"
#include "base/time/default_tick_clock.h"
#include "third_party/blink/public/web/blink.h"
#include "third_party/blink/renderer/platform/bindings/v8_per_isolate_data.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/traced_value.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"

namespace blink {

void LogRuntimeCallStats(v8::Isolate* isolate) {}

namespace {
RuntimeCallStats* g_runtime_call_stats_for_testing =;
}

void RuntimeCallCounter::Dump(TracedValue& value) const {}

void RuntimeCallTimer::Start(RuntimeCallCounter* counter,
                             RuntimeCallTimer* parent) {}

RuntimeCallTimer* RuntimeCallTimer::Stop() {}

RuntimeCallStats::RuntimeCallStats(const base::TickClock* clock)
    :{}

// static
RuntimeCallStats* RuntimeCallStats::From(v8::Isolate* isolate) {}

void RuntimeCallStats::Reset() {}

void RuntimeCallStats::Dump(TracedValue& value) const {}

namespace {
const char row_format[] =;
}

String RuntimeCallStats::ToString() const {}

// static
void RuntimeCallStats::SetRuntimeCallStatsForTesting() {}

// static
void RuntimeCallStats::ClearRuntimeCallStatsForTesting() {}

// This function exists to remove runtime_enabled_features.h dependnency from
// runtime_call_stats.h.
bool RuntimeCallStats::IsEnabled() {}

#if BUILDFLAG(RCS_COUNT_EVERYTHING)
RuntimeCallCounter* RuntimeCallStats::GetCounter(const char* name) {
  CounterMap::iterator it = counter_map_.find(name);
  if (it != counter_map_.end())
    return it->value.get();
  return counter_map_.insert(name, std::make_unique<RuntimeCallCounter>(name))
      .stored_value->value.get();
}

Vector<RuntimeCallCounter*> RuntimeCallStats::CounterMapToSortedArray() const {
  Vector<RuntimeCallCounter*> counters;
  for (const auto& counter : counter_map_.Values()) {
    counters.push_back(counter.get());
  }
  auto comparator = [](RuntimeCallCounter* a, RuntimeCallCounter* b) {
    return a->GetCount() == b->GetCount()
               ? strcmp(a->GetName(), b->GetName()) < 0
               : a->GetCount() < b->GetCount();
  };
  std::sort(counters.begin(), counters.end(), comparator);
  return counters;
}

void RuntimeCallStats::AddCounterMapStatsToBuilder(
    StringBuilder& builder) const {
  builder.AppendFormat("\nNumber of counters in map: %u\n\n",
                       counter_map_.size());
  for (RuntimeCallCounter* counter : CounterMapToSortedArray()) {
    builder.AppendFormat(row_format, counter->GetName(), counter->GetCount(),
                         counter->GetTime().InMillisecondsF());
  }
}
#endif

constexpr const char* RuntimeCallStatsScopedTracer::s_category_group_ =);
constexpr const char* RuntimeCallStatsScopedTracer::s_name_ =;

void RuntimeCallStatsScopedTracer::AddBeginTraceEventIfEnabled(
    v8::Isolate* isolate) {}

void RuntimeCallStatsScopedTracer::AddEndTraceEvent() {}

}  // namespace blink