mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Merge system_wrappers:metrics and system_wrappers:metrics_default.
After this CL, WebRTC clients will be able to exclude the default metrics implementation by defining the preprocessor macro WEBRTC_EXCLUDE_METRICS_DEFAULT (if GN is used, it will be enough to set rtc_exclude_metrics_default to true). Bug: webrtc:9631 Change-Id: Id6db23cc4b6c292d9f97372a8014c0c467ed0538 No-Try: True Reviewed-on: https://webrtc-review.googlesource.com/98102 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#24747}
This commit is contained in:
parent
d574123c50
commit
c1c2a8875f
4 changed files with 86 additions and 80 deletions
|
@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@
|
|||
#ifndef SYSTEM_WRAPPERS_INCLUDE_METRICS_H_
|
||||
#define SYSTEM_WRAPPERS_INCLUDE_METRICS_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#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<int, int> samples; // <value, # of events>
|
||||
};
|
||||
|
||||
// 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<std::string, std::unique_ptr<SampleInfo>>* 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
|
||||
|
||||
|
|
|
@ -11,51 +11,6 @@
|
|||
#ifndef SYSTEM_WRAPPERS_INCLUDE_METRICS_DEFAULT_H_
|
||||
#define SYSTEM_WRAPPERS_INCLUDE_METRICS_DEFAULT_H_
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
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<int, int> samples; // <value, # of events>
|
||||
};
|
||||
|
||||
// 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<std::string, std::unique_ptr<SampleInfo>>* 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_
|
||||
|
|
|
@ -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 <algorithm>
|
||||
|
||||
#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,
|
Loading…
Reference in a new issue