diff --git a/system_wrappers/BUILD.gn b/system_wrappers/BUILD.gn index a926147bba..2cd2509197 100644 --- a/system_wrappers/BUILD.gn +++ b/system_wrappers/BUILD.gn @@ -110,18 +110,6 @@ rtc_source_set("runtime_enabled_features_api") { ] } -rtc_source_set("metrics_api") { - visibility = [ "*" ] - sources = [ - "include/metrics.h", - ] - deps = [ - "..:webrtc_common", - "../rtc_base:checks", - "../rtc_base:rtc_base_approved", - ] -} - rtc_source_set("field_trial_default") { visibility = [ "*" ] sources = [ @@ -145,15 +133,40 @@ rtc_source_set("runtime_enabled_features_default") { ] } +rtc_source_set("metrics") { + visibility = [ "*" ] + public = [ + "include/metrics.h", + "include/metrics_default.h", + ] + sources = [ + "source/metrics.cc", + ] + if (rtc_exclude_metrics_default) { + defines = [ "WEBRTC_EXCLUDE_METRICS_DEFAULT" ] + } + deps = [ + "..:webrtc_common", + "../rtc_base:checks", + "../rtc_base:rtc_base_approved", + ] +} + +# TODO(bugs.webrtc.org/9631): Remove this as soon as Chromium stops depending +# on it. +rtc_source_set("metrics_api") { + visibility = [ "*" ] + public_deps = [ # no-presubmit-check TODO(webrtc:8603) + ":metrics", + ] +} + +# TODO(bugs.webrtc.org/9631): Remove this as soon as Chromium stops depending +# on it. rtc_source_set("metrics_default") { visibility = [ "*" ] - sources = [ - "include/metrics_default.h", - "source/metrics_default.cc", - ] - deps = [ - ":metrics_api", - "../rtc_base:rtc_base_approved", + public_deps = [ # no-presubmit-check TODO(webrtc:8603) + ":metrics", ] } diff --git a/system_wrappers/include/metrics.h b/system_wrappers/include/metrics.h index 99b8194f1a..2a2cda02d0 100644 --- a/system_wrappers/include/metrics.h +++ b/system_wrappers/include/metrics.h @@ -11,6 +11,8 @@ #ifndef SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ #define SYSTEM_WRAPPERS_INCLUDE_METRICS_H_ +#include +#include #include #include "common_types.h" // NOLINT(build/include) @@ -31,20 +33,21 @@ // The macros use the methods HistogramFactoryGetCounts, // HistogramFactoryGetEnumeration and HistogramAdd. // -// Therefore, WebRTC clients must either: -// -// - provide implementations of -// Histogram* webrtc::metrics::HistogramFactoryGetCounts( -// const std::string& name, int sample, int min, int max, -// int bucket_count); -// Histogram* webrtc::metrics::HistogramFactoryGetEnumeration( -// const std::string& name, int sample, int boundary); -// void webrtc::metrics::HistogramAdd( -// Histogram* histogram_pointer, const std::string& name, int sample); -// -// - or link with the default implementations (i.e. -// system_wrappers:metrics_default). +// By default WebRTC provides implementations of the aforementioned methods +// that can be found in system_wrappers/source/metrics.cc. If clients want to +// provide a custom version, they will have to: // +// 1. Compile WebRTC defining the preprocessor macro +// WEBRTC_EXCLUDE_METRICS_DEFAULT (if GN is used this can be achieved +// by setting the GN arg rtc_exclude_metrics_default to true). +// 2. Provide implementations of: +// Histogram* webrtc::metrics::HistogramFactoryGetCounts( +// const std::string& name, int sample, int min, int max, +// int bucket_count); +// Histogram* webrtc::metrics::HistogramFactoryGetEnumeration( +// const std::string& name, int sample, int boundary); +// void webrtc::metrics::HistogramAdd( +// Histogram* histogram_pointer, const std::string& name, int sample); // // Example usage: // @@ -274,6 +277,39 @@ Histogram* SparseHistogramFactoryGetEnumeration(const std::string& name, // Function for adding a |sample| to a histogram. void HistogramAdd(Histogram* histogram_pointer, int sample); +struct SampleInfo { + SampleInfo(const std::string& name, int min, int max, size_t bucket_count); + ~SampleInfo(); + + const std::string name; + const int min; + const int max; + const size_t bucket_count; + std::map samples; // +}; + +// Enables collection of samples. +// This method should be called before any other call into webrtc. +void Enable(); + +// Gets histograms and clears all samples. +void GetAndReset( + std::map>* histograms); + +// Functions below are mainly for testing. + +// Clears all samples. +void Reset(); + +// Returns the number of times the |sample| has been added to the histogram. +int NumEvents(const std::string& name, int sample); + +// Returns the total number of added samples to the histogram. +int NumSamples(const std::string& name); + +// Returns the minimum sample value (or -1 if the histogram has no samples). +int MinSample(const std::string& name); + } // namespace metrics } // namespace webrtc diff --git a/system_wrappers/include/metrics_default.h b/system_wrappers/include/metrics_default.h index 5ce3582204..5311587577 100644 --- a/system_wrappers/include/metrics_default.h +++ b/system_wrappers/include/metrics_default.h @@ -11,51 +11,6 @@ #ifndef SYSTEM_WRAPPERS_INCLUDE_METRICS_DEFAULT_H_ #define SYSTEM_WRAPPERS_INCLUDE_METRICS_DEFAULT_H_ -#include -#include -#include - -namespace webrtc { -namespace metrics { - -// This class does not actually exist. It is casted to an implementation defined -// pointer inside the functions. -class Histogram; - -struct SampleInfo { - SampleInfo(const std::string& name, int min, int max, size_t bucket_count); - ~SampleInfo(); - - const std::string name; - const int min; - const int max; - const size_t bucket_count; - std::map samples; // -}; - -// Enables collection of samples. -// This method should be called before any other call into webrtc. -void Enable(); - -// Gets histograms and clears all samples. -void GetAndReset( - std::map>* histograms); - -// Functions below are mainly for testing. - -// Clears all samples. -void Reset(); - -// Returns the number of times the |sample| has been added to the histogram. -int NumEvents(const std::string& name, int sample); - -// Returns the total number of added samples to the histogram. -int NumSamples(const std::string& name); - -// Returns the minimum sample value (or -1 if the histogram has no samples). -int MinSample(const std::string& name); - -} // namespace metrics -} // namespace webrtc +#include "system_wrappers/include/metrics.h" #endif // SYSTEM_WRAPPERS_INCLUDE_METRICS_DEFAULT_H_ diff --git a/system_wrappers/source/metrics_default.cc b/system_wrappers/source/metrics.cc similarity index 99% rename from system_wrappers/source/metrics_default.cc rename to system_wrappers/source/metrics.cc index 7b62c8103f..662e64ef24 100644 --- a/system_wrappers/source/metrics_default.cc +++ b/system_wrappers/source/metrics.cc @@ -7,13 +7,12 @@ // be found in the AUTHORS file in the root of the source tree. // -#include "system_wrappers/include/metrics_default.h" +#include "system_wrappers/include/metrics.h" #include #include "rtc_base/criticalsection.h" #include "rtc_base/thread_annotations.h" -#include "system_wrappers/include/metrics.h" // Default implementation of histogram methods for WebRTC clients that do not // want to provide their own implementation. @@ -203,6 +202,7 @@ RtcHistogramMap* GetMap() { } } // namespace +#ifndef WEBRTC_EXCLUDE_METRICS_DEFAULT // Implementation of histogram methods in // webrtc/system_wrappers/interface/metrics.h. @@ -259,6 +259,8 @@ void HistogramAdd(Histogram* histogram_pointer, int sample) { ptr->Add(sample); } +#endif // WEBRTC_EXCLUDE_METRICS_DEFAULT + SampleInfo::SampleInfo(const std::string& name, int min, int max,