mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Adopt absl::string_view in system_wrappers/
Bug: webrtc:13579 Change-Id: Id0e6515c63a3c9aa6d7effef7a2bd8b5ef35af09 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/262245 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Ali Tofigh <alito@webrtc.org> Reviewed-by: Kári Helgason <kthelgason@webrtc.org> Reviewed-by: Niels Moller <nisse@webrtc.org> Reviewed-by: Xavier Lepaul <xalep@webrtc.org> Cr-Commit-Position: refs/heads/main@{#36904}
This commit is contained in:
parent
2e521f5a25
commit
969c1356af
11 changed files with 83 additions and 61 deletions
|
@ -1037,6 +1037,7 @@ if (is_ios || is_mac) {
|
||||||
"../rtc_base:logging",
|
"../rtc_base:logging",
|
||||||
"../rtc_base:network_constants",
|
"../rtc_base:network_constants",
|
||||||
"../rtc_base:safe_conversions",
|
"../rtc_base:safe_conversions",
|
||||||
|
"../rtc_base:stringutils",
|
||||||
"../rtc_base:timeutils",
|
"../rtc_base:timeutils",
|
||||||
"../stats:rtc_stats",
|
"../stats:rtc_stats",
|
||||||
"../system_wrappers:field_trial",
|
"../system_wrappers:field_trial",
|
||||||
|
|
|
@ -836,6 +836,7 @@ if (current_os == "linux" || is_android) {
|
||||||
":native_api_jni",
|
":native_api_jni",
|
||||||
":peerconnection_jni",
|
":peerconnection_jni",
|
||||||
"../../pc:peerconnection",
|
"../../pc:peerconnection",
|
||||||
|
"../../rtc_base:stringutils",
|
||||||
"../../system_wrappers:metrics",
|
"../../system_wrappers:metrics",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
#include "rtc_base/string_utils.h"
|
||||||
#include "sdk/android/generated_metrics_jni/Metrics_jni.h"
|
#include "sdk/android/generated_metrics_jni/Metrics_jni.h"
|
||||||
#include "sdk/android/native_api/jni/java_types.h"
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
@ -28,7 +29,9 @@ static void JNI_Metrics_Enable(JNIEnv* jni) {
|
||||||
static ScopedJavaLocalRef<jobject> JNI_Metrics_GetAndReset(JNIEnv* jni) {
|
static ScopedJavaLocalRef<jobject> JNI_Metrics_GetAndReset(JNIEnv* jni) {
|
||||||
ScopedJavaLocalRef<jobject> j_metrics = Java_Metrics_Constructor(jni);
|
ScopedJavaLocalRef<jobject> j_metrics = Java_Metrics_Constructor(jni);
|
||||||
|
|
||||||
std::map<std::string, std::unique_ptr<metrics::SampleInfo>> histograms;
|
std::map<std::string, std::unique_ptr<metrics::SampleInfo>,
|
||||||
|
rtc::AbslStringViewCmp>
|
||||||
|
histograms;
|
||||||
metrics::GetAndReset(&histograms);
|
metrics::GetAndReset(&histograms);
|
||||||
for (const auto& kv : histograms) {
|
for (const auto& kv : histograms) {
|
||||||
// Create and add samples to `HistogramInfo`.
|
// Create and add samples to `HistogramInfo`.
|
||||||
|
|
|
@ -12,12 +12,14 @@
|
||||||
|
|
||||||
#import "RTCMetricsSampleInfo+Private.h"
|
#import "RTCMetricsSampleInfo+Private.h"
|
||||||
|
|
||||||
|
#include "rtc_base/string_utils.h"
|
||||||
|
|
||||||
void RTCEnableMetrics(void) {
|
void RTCEnableMetrics(void) {
|
||||||
webrtc::metrics::Enable();
|
webrtc::metrics::Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
NSArray<RTC_OBJC_TYPE(RTCMetricsSampleInfo) *> *RTCGetAndResetMetrics(void) {
|
NSArray<RTC_OBJC_TYPE(RTCMetricsSampleInfo) *> *RTCGetAndResetMetrics(void) {
|
||||||
std::map<std::string, std::unique_ptr<webrtc::metrics::SampleInfo>>
|
std::map<std::string, std::unique_ptr<webrtc::metrics::SampleInfo>, rtc::AbslStringViewCmp>
|
||||||
histograms;
|
histograms;
|
||||||
webrtc::metrics::GetAndReset(&histograms);
|
webrtc::metrics::GetAndReset(&histograms);
|
||||||
|
|
||||||
|
|
|
@ -76,9 +76,7 @@ rtc_library("system_wrappers") {
|
||||||
deps += [ "../rtc_base:win32" ]
|
deps += [ "../rtc_base:win32" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
deps += [
|
deps += [ "../rtc_base:rtc_numerics" ]
|
||||||
"../rtc_base:rtc_numerics",
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc_library("field_trial") {
|
rtc_library("field_trial") {
|
||||||
|
@ -107,8 +105,10 @@ rtc_library("metrics") {
|
||||||
"../rtc_base:atomicops",
|
"../rtc_base:atomicops",
|
||||||
"../rtc_base:checks",
|
"../rtc_base:checks",
|
||||||
"../rtc_base:macromagic",
|
"../rtc_base:macromagic",
|
||||||
|
"../rtc_base:stringutils",
|
||||||
"../rtc_base/synchronization:mutex",
|
"../rtc_base/synchronization:mutex",
|
||||||
]
|
]
|
||||||
|
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
rtc_library("denormal_disabler") {
|
rtc_library("denormal_disabler") {
|
||||||
|
@ -144,6 +144,7 @@ if (rtc_include_tests && !build_with_chromium) {
|
||||||
":system_wrappers",
|
":system_wrappers",
|
||||||
"../rtc_base:checks",
|
"../rtc_base:checks",
|
||||||
"../rtc_base:random",
|
"../rtc_base:random",
|
||||||
|
"../rtc_base:stringutils",
|
||||||
"../test:rtc_expect_death",
|
"../test:rtc_expect_death",
|
||||||
"../test:test_main",
|
"../test:test_main",
|
||||||
"../test:test_support",
|
"../test:test_support",
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
// WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT (if GN is used this can be achieved
|
// WEBRTC_EXCLUDE_FIELD_TRIAL_DEFAULT (if GN is used this can be achieved
|
||||||
// by setting the GN arg rtc_exclude_field_trial_default to true).
|
// by setting the GN arg rtc_exclude_field_trial_default to true).
|
||||||
// 2. Provide an implementation of:
|
// 2. Provide an implementation of:
|
||||||
// std::string webrtc::field_trial::FindFullName(const std::string& trial).
|
// std::string webrtc::field_trial::FindFullName(absl::string_view trial).
|
||||||
//
|
//
|
||||||
// They are designed to wire up directly to chrome field trials and to speed up
|
// They are designed to wire up directly to chrome field trials and to speed up
|
||||||
// developers by reducing the need to wire APIs to control whether a feature is
|
// developers by reducing the need to wire APIs to control whether a feature is
|
||||||
|
@ -68,13 +68,13 @@ std::string FindFullName(absl::string_view name);
|
||||||
// Convenience method, returns true iff FindFullName(name) return a string that
|
// Convenience method, returns true iff FindFullName(name) return a string that
|
||||||
// starts with "Enabled".
|
// starts with "Enabled".
|
||||||
// TODO(tommi): Make sure all implementations support this.
|
// TODO(tommi): Make sure all implementations support this.
|
||||||
inline bool IsEnabled(const char* name) {
|
inline bool IsEnabled(absl::string_view name) {
|
||||||
return FindFullName(name).find("Enabled") == 0;
|
return FindFullName(name).find("Enabled") == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convenience method, returns true iff FindFullName(name) return a string that
|
// Convenience method, returns true iff FindFullName(name) return a string that
|
||||||
// starts with "Disabled".
|
// starts with "Disabled".
|
||||||
inline bool IsDisabled(const char* name) {
|
inline bool IsDisabled(absl::string_view name) {
|
||||||
return FindFullName(name).find("Disabled") == 0;
|
return FindFullName(name).find("Disabled") == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,14 +87,15 @@ void InitFieldTrialsFromString(const char* trials_string);
|
||||||
const char* GetFieldTrialString();
|
const char* GetFieldTrialString();
|
||||||
|
|
||||||
// Validates the given field trial string.
|
// Validates the given field trial string.
|
||||||
bool FieldTrialsStringIsValid(const char* trials_string);
|
bool FieldTrialsStringIsValid(absl::string_view trials_string);
|
||||||
|
|
||||||
// Merges two field trial strings.
|
// Merges two field trial strings.
|
||||||
//
|
//
|
||||||
// If a key (trial) exists twice with conflicting values (groups), the value
|
// If a key (trial) exists twice with conflicting values (groups), the value
|
||||||
// in 'second' takes precedence.
|
// in 'second' takes precedence.
|
||||||
// Shall only be called with valid FieldTrial strings.
|
// Shall only be called with valid FieldTrial strings.
|
||||||
std::string MergeFieldTrialsStrings(const char* first, const char* second);
|
std::string MergeFieldTrialsStrings(absl::string_view first,
|
||||||
|
absl::string_view second);
|
||||||
|
|
||||||
} // namespace field_trial
|
} // namespace field_trial
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/atomic_ops.h"
|
#include "rtc_base/atomic_ops.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
|
#include "rtc_base/string_utils.h"
|
||||||
|
|
||||||
#if defined(RTC_DISABLE_METRICS)
|
#if defined(RTC_DISABLE_METRICS)
|
||||||
#define RTC_METRICS_ENABLED 0
|
#define RTC_METRICS_ENABLED 0
|
||||||
|
@ -76,12 +78,12 @@ void NoOp(const Ts&...) {}
|
||||||
// by setting the GN arg rtc_exclude_metrics_default to true).
|
// by setting the GN arg rtc_exclude_metrics_default to true).
|
||||||
// 2. Provide implementations of:
|
// 2. Provide implementations of:
|
||||||
// Histogram* webrtc::metrics::HistogramFactoryGetCounts(
|
// Histogram* webrtc::metrics::HistogramFactoryGetCounts(
|
||||||
// const std::string& name, int sample, int min, int max,
|
// absl::string_view name, int sample, int min, int max,
|
||||||
// int bucket_count);
|
// int bucket_count);
|
||||||
// Histogram* webrtc::metrics::HistogramFactoryGetEnumeration(
|
// Histogram* webrtc::metrics::HistogramFactoryGetEnumeration(
|
||||||
// const std::string& name, int sample, int boundary);
|
// absl::string_view name, int sample, int boundary);
|
||||||
// void webrtc::metrics::HistogramAdd(
|
// void webrtc::metrics::HistogramAdd(
|
||||||
// Histogram* histogram_pointer, const std::string& name, int sample);
|
// Histogram* histogram_pointer, absl::string_view name, int sample);
|
||||||
//
|
//
|
||||||
// Example usage:
|
// Example usage:
|
||||||
//
|
//
|
||||||
|
@ -188,7 +190,6 @@ void NoOp(const Ts&...) {}
|
||||||
webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary))
|
webrtc::metrics::HistogramFactoryGetEnumeration(name, boundary))
|
||||||
|
|
||||||
// The name of the histogram should not vary.
|
// The name of the histogram should not vary.
|
||||||
// TODO(asapersson): Consider changing string to const char*.
|
|
||||||
#define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \
|
#define RTC_HISTOGRAM_COMMON_BLOCK(constant_name, sample, \
|
||||||
factory_get_invocation) \
|
factory_get_invocation) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -371,32 +372,31 @@ class Histogram;
|
||||||
// histogram).
|
// histogram).
|
||||||
|
|
||||||
// Get histogram for counters.
|
// Get histogram for counters.
|
||||||
Histogram* HistogramFactoryGetCounts(const std::string& name,
|
Histogram* HistogramFactoryGetCounts(absl::string_view name,
|
||||||
int min,
|
int min,
|
||||||
int max,
|
int max,
|
||||||
int bucket_count);
|
int bucket_count);
|
||||||
|
|
||||||
// Get histogram for counters with linear bucket spacing.
|
// Get histogram for counters with linear bucket spacing.
|
||||||
Histogram* HistogramFactoryGetCountsLinear(const std::string& name,
|
Histogram* HistogramFactoryGetCountsLinear(absl::string_view name,
|
||||||
int min,
|
int min,
|
||||||
int max,
|
int max,
|
||||||
int bucket_count);
|
int bucket_count);
|
||||||
|
|
||||||
// Get histogram for enumerators.
|
// Get histogram for enumerators.
|
||||||
// `boundary` should be above the max enumerator sample.
|
// `boundary` should be above the max enumerator sample.
|
||||||
Histogram* HistogramFactoryGetEnumeration(const std::string& name,
|
Histogram* HistogramFactoryGetEnumeration(absl::string_view name, int boundary);
|
||||||
int boundary);
|
|
||||||
|
|
||||||
// Get sparse histogram for enumerators.
|
// Get sparse histogram for enumerators.
|
||||||
// `boundary` should be above the max enumerator sample.
|
// `boundary` should be above the max enumerator sample.
|
||||||
Histogram* SparseHistogramFactoryGetEnumeration(const std::string& name,
|
Histogram* SparseHistogramFactoryGetEnumeration(absl::string_view name,
|
||||||
int boundary);
|
int boundary);
|
||||||
|
|
||||||
// Function for adding a `sample` to a histogram.
|
// Function for adding a `sample` to a histogram.
|
||||||
void HistogramAdd(Histogram* histogram_pointer, int sample);
|
void HistogramAdd(Histogram* histogram_pointer, int sample);
|
||||||
|
|
||||||
struct SampleInfo {
|
struct SampleInfo {
|
||||||
SampleInfo(const std::string& name, int min, int max, size_t bucket_count);
|
SampleInfo(absl::string_view name, int min, int max, size_t bucket_count);
|
||||||
~SampleInfo();
|
~SampleInfo();
|
||||||
|
|
||||||
const std::string name;
|
const std::string name;
|
||||||
|
@ -412,7 +412,8 @@ void Enable();
|
||||||
|
|
||||||
// Gets histograms and clears all samples.
|
// Gets histograms and clears all samples.
|
||||||
void GetAndReset(
|
void GetAndReset(
|
||||||
std::map<std::string, std::unique_ptr<SampleInfo>>* histograms);
|
std::map<std::string, std::unique_ptr<SampleInfo>, rtc::AbslStringViewCmp>*
|
||||||
|
histograms);
|
||||||
|
|
||||||
// Functions below are mainly for testing.
|
// Functions below are mainly for testing.
|
||||||
|
|
||||||
|
@ -420,17 +421,17 @@ void GetAndReset(
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
// Returns the number of times the `sample` has been added to the histogram.
|
// Returns the number of times the `sample` has been added to the histogram.
|
||||||
int NumEvents(const std::string& name, int sample);
|
int NumEvents(absl::string_view name, int sample);
|
||||||
|
|
||||||
// Returns the total number of added samples to the histogram.
|
// Returns the total number of added samples to the histogram.
|
||||||
int NumSamples(const std::string& name);
|
int NumSamples(absl::string_view name);
|
||||||
|
|
||||||
// Returns the minimum sample value (or -1 if the histogram has no samples).
|
// Returns the minimum sample value (or -1 if the histogram has no samples).
|
||||||
int MinSample(const std::string& name);
|
int MinSample(absl::string_view name);
|
||||||
|
|
||||||
// Returns a map with keys the samples with at least one event and values the
|
// Returns a map with keys the samples with at least one event and values the
|
||||||
// number of events for that sample.
|
// number of events for that sample.
|
||||||
std::map<int, int> Samples(const std::string& name);
|
std::map<int, int> Samples(absl::string_view name);
|
||||||
|
|
||||||
} // namespace metrics
|
} // namespace metrics
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
|
@ -69,7 +69,7 @@ bool FieldTrialsStringIsValidInternal(const absl::string_view trials) {
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
bool FieldTrialsStringIsValid(const char* trials_string) {
|
bool FieldTrialsStringIsValid(absl::string_view trials_string) {
|
||||||
return FieldTrialsStringIsValidInternal(trials_string);
|
return FieldTrialsStringIsValidInternal(trials_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,8 @@ void InsertOrReplaceFieldTrialStringsInMap(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MergeFieldTrialsStrings(const char* first, const char* second) {
|
std::string MergeFieldTrialsStrings(absl::string_view first,
|
||||||
|
absl::string_view second) {
|
||||||
std::map<std::string, std::string> fieldtrial_map;
|
std::map<std::string, std::string> fieldtrial_map;
|
||||||
InsertOrReplaceFieldTrialStringsInMap(&fieldtrial_map, first);
|
InsertOrReplaceFieldTrialStringsInMap(&fieldtrial_map, first);
|
||||||
InsertOrReplaceFieldTrialStringsInMap(&fieldtrial_map, second);
|
InsertOrReplaceFieldTrialStringsInMap(&fieldtrial_map, second);
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
|
#include "rtc_base/string_utils.h"
|
||||||
#include "rtc_base/synchronization/mutex.h"
|
#include "rtc_base/synchronization/mutex.h"
|
||||||
#include "rtc_base/thread_annotations.h"
|
#include "rtc_base/thread_annotations.h"
|
||||||
|
|
||||||
|
@ -29,7 +31,7 @@ const int kMaxSampleMapSize = 300;
|
||||||
|
|
||||||
class RtcHistogram {
|
class RtcHistogram {
|
||||||
public:
|
public:
|
||||||
RtcHistogram(const std::string& name, int min, int max, int bucket_count)
|
RtcHistogram(absl::string_view name, int min, int max, int bucket_count)
|
||||||
: min_(min), max_(max), info_(name, min, max, bucket_count) {
|
: min_(min), max_(max), info_(name, min, max, bucket_count) {
|
||||||
RTC_DCHECK_GT(bucket_count, 0);
|
RTC_DCHECK_GT(bucket_count, 0);
|
||||||
}
|
}
|
||||||
|
@ -111,7 +113,7 @@ class RtcHistogramMap {
|
||||||
RtcHistogramMap(const RtcHistogramMap&) = delete;
|
RtcHistogramMap(const RtcHistogramMap&) = delete;
|
||||||
RtcHistogramMap& operator=(const RtcHistogramMap&) = delete;
|
RtcHistogramMap& operator=(const RtcHistogramMap&) = delete;
|
||||||
|
|
||||||
Histogram* GetCountsHistogram(const std::string& name,
|
Histogram* GetCountsHistogram(absl::string_view name,
|
||||||
int min,
|
int min,
|
||||||
int max,
|
int max,
|
||||||
int bucket_count) {
|
int bucket_count) {
|
||||||
|
@ -121,23 +123,24 @@ class RtcHistogramMap {
|
||||||
return reinterpret_cast<Histogram*>(it->second.get());
|
return reinterpret_cast<Histogram*>(it->second.get());
|
||||||
|
|
||||||
RtcHistogram* hist = new RtcHistogram(name, min, max, bucket_count);
|
RtcHistogram* hist = new RtcHistogram(name, min, max, bucket_count);
|
||||||
map_[name].reset(hist);
|
map_.emplace(name, hist);
|
||||||
return reinterpret_cast<Histogram*>(hist);
|
return reinterpret_cast<Histogram*>(hist);
|
||||||
}
|
}
|
||||||
|
|
||||||
Histogram* GetEnumerationHistogram(const std::string& name, int boundary) {
|
Histogram* GetEnumerationHistogram(absl::string_view name, int boundary) {
|
||||||
MutexLock lock(&mutex_);
|
MutexLock lock(&mutex_);
|
||||||
const auto& it = map_.find(name);
|
const auto& it = map_.find(name);
|
||||||
if (it != map_.end())
|
if (it != map_.end())
|
||||||
return reinterpret_cast<Histogram*>(it->second.get());
|
return reinterpret_cast<Histogram*>(it->second.get());
|
||||||
|
|
||||||
RtcHistogram* hist = new RtcHistogram(name, 1, boundary, boundary + 1);
|
RtcHistogram* hist = new RtcHistogram(name, 1, boundary, boundary + 1);
|
||||||
map_[name].reset(hist);
|
map_.emplace(name, hist);
|
||||||
return reinterpret_cast<Histogram*>(hist);
|
return reinterpret_cast<Histogram*>(hist);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetAndReset(
|
void GetAndReset(std::map<std::string,
|
||||||
std::map<std::string, std::unique_ptr<SampleInfo>>* histograms) {
|
std::unique_ptr<SampleInfo>,
|
||||||
|
rtc::AbslStringViewCmp>* histograms) {
|
||||||
MutexLock lock(&mutex_);
|
MutexLock lock(&mutex_);
|
||||||
for (const auto& kv : map_) {
|
for (const auto& kv : map_) {
|
||||||
std::unique_ptr<SampleInfo> info = kv.second->GetAndReset();
|
std::unique_ptr<SampleInfo> info = kv.second->GetAndReset();
|
||||||
|
@ -153,25 +156,25 @@ class RtcHistogramMap {
|
||||||
kv.second->Reset();
|
kv.second->Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
int NumEvents(const std::string& name, int sample) const {
|
int NumEvents(absl::string_view name, int sample) const {
|
||||||
MutexLock lock(&mutex_);
|
MutexLock lock(&mutex_);
|
||||||
const auto& it = map_.find(name);
|
const auto& it = map_.find(name);
|
||||||
return (it == map_.end()) ? 0 : it->second->NumEvents(sample);
|
return (it == map_.end()) ? 0 : it->second->NumEvents(sample);
|
||||||
}
|
}
|
||||||
|
|
||||||
int NumSamples(const std::string& name) const {
|
int NumSamples(absl::string_view name) const {
|
||||||
MutexLock lock(&mutex_);
|
MutexLock lock(&mutex_);
|
||||||
const auto& it = map_.find(name);
|
const auto& it = map_.find(name);
|
||||||
return (it == map_.end()) ? 0 : it->second->NumSamples();
|
return (it == map_.end()) ? 0 : it->second->NumSamples();
|
||||||
}
|
}
|
||||||
|
|
||||||
int MinSample(const std::string& name) const {
|
int MinSample(absl::string_view name) const {
|
||||||
MutexLock lock(&mutex_);
|
MutexLock lock(&mutex_);
|
||||||
const auto& it = map_.find(name);
|
const auto& it = map_.find(name);
|
||||||
return (it == map_.end()) ? -1 : it->second->MinSample();
|
return (it == map_.end()) ? -1 : it->second->MinSample();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, int> Samples(const std::string& name) const {
|
std::map<int, int> Samples(absl::string_view name) const {
|
||||||
MutexLock lock(&mutex_);
|
MutexLock lock(&mutex_);
|
||||||
const auto& it = map_.find(name);
|
const auto& it = map_.find(name);
|
||||||
return (it == map_.end()) ? std::map<int, int>() : it->second->Samples();
|
return (it == map_.end()) ? std::map<int, int>() : it->second->Samples();
|
||||||
|
@ -179,8 +182,8 @@ class RtcHistogramMap {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable Mutex mutex_;
|
mutable Mutex mutex_;
|
||||||
std::map<std::string, std::unique_ptr<RtcHistogram>> map_
|
std::map<std::string, std::unique_ptr<RtcHistogram>, rtc::AbslStringViewCmp>
|
||||||
RTC_GUARDED_BY(mutex_);
|
map_ RTC_GUARDED_BY(mutex_);
|
||||||
};
|
};
|
||||||
|
|
||||||
// RtcHistogramMap is allocated upon call to Enable().
|
// RtcHistogramMap is allocated upon call to Enable().
|
||||||
|
@ -223,7 +226,7 @@ RtcHistogramMap* GetMap() {
|
||||||
// Creates (or finds) histogram.
|
// Creates (or finds) histogram.
|
||||||
// The returned histogram pointer is cached (and used for adding samples in
|
// The returned histogram pointer is cached (and used for adding samples in
|
||||||
// subsequent calls).
|
// subsequent calls).
|
||||||
Histogram* HistogramFactoryGetCounts(const std::string& name,
|
Histogram* HistogramFactoryGetCounts(absl::string_view name,
|
||||||
int min,
|
int min,
|
||||||
int max,
|
int max,
|
||||||
int bucket_count) {
|
int bucket_count) {
|
||||||
|
@ -236,7 +239,7 @@ Histogram* HistogramFactoryGetCounts(const std::string& name,
|
||||||
// Creates (or finds) histogram.
|
// Creates (or finds) histogram.
|
||||||
// The returned histogram pointer is cached (and used for adding samples in
|
// The returned histogram pointer is cached (and used for adding samples in
|
||||||
// subsequent calls).
|
// subsequent calls).
|
||||||
Histogram* HistogramFactoryGetCountsLinear(const std::string& name,
|
Histogram* HistogramFactoryGetCountsLinear(absl::string_view name,
|
||||||
int min,
|
int min,
|
||||||
int max,
|
int max,
|
||||||
int bucket_count) {
|
int bucket_count) {
|
||||||
|
@ -251,7 +254,7 @@ Histogram* HistogramFactoryGetCountsLinear(const std::string& name,
|
||||||
// Creates (or finds) histogram.
|
// Creates (or finds) histogram.
|
||||||
// The returned histogram pointer is cached (and used for adding samples in
|
// The returned histogram pointer is cached (and used for adding samples in
|
||||||
// subsequent calls).
|
// subsequent calls).
|
||||||
Histogram* HistogramFactoryGetEnumeration(const std::string& name,
|
Histogram* HistogramFactoryGetEnumeration(absl::string_view name,
|
||||||
int boundary) {
|
int boundary) {
|
||||||
RtcHistogramMap* map = GetMap();
|
RtcHistogramMap* map = GetMap();
|
||||||
if (!map)
|
if (!map)
|
||||||
|
@ -261,7 +264,7 @@ Histogram* HistogramFactoryGetEnumeration(const std::string& name,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our default implementation reuses the non-sparse histogram.
|
// Our default implementation reuses the non-sparse histogram.
|
||||||
Histogram* SparseHistogramFactoryGetEnumeration(const std::string& name,
|
Histogram* SparseHistogramFactoryGetEnumeration(absl::string_view name,
|
||||||
int boundary) {
|
int boundary) {
|
||||||
return HistogramFactoryGetEnumeration(name, boundary);
|
return HistogramFactoryGetEnumeration(name, boundary);
|
||||||
}
|
}
|
||||||
|
@ -274,7 +277,7 @@ void HistogramAdd(Histogram* histogram_pointer, int sample) {
|
||||||
|
|
||||||
#endif // WEBRTC_EXCLUDE_METRICS_DEFAULT
|
#endif // WEBRTC_EXCLUDE_METRICS_DEFAULT
|
||||||
|
|
||||||
SampleInfo::SampleInfo(const std::string& name,
|
SampleInfo::SampleInfo(absl::string_view name,
|
||||||
int min,
|
int min,
|
||||||
int max,
|
int max,
|
||||||
size_t bucket_count)
|
size_t bucket_count)
|
||||||
|
@ -292,7 +295,8 @@ void Enable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetAndReset(
|
void GetAndReset(
|
||||||
std::map<std::string, std::unique_ptr<SampleInfo>>* histograms) {
|
std::map<std::string, std::unique_ptr<SampleInfo>, rtc::AbslStringViewCmp>*
|
||||||
|
histograms) {
|
||||||
histograms->clear();
|
histograms->clear();
|
||||||
RtcHistogramMap* map = GetMap();
|
RtcHistogramMap* map = GetMap();
|
||||||
if (map)
|
if (map)
|
||||||
|
@ -305,22 +309,22 @@ void Reset() {
|
||||||
map->Reset();
|
map->Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
int NumEvents(const std::string& name, int sample) {
|
int NumEvents(absl::string_view name, int sample) {
|
||||||
RtcHistogramMap* map = GetMap();
|
RtcHistogramMap* map = GetMap();
|
||||||
return map ? map->NumEvents(name, sample) : 0;
|
return map ? map->NumEvents(name, sample) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NumSamples(const std::string& name) {
|
int NumSamples(absl::string_view name) {
|
||||||
RtcHistogramMap* map = GetMap();
|
RtcHistogramMap* map = GetMap();
|
||||||
return map ? map->NumSamples(name) : 0;
|
return map ? map->NumSamples(name) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MinSample(const std::string& name) {
|
int MinSample(absl::string_view name) {
|
||||||
RtcHistogramMap* map = GetMap();
|
RtcHistogramMap* map = GetMap();
|
||||||
return map ? map->MinSample(name) : -1;
|
return map ? map->MinSample(name) : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, int> Samples(const std::string& name) {
|
std::map<int, int> Samples(absl::string_view name) {
|
||||||
RtcHistogramMap* map = GetMap();
|
RtcHistogramMap* map = GetMap();
|
||||||
return map ? map->Samples(name) : std::map<int, int>();
|
return map ? map->Samples(name) : std::map<int, int>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
|
#include "rtc_base/string_utils.h"
|
||||||
#include "system_wrappers/include/metrics.h"
|
#include "system_wrappers/include/metrics.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
|
||||||
|
@ -24,10 +25,10 @@ namespace {
|
||||||
const int kSample = 22;
|
const int kSample = 22;
|
||||||
const char kName[] = "Name";
|
const char kName[] = "Name";
|
||||||
|
|
||||||
int NumSamples(
|
int NumSamples(absl::string_view name,
|
||||||
const std::string& name,
|
const std::map<std::string,
|
||||||
const std::map<std::string, std::unique_ptr<metrics::SampleInfo>>&
|
std::unique_ptr<metrics::SampleInfo>,
|
||||||
histograms) {
|
rtc::AbslStringViewCmp>& histograms) {
|
||||||
const auto it = histograms.find(name);
|
const auto it = histograms.find(name);
|
||||||
if (it == histograms.end())
|
if (it == histograms.end())
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -39,10 +40,11 @@ int NumSamples(
|
||||||
return num_samples;
|
return num_samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NumEvents(const std::string& name,
|
int NumEvents(absl::string_view name,
|
||||||
int sample,
|
int sample,
|
||||||
const std::map<std::string, std::unique_ptr<metrics::SampleInfo>>&
|
const std::map<std::string,
|
||||||
histograms) {
|
std::unique_ptr<metrics::SampleInfo>,
|
||||||
|
rtc::AbslStringViewCmp>& histograms) {
|
||||||
const auto it = histograms.find(name);
|
const auto it = histograms.find(name);
|
||||||
if (it == histograms.end())
|
if (it == histograms.end())
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -118,7 +120,9 @@ TEST_F(MetricsDefaultTest, Underflow) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(MetricsDefaultTest, GetAndReset) {
|
TEST_F(MetricsDefaultTest, GetAndReset) {
|
||||||
std::map<std::string, std::unique_ptr<metrics::SampleInfo>> histograms;
|
std::map<std::string, std::unique_ptr<metrics::SampleInfo>,
|
||||||
|
rtc::AbslStringViewCmp>
|
||||||
|
histograms;
|
||||||
metrics::GetAndReset(&histograms);
|
metrics::GetAndReset(&histograms);
|
||||||
EXPECT_EQ(0u, histograms.size());
|
EXPECT_EQ(0u, histograms.size());
|
||||||
RTC_HISTOGRAM_PERCENTAGE("Histogram1", 4);
|
RTC_HISTOGRAM_PERCENTAGE("Histogram1", 4);
|
||||||
|
@ -154,7 +158,9 @@ TEST_F(MetricsDefaultTest, TestMinMaxBucket) {
|
||||||
const std::string kName = "MinMaxCounts100";
|
const std::string kName = "MinMaxCounts100";
|
||||||
RTC_HISTOGRAM_COUNTS_100(kName, 4);
|
RTC_HISTOGRAM_COUNTS_100(kName, 4);
|
||||||
|
|
||||||
std::map<std::string, std::unique_ptr<metrics::SampleInfo>> histograms;
|
std::map<std::string, std::unique_ptr<metrics::SampleInfo>,
|
||||||
|
rtc::AbslStringViewCmp>
|
||||||
|
histograms;
|
||||||
metrics::GetAndReset(&histograms);
|
metrics::GetAndReset(&histograms);
|
||||||
EXPECT_EQ(1u, histograms.size());
|
EXPECT_EQ(1u, histograms.size());
|
||||||
EXPECT_EQ(kName, histograms.begin()->second->name);
|
EXPECT_EQ(kName, histograms.begin()->second->name);
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "system_wrappers/include/metrics.h"
|
#include "system_wrappers/include/metrics.h"
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "test/gmock.h"
|
#include "test/gmock.h"
|
||||||
#include "test/gtest.h"
|
#include "test/gtest.h"
|
||||||
|
|
||||||
|
@ -22,10 +23,10 @@ namespace webrtc {
|
||||||
namespace {
|
namespace {
|
||||||
const int kSample = 22;
|
const int kSample = 22;
|
||||||
|
|
||||||
void AddSparseSample(const std::string& name, int sample) {
|
void AddSparseSample(absl::string_view name, int sample) {
|
||||||
RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample);
|
RTC_HISTOGRAM_COUNTS_SPARSE_100(name, sample);
|
||||||
}
|
}
|
||||||
void AddSampleWithVaryingName(int index, const std::string& name, int sample) {
|
void AddSampleWithVaryingName(int index, absl::string_view name, int sample) {
|
||||||
RTC_HISTOGRAMS_COUNTS_100(index, name, sample);
|
RTC_HISTOGRAMS_COUNTS_100(index, name, sample);
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Reference in a new issue