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

Side by Side 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, 3 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 unified diff | Download patch
« no previous file with comments | « webrtc/stats/OWNERS ('k') | webrtc/stats/rtcstats_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/api/rtcstats.h"
12
13 #include "webrtc/base/stringencode.h"
14
15 namespace webrtc {
16
17 namespace {
18
19 // Produces "{ a, b, c }". Works for non-vector |RTCStatsMemberInterface::Type|
20 // types.
21 template<typename T>
22 std::string VectorToString(const std::vector<T>& vector) {
23 if (vector.empty())
24 return "{}";
25 std::ostringstream oss;
26 oss << "{ " << rtc::ToString<T>(vector[0]);
27 for (size_t i = 1; i < vector.size(); ++i) {
28 oss << ", " << rtc::ToString<T>(vector[i]);
29 }
30 oss << " }";
31 return oss.str();
32 }
33
34 // Produces "{ \"a\", \"b\", \"c\" }". Works for vectors of both const char* and
35 // std::string element types.
36 template<typename T>
37 std::string VectorOfStringsToString(const std::vector<T>& strings) {
38 if (strings.empty())
39 return "{}";
40 std::ostringstream oss;
41 oss << "{ \"" << rtc::ToString<T>(strings[0]) << '\"';
42 for (size_t i = 1; i < strings.size(); ++i) {
43 oss << ", \"" << rtc::ToString<T>(strings[i]) << '\"';
44 }
45 oss << " }";
46 return oss.str();
47 }
48
49 } // namespace
50
51 std::string RTCStats::ToString() const {
52 std::ostringstream oss;
53 oss << type() << " {\n id: \"" << id_ << "\"\n timestamp: "
54 << timestamp_ << '\n';
55 for (const RTCStatsMemberInterface* member : Members()) {
56 oss << " " << member->name() << ": ";
57 if (member->is_defined()) {
58 if (member->is_string())
59 oss << '"' << member->ValueToString() << "\"\n";
60 else
61 oss << member->ValueToString() << '\n';
62 } else {
63 oss << "undefined\n";
64 }
65 }
66 oss << '}';
67 return oss.str();
68 }
69
70 std::vector<const RTCStatsMemberInterface*> RTCStats::Members() const {
71 return MembersOfThisObjectAndAncestors(0);
72 }
73
74 std::vector<const RTCStatsMemberInterface*>
75 RTCStats::MembersOfThisObjectAndAncestors(
76 size_t additional_capacity) const {
77 std::vector<const RTCStatsMemberInterface*> members;
78 members.reserve(additional_capacity);
79 return members;
80 }
81
82 #define WEBRTC_DEFINE_RTCSTATSMEMBER(T, type, is_seq, is_str, to_str) \
83 template<> \
84 const RTCStatsMemberInterface::Type RTCStatsMember<T>::kType = \
85 RTCStatsMemberInterface::type; \
86 template<> \
87 bool RTCStatsMember<T>::is_sequence() const { return is_seq; } \
88 template<> \
89 bool RTCStatsMember<T>::is_string() const { return is_str; } \
90 template<> \
91 std::string RTCStatsMember<T>::ValueToString() const { \
92 RTC_DCHECK(is_defined_); \
93 return to_str; \
94 }
95
96 WEBRTC_DEFINE_RTCSTATSMEMBER(int32_t, kInt32, false, false,
97 rtc::ToString(value_));
98 WEBRTC_DEFINE_RTCSTATSMEMBER(uint32_t, kUint32, false, false,
99 rtc::ToString(value_));
100 WEBRTC_DEFINE_RTCSTATSMEMBER(int64_t, kInt64, false, false,
101 rtc::ToString(value_));
102 WEBRTC_DEFINE_RTCSTATSMEMBER(uint64_t, kUint64, false, false,
103 rtc::ToString(value_));
104 WEBRTC_DEFINE_RTCSTATSMEMBER(double, kDouble, false, false,
105 rtc::ToString(value_));
106 WEBRTC_DEFINE_RTCSTATSMEMBER(const char*, kStaticString, false, true,
107 value_);
108 WEBRTC_DEFINE_RTCSTATSMEMBER(std::string, kString, false, true,
109 value_);
110 WEBRTC_DEFINE_RTCSTATSMEMBER(
111 std::vector<int32_t>, kSequenceInt32, true, false,
112 VectorToString(value_));
113 WEBRTC_DEFINE_RTCSTATSMEMBER(
114 std::vector<uint32_t>, kSequenceUint32, true, false,
115 VectorToString(value_));
116 WEBRTC_DEFINE_RTCSTATSMEMBER(
117 std::vector<int64_t>, kSequenceInt64, true, false,
118 VectorToString(value_));
119 WEBRTC_DEFINE_RTCSTATSMEMBER(
120 std::vector<uint64_t>, kSequenceUint64, true, false,
121 VectorToString(value_));
122 WEBRTC_DEFINE_RTCSTATSMEMBER(
123 std::vector<double>, kSequenceDouble, true, false,
124 VectorToString(value_));
125 WEBRTC_DEFINE_RTCSTATSMEMBER(
126 std::vector<const char*>, kSequenceStaticString, true, false,
127 VectorOfStringsToString(value_));
128 WEBRTC_DEFINE_RTCSTATSMEMBER(
129 std::vector<std::string>, kSequenceString, true, false,
130 VectorOfStringsToString(value_));
131
132 } // namespace webrtc
OLDNEW
« 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