Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: webrtc/stats/rtcstats.cc

Issue 2241093002: RTCStats and RTCStatsReport added (webrtc/stats) (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/stats/OWNERS ('k') | webrtc/stats/rtcstats_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/stats/rtcstats.cc
diff --git a/webrtc/stats/rtcstats.cc b/webrtc/stats/rtcstats.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1a35739c61758b9cb72d4f14b9ff3edb2f916cf2
--- /dev/null
+++ b/webrtc/stats/rtcstats.cc
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2016 The WebRTC 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 in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/api/rtcstats.h"
+
+#include "webrtc/base/stringencode.h"
+
+namespace webrtc {
+
+namespace {
+
+// Produces "{ a, b, c }". Works for non-vector |RTCStatsMemberInterface::Type|
+// types.
+template<typename T>
+std::string VectorToString(const std::vector<T>& vector) {
+ if (vector.empty())
+ return "{}";
+ std::ostringstream oss;
+ oss << "{ " << rtc::ToString<T>(vector[0]);
+ for (size_t i = 1; i < vector.size(); ++i) {
+ oss << ", " << rtc::ToString<T>(vector[i]);
+ }
+ oss << " }";
+ return oss.str();
+}
+
+// Produces "{ \"a\", \"b\", \"c\" }". Works for vectors of both const char* and
+// std::string element types.
+template<typename T>
+std::string VectorOfStringsToString(const std::vector<T>& strings) {
+ if (strings.empty())
+ return "{}";
+ std::ostringstream oss;
+ oss << "{ \"" << rtc::ToString<T>(strings[0]) << '\"';
+ for (size_t i = 1; i < strings.size(); ++i) {
+ oss << ", \"" << rtc::ToString<T>(strings[i]) << '\"';
+ }
+ oss << " }";
+ return oss.str();
+}
+
+} // namespace
+
+std::string RTCStats::ToString() const {
+ std::ostringstream oss;
+ oss << type() << " {\n id: \"" << id_ << "\"\n timestamp: "
+ << timestamp_ << '\n';
+ for (const RTCStatsMemberInterface* member : Members()) {
+ oss << " " << member->name() << ": ";
+ if (member->is_defined()) {
+ if (member->is_string())
+ oss << '"' << member->ValueToString() << "\"\n";
+ else
+ oss << member->ValueToString() << '\n';
+ } else {
+ oss << "undefined\n";
+ }
+ }
+ oss << '}';
+ return oss.str();
+}
+
+std::vector<const RTCStatsMemberInterface*> RTCStats::Members() const {
+ return MembersOfThisObjectAndAncestors(0);
+}
+
+std::vector<const RTCStatsMemberInterface*>
+RTCStats::MembersOfThisObjectAndAncestors(
+ size_t additional_capacity) const {
+ std::vector<const RTCStatsMemberInterface*> members;
+ members.reserve(additional_capacity);
+ return members;
+}
+
+#define WEBRTC_DEFINE_RTCSTATSMEMBER(T, type, is_seq, is_str, to_str) \
+ template<> \
+ const RTCStatsMemberInterface::Type RTCStatsMember<T>::kType = \
+ RTCStatsMemberInterface::type; \
+ template<> \
+ bool RTCStatsMember<T>::is_sequence() const { return is_seq; } \
+ template<> \
+ bool RTCStatsMember<T>::is_string() const { return is_str; } \
+ template<> \
+ std::string RTCStatsMember<T>::ValueToString() const { \
+ RTC_DCHECK(is_defined_); \
+ return to_str; \
+ }
+
+WEBRTC_DEFINE_RTCSTATSMEMBER(int32_t, kInt32, false, false,
+ rtc::ToString(value_));
+WEBRTC_DEFINE_RTCSTATSMEMBER(uint32_t, kUint32, false, false,
+ rtc::ToString(value_));
+WEBRTC_DEFINE_RTCSTATSMEMBER(int64_t, kInt64, false, false,
+ rtc::ToString(value_));
+WEBRTC_DEFINE_RTCSTATSMEMBER(uint64_t, kUint64, false, false,
+ rtc::ToString(value_));
+WEBRTC_DEFINE_RTCSTATSMEMBER(double, kDouble, false, false,
+ rtc::ToString(value_));
+WEBRTC_DEFINE_RTCSTATSMEMBER(const char*, kStaticString, false, true,
+ value_);
+WEBRTC_DEFINE_RTCSTATSMEMBER(std::string, kString, false, true,
+ value_);
+WEBRTC_DEFINE_RTCSTATSMEMBER(
+ std::vector<int32_t>, kSequenceInt32, true, false,
+ VectorToString(value_));
+WEBRTC_DEFINE_RTCSTATSMEMBER(
+ std::vector<uint32_t>, kSequenceUint32, true, false,
+ VectorToString(value_));
+WEBRTC_DEFINE_RTCSTATSMEMBER(
+ std::vector<int64_t>, kSequenceInt64, true, false,
+ VectorToString(value_));
+WEBRTC_DEFINE_RTCSTATSMEMBER(
+ std::vector<uint64_t>, kSequenceUint64, true, false,
+ VectorToString(value_));
+WEBRTC_DEFINE_RTCSTATSMEMBER(
+ std::vector<double>, kSequenceDouble, true, false,
+ VectorToString(value_));
+WEBRTC_DEFINE_RTCSTATSMEMBER(
+ std::vector<const char*>, kSequenceStaticString, true, false,
+ VectorOfStringsToString(value_));
+WEBRTC_DEFINE_RTCSTATSMEMBER(
+ std::vector<std::string>, kSequenceString, true, false,
+ VectorOfStringsToString(value_));
+
+} // namespace webrtc
« no previous file with comments | « webrtc/stats/OWNERS ('k') | webrtc/stats/rtcstats_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698