tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2014 The WebRTC project authors. All Rights Reserved. |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 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. |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #include "api/statstypes.h" |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 | [diff] [blame] | 12 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 13 | #include <string.h> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 15 | #include "rtc_base/checks.h" |
Niels Möller | 84255bb | 2017-10-06 11:43:23 | [diff] [blame] | 16 | #include "rtc_base/refcountedobject.h" |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 17 | |
| 18 | // TODO(tommi): Could we have a static map of value name -> expected type |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 19 | // and use this to RTC_DCHECK on correct usage (somewhat strongly typed values)? |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 20 | // Alternatively, we could define the names+type in a separate document and |
| 21 | // generate strongly typed inline C++ code that forces the correct type to be |
| 22 | // used for a given name at compile time. |
| 23 | |
tommi@webrtc.org | 4b89aa0 | 2015-03-16 09:52:30 | [diff] [blame] | 24 | using rtc::RefCountedObject; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 25 | |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 | [diff] [blame] | 26 | namespace webrtc { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 27 | namespace { |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 | [diff] [blame] | 28 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 29 | // The id of StatsReport of type kStatsReportTypeBwe. |
| 30 | const char kStatsReportVideoBweId[] = "bweforvideo"; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 31 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 32 | // NOTE: These names need to be consistent with an external |
| 33 | // specification (W3C Stats Identifiers). |
| 34 | const char* InternalTypeToString(StatsReport::StatsType type) { |
| 35 | switch (type) { |
| 36 | case StatsReport::kStatsReportTypeSession: |
| 37 | return "googLibjingleSession"; |
| 38 | case StatsReport::kStatsReportTypeBwe: |
| 39 | return "VideoBwe"; |
| 40 | case StatsReport::kStatsReportTypeRemoteSsrc: |
| 41 | return "remoteSsrc"; |
| 42 | case StatsReport::kStatsReportTypeSsrc: |
| 43 | return "ssrc"; |
| 44 | case StatsReport::kStatsReportTypeTrack: |
| 45 | return "googTrack"; |
| 46 | case StatsReport::kStatsReportTypeIceLocalCandidate: |
| 47 | return "localcandidate"; |
| 48 | case StatsReport::kStatsReportTypeIceRemoteCandidate: |
| 49 | return "remotecandidate"; |
| 50 | case StatsReport::kStatsReportTypeTransport: |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 51 | return "transport"; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 52 | case StatsReport::kStatsReportTypeComponent: |
| 53 | return "googComponent"; |
| 54 | case StatsReport::kStatsReportTypeCandidatePair: |
| 55 | return "googCandidatePair"; |
| 56 | case StatsReport::kStatsReportTypeCertificate: |
| 57 | return "googCertificate"; |
| 58 | case StatsReport::kStatsReportTypeDataChannel: |
| 59 | return "datachannel"; |
| 60 | } |
nisse | eb4ca4e | 2017-01-12 10:24:27 | [diff] [blame] | 61 | RTC_NOTREACHED(); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 62 | return nullptr; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 63 | } |
| 64 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 65 | class BandwidthEstimationId : public StatsReport::IdBase { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 66 | public: |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 67 | BandwidthEstimationId() |
| 68 | : StatsReport::IdBase(StatsReport::kStatsReportTypeBwe) {} |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 69 | std::string ToString() const override { return kStatsReportVideoBweId; } |
| 70 | }; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 71 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 72 | class TypedId : public StatsReport::IdBase { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 73 | public: |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 74 | TypedId(StatsReport::StatsType type, const std::string& id) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 75 | : StatsReport::IdBase(type), id_(id) {} |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 76 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 77 | bool Equals(const IdBase& other) const override { |
| 78 | return IdBase::Equals(other) && |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 79 | static_cast<const TypedId&>(other).id_ == id_; |
| 80 | } |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 81 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 82 | std::string ToString() const override { |
| 83 | return std::string(InternalTypeToString(type_)) + kSeparator + id_; |
| 84 | } |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 85 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 86 | protected: |
| 87 | const std::string id_; |
| 88 | }; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 89 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 90 | class TypedIntId : public StatsReport::IdBase { |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 | [diff] [blame] | 91 | public: |
| 92 | TypedIntId(StatsReport::StatsType type, int id) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 93 | : StatsReport::IdBase(type), id_(id) {} |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 | [diff] [blame] | 94 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 95 | bool Equals(const IdBase& other) const override { |
| 96 | return IdBase::Equals(other) && |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 | [diff] [blame] | 97 | static_cast<const TypedIntId&>(other).id_ == id_; |
| 98 | } |
| 99 | |
| 100 | std::string ToString() const override { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 101 | return std::string(InternalTypeToString(type_)) + kSeparator + |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 | [diff] [blame] | 102 | rtc::ToString<int>(id_); |
| 103 | } |
| 104 | |
| 105 | protected: |
| 106 | const int id_; |
| 107 | }; |
| 108 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 109 | class IdWithDirection : public TypedId { |
| 110 | public: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 111 | IdWithDirection(StatsReport::StatsType type, |
| 112 | const std::string& id, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 113 | StatsReport::Direction direction) |
| 114 | : TypedId(type, id), direction_(direction) {} |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 115 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 116 | bool Equals(const IdBase& other) const override { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 117 | return TypedId::Equals(other) && |
| 118 | static_cast<const IdWithDirection&>(other).direction_ == direction_; |
| 119 | } |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 120 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 121 | std::string ToString() const override { |
| 122 | std::string ret(TypedId::ToString()); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 | [diff] [blame] | 123 | ret += kSeparator; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 124 | ret += direction_ == StatsReport::kSend ? "send" : "recv"; |
| 125 | return ret; |
| 126 | } |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 127 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 128 | private: |
| 129 | const StatsReport::Direction direction_; |
| 130 | }; |
| 131 | |
| 132 | class CandidateId : public TypedId { |
| 133 | public: |
| 134 | CandidateId(bool local, const std::string& id) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 135 | : TypedId(local ? StatsReport::kStatsReportTypeIceLocalCandidate |
| 136 | : StatsReport::kStatsReportTypeIceRemoteCandidate, |
| 137 | id) {} |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 138 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 139 | std::string ToString() const override { return "Cand-" + id_; } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 140 | }; |
| 141 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 142 | class ComponentId : public StatsReport::IdBase { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 143 | public: |
| 144 | ComponentId(const std::string& content_name, int component) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 145 | : ComponentId(StatsReport::kStatsReportTypeComponent, |
| 146 | content_name, |
| 147 | component) {} |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 148 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 149 | bool Equals(const IdBase& other) const override { |
| 150 | return IdBase::Equals(other) && |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 151 | static_cast<const ComponentId&>(other).component_ == component_ && |
| 152 | static_cast<const ComponentId&>(other).content_name_ == |
| 153 | content_name_; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 154 | } |
| 155 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 156 | std::string ToString() const override { return ToString("Channel-"); } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 157 | |
| 158 | protected: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 159 | ComponentId(StatsReport::StatsType type, |
| 160 | const std::string& content_name, |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 161 | int component) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 162 | : IdBase(type), content_name_(content_name), component_(component) {} |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 163 | |
| 164 | std::string ToString(const char* prefix) const { |
| 165 | std::string ret(prefix); |
| 166 | ret += content_name_; |
| 167 | ret += '-'; |
| 168 | ret += rtc::ToString<>(component_); |
| 169 | return ret; |
| 170 | } |
| 171 | |
| 172 | private: |
| 173 | const std::string content_name_; |
| 174 | const int component_; |
| 175 | }; |
| 176 | |
| 177 | class CandidatePairId : public ComponentId { |
| 178 | public: |
| 179 | CandidatePairId(const std::string& content_name, int component, int index) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 180 | : ComponentId(StatsReport::kStatsReportTypeCandidatePair, |
| 181 | content_name, |
| 182 | component), |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 183 | index_(index) {} |
| 184 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 185 | bool Equals(const IdBase& other) const override { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 186 | return ComponentId::Equals(other) && |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 187 | static_cast<const CandidatePairId&>(other).index_ == index_; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | std::string ToString() const override { |
| 191 | std::string ret(ComponentId::ToString("Conn-")); |
| 192 | ret += '-'; |
| 193 | ret += rtc::ToString<>(index_); |
| 194 | return ret; |
| 195 | } |
| 196 | |
| 197 | private: |
| 198 | const int index_; |
| 199 | }; |
| 200 | |
| 201 | } // namespace |
| 202 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 203 | StatsReport::IdBase::IdBase(StatsType type) : type_(type) {} |
| 204 | StatsReport::IdBase::~IdBase() {} |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 205 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 206 | StatsReport::StatsType StatsReport::IdBase::type() const { |
| 207 | return type_; |
| 208 | } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 209 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 210 | bool StatsReport::IdBase::Equals(const IdBase& other) const { |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 211 | return other.type_ == type_; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 212 | } |
| 213 | |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 214 | StatsReport::Value::Value(StatsValueName name, int64_t value, Type int_type) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 215 | : name(name), type_(int_type) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 216 | RTC_DCHECK(type_ == kInt || type_ == kInt64); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 217 | type_ == kInt ? value_.int_ = static_cast<int>(value) : value_.int64_ = value; |
| 218 | } |
| 219 | |
| 220 | StatsReport::Value::Value(StatsValueName name, float f) |
| 221 | : name(name), type_(kFloat) { |
| 222 | value_.float_ = f; |
| 223 | } |
| 224 | |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 225 | StatsReport::Value::Value(StatsValueName name, const std::string& value) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 226 | : name(name), type_(kString) { |
| 227 | value_.string_ = new std::string(value); |
| 228 | } |
| 229 | |
| 230 | StatsReport::Value::Value(StatsValueName name, const char* value) |
| 231 | : name(name), type_(kStaticString) { |
| 232 | value_.static_string_ = value; |
| 233 | } |
| 234 | |
| 235 | StatsReport::Value::Value(StatsValueName name, bool b) |
| 236 | : name(name), type_(kBool) { |
| 237 | value_.bool_ = b; |
| 238 | } |
| 239 | |
| 240 | StatsReport::Value::Value(StatsValueName name, const Id& value) |
| 241 | : name(name), type_(kId) { |
| 242 | value_.id_ = new Id(value); |
| 243 | } |
| 244 | |
| 245 | StatsReport::Value::~Value() { |
| 246 | switch (type_) { |
| 247 | case kInt: |
| 248 | case kInt64: |
| 249 | case kFloat: |
| 250 | case kBool: |
| 251 | case kStaticString: |
| 252 | break; |
| 253 | case kString: |
| 254 | delete value_.string_; |
| 255 | break; |
| 256 | case kId: |
| 257 | delete value_.id_; |
| 258 | break; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | bool StatsReport::Value::Equals(const Value& other) const { |
| 263 | if (name != other.name) |
| 264 | return false; |
| 265 | |
| 266 | // There's a 1:1 relation between a name and a type, so we don't have to |
| 267 | // check that. |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 268 | RTC_DCHECK_EQ(type_, other.type_); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 269 | |
| 270 | switch (type_) { |
| 271 | case kInt: |
| 272 | return value_.int_ == other.value_.int_; |
| 273 | case kInt64: |
| 274 | return value_.int64_ == other.value_.int64_; |
| 275 | case kFloat: |
| 276 | return value_.float_ == other.value_.float_; |
| 277 | case kStaticString: { |
kwiberg | 5377bc7 | 2016-10-04 20:46:56 | [diff] [blame] | 278 | #if RTC_DCHECK_IS_ON |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 279 | if (value_.static_string_ != other.value_.static_string_) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 280 | RTC_DCHECK(strcmp(value_.static_string_, other.value_.static_string_) != |
| 281 | 0) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 282 | << "Duplicate global?"; |
| 283 | } |
| 284 | #endif |
| 285 | return value_.static_string_ == other.value_.static_string_; |
| 286 | } |
| 287 | case kString: |
| 288 | return *value_.string_ == *other.value_.string_; |
| 289 | case kBool: |
| 290 | return value_.bool_ == other.value_.bool_; |
| 291 | case kId: |
| 292 | return (*value_.id_)->Equals(*other.value_.id_); |
| 293 | } |
| 294 | RTC_NOTREACHED(); |
| 295 | return false; |
| 296 | } |
| 297 | |
| 298 | bool StatsReport::Value::operator==(const std::string& value) const { |
| 299 | return (type_ == kString && value_.string_->compare(value) == 0) || |
| 300 | (type_ == kStaticString && value.compare(value_.static_string_) == 0); |
| 301 | } |
| 302 | |
| 303 | bool StatsReport::Value::operator==(const char* value) const { |
| 304 | if (type_ == kString) |
| 305 | return value_.string_->compare(value) == 0; |
| 306 | if (type_ != kStaticString) |
| 307 | return false; |
kwiberg | 5377bc7 | 2016-10-04 20:46:56 | [diff] [blame] | 308 | #if RTC_DCHECK_IS_ON |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 309 | if (value_.static_string_ != value) |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 310 | RTC_DCHECK(strcmp(value_.static_string_, value) != 0) |
| 311 | << "Duplicate global?"; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 312 | #endif |
| 313 | return value == value_.static_string_; |
| 314 | } |
| 315 | |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 316 | bool StatsReport::Value::operator==(int64_t value) const { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 317 | return type_ == kInt ? value_.int_ == static_cast<int>(value) |
| 318 | : (type_ == kInt64 ? value_.int64_ == value : false); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | bool StatsReport::Value::operator==(bool value) const { |
| 322 | return type_ == kBool && value_.bool_ == value; |
| 323 | } |
| 324 | |
| 325 | bool StatsReport::Value::operator==(float value) const { |
| 326 | return type_ == kFloat && value_.float_ == value; |
| 327 | } |
| 328 | |
| 329 | bool StatsReport::Value::operator==(const Id& value) const { |
| 330 | return type_ == kId && (*value_.id_)->Equals(value); |
| 331 | } |
| 332 | |
| 333 | int StatsReport::Value::int_val() const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 334 | RTC_DCHECK(type_ == kInt); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 335 | return value_.int_; |
| 336 | } |
| 337 | |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 338 | int64_t StatsReport::Value::int64_val() const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 339 | RTC_DCHECK(type_ == kInt64); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 340 | return value_.int64_; |
| 341 | } |
| 342 | |
| 343 | float StatsReport::Value::float_val() const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 344 | RTC_DCHECK(type_ == kFloat); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 345 | return value_.float_; |
| 346 | } |
| 347 | |
| 348 | const char* StatsReport::Value::static_string_val() const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 349 | RTC_DCHECK(type_ == kStaticString); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 350 | return value_.static_string_; |
| 351 | } |
| 352 | |
| 353 | const std::string& StatsReport::Value::string_val() const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 354 | RTC_DCHECK(type_ == kString); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 355 | return *value_.string_; |
| 356 | } |
| 357 | |
| 358 | bool StatsReport::Value::bool_val() const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 359 | RTC_DCHECK(type_ == kBool); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 360 | return value_.bool_; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 361 | } |
| 362 | |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 363 | const char* StatsReport::Value::display_name() const { |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 364 | switch (name) { |
Minyue | 2a8a78c | 2016-04-07 14:48:15 | [diff] [blame] | 365 | case kStatsValueNameAecDivergentFilterFraction: |
| 366 | return "aecDivergentFilterFraction"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 367 | case kStatsValueNameAudioOutputLevel: |
| 368 | return "audioOutputLevel"; |
| 369 | case kStatsValueNameAudioInputLevel: |
| 370 | return "audioInputLevel"; |
| 371 | case kStatsValueNameBytesSent: |
| 372 | return "bytesSent"; |
Steve Anton | 2dbc69f | 2017-08-25 00:15:13 | [diff] [blame] | 373 | case kStatsValueNameConcealedSamples: |
| 374 | return "concealedSamples"; |
Gustaf Ullberg | 9a2e906 | 2017-09-18 07:28:20 | [diff] [blame] | 375 | case kStatsValueNameConcealmentEvents: |
| 376 | return "concealmentEvents"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 377 | case kStatsValueNamePacketsSent: |
| 378 | return "packetsSent"; |
| 379 | case kStatsValueNameBytesReceived: |
| 380 | return "bytesReceived"; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 | [diff] [blame] | 381 | case kStatsValueNameLabel: |
| 382 | return "label"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 383 | case kStatsValueNamePacketsReceived: |
| 384 | return "packetsReceived"; |
| 385 | case kStatsValueNamePacketsLost: |
| 386 | return "packetsLost"; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 | [diff] [blame] | 387 | case kStatsValueNameProtocol: |
| 388 | return "protocol"; |
Steve Anton | 2dbc69f | 2017-08-25 00:15:13 | [diff] [blame] | 389 | case kStatsValueNameTotalSamplesReceived: |
| 390 | return "totalSamplesReceived"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 391 | case kStatsValueNameTransportId: |
| 392 | return "transportId"; |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 393 | case kStatsValueNameSelectedCandidatePairId: |
| 394 | return "selectedCandidatePairId"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 395 | case kStatsValueNameSsrc: |
| 396 | return "ssrc"; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 | [diff] [blame] | 397 | case kStatsValueNameState: |
| 398 | return "state"; |
| 399 | case kStatsValueNameDataChannelId: |
| 400 | return "datachannelid"; |
sakal | e5ba44e | 2016-10-26 14:09:24 | [diff] [blame] | 401 | case kStatsValueNameFramesDecoded: |
| 402 | return "framesDecoded"; |
sakal | 43536c3 | 2016-10-24 08:46:43 | [diff] [blame] | 403 | case kStatsValueNameFramesEncoded: |
| 404 | return "framesEncoded"; |
Gustaf Ullberg | b0a0207 | 2017-10-02 10:00:34 | [diff] [blame] | 405 | case kStatsValueNameJitterBufferDelay: |
| 406 | return "jitterBufferDelay"; |
Peter Boström | b7d9a97 | 2015-12-18 15:01:11 | [diff] [blame] | 407 | case kStatsValueNameCodecImplementationName: |
| 408 | return "codecImplementationName"; |
fippo | bec70ab | 2016-01-28 09:27:15 | [diff] [blame] | 409 | case kStatsValueNameMediaType: |
| 410 | return "mediaType"; |
sakal | 87da404 | 2016-10-31 13:53:47 | [diff] [blame] | 411 | case kStatsValueNameQpSum: |
| 412 | return "qpSum"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 413 | // 'goog' prefixed constants. |
Henrik Lundin | 8e6fd46 | 2015-06-02 07:24:52 | [diff] [blame] | 414 | case kStatsValueNameAccelerateRate: |
| 415 | return "googAccelerateRate"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 416 | case kStatsValueNameActiveConnection: |
| 417 | return "googActiveConnection"; |
| 418 | case kStatsValueNameActualEncBitrate: |
| 419 | return "googActualEncBitrate"; |
| 420 | case kStatsValueNameAvailableReceiveBandwidth: |
| 421 | return "googAvailableReceiveBandwidth"; |
| 422 | case kStatsValueNameAvailableSendBandwidth: |
| 423 | return "googAvailableSendBandwidth"; |
| 424 | case kStatsValueNameAvgEncodeMs: |
| 425 | return "googAvgEncodeMs"; |
| 426 | case kStatsValueNameBucketDelay: |
| 427 | return "googBucketDelay"; |
| 428 | case kStatsValueNameBandwidthLimitedResolution: |
| 429 | return "googBandwidthLimitedResolution"; |
zhihuang | 5ecf16c | 2016-06-02 00:09:15 | [diff] [blame] | 430 | // STUN ping related attributes. |
Qingsi Wang | 72a43a1 | 2018-02-21 00:03:18 | [diff] [blame] | 431 | // |
zhihuang | 5ecf16c | 2016-06-02 00:09:15 | [diff] [blame] | 432 | // TODO(zhihuang) Rename these stats to follow the standards. |
Qingsi Wang | 72a43a1 | 2018-02-21 00:03:18 | [diff] [blame] | 433 | // Connectivity checks. |
zhihuang | 5ecf16c | 2016-06-02 00:09:15 | [diff] [blame] | 434 | case kStatsValueNameSentPingRequestsTotal: |
| 435 | return "requestsSent"; |
| 436 | case kStatsValueNameSentPingRequestsBeforeFirstResponse: |
| 437 | return "consentRequestsSent"; |
| 438 | case kStatsValueNameSentPingResponses: |
| 439 | return "responsesSent"; |
| 440 | case kStatsValueNameRecvPingRequests: |
| 441 | return "requestsReceived"; |
| 442 | case kStatsValueNameRecvPingResponses: |
| 443 | return "responsesReceived"; |
Qingsi Wang | 72a43a1 | 2018-02-21 00:03:18 | [diff] [blame] | 444 | // STUN Keepalive pings. |
| 445 | case kStatsValueNameSentStunKeepaliveRequests: |
| 446 | return "stunKeepaliveRequestsSent"; |
| 447 | case kStatsValueNameRecvStunKeepaliveResponses: |
| 448 | return "stunKeepaliveResponsesReceived"; |
| 449 | case kStatsValueNameStunKeepaliveRttTotal: |
| 450 | return "stunKeepaliveRttTotal"; |
| 451 | case kStatsValueNameStunKeepaliveRttSquaredTotal: |
| 452 | return "stunKeepaliveRttSquaredTotal"; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 453 | |
| 454 | // Candidate related attributes. Values are taken from |
| 455 | // http://w3c.github.io/webrtc-stats/#rtcstatstype-enum*. |
| 456 | case kStatsValueNameCandidateIPAddress: |
| 457 | return "ipAddress"; |
| 458 | case kStatsValueNameCandidateNetworkType: |
| 459 | return "networkType"; |
| 460 | case kStatsValueNameCandidatePortNumber: |
| 461 | return "portNumber"; |
| 462 | case kStatsValueNameCandidatePriority: |
| 463 | return "priority"; |
| 464 | case kStatsValueNameCandidateTransportType: |
| 465 | return "transport"; |
| 466 | case kStatsValueNameCandidateType: |
| 467 | return "candidateType"; |
| 468 | |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 469 | case kStatsValueNameChannelId: |
| 470 | return "googChannelId"; |
| 471 | case kStatsValueNameCodecName: |
| 472 | return "googCodecName"; |
| 473 | case kStatsValueNameComponent: |
| 474 | return "googComponent"; |
| 475 | case kStatsValueNameContentName: |
| 476 | return "googContentName"; |
ilnik | 2e1b40b | 2017-09-04 14:57:17 | [diff] [blame] | 477 | case kStatsValueNameContentType: |
| 478 | return "googContentType"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 479 | case kStatsValueNameCpuLimitedResolution: |
| 480 | return "googCpuLimitedResolution"; |
| 481 | case kStatsValueNameDecodingCTSG: |
| 482 | return "googDecodingCTSG"; |
| 483 | case kStatsValueNameDecodingCTN: |
| 484 | return "googDecodingCTN"; |
henrik.lundin | 6348978 | 2016-09-20 08:47:12 | [diff] [blame] | 485 | case kStatsValueNameDecodingMutedOutput: |
| 486 | return "googDecodingMuted"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 487 | case kStatsValueNameDecodingNormal: |
| 488 | return "googDecodingNormal"; |
| 489 | case kStatsValueNameDecodingPLC: |
| 490 | return "googDecodingPLC"; |
| 491 | case kStatsValueNameDecodingCNG: |
| 492 | return "googDecodingCNG"; |
| 493 | case kStatsValueNameDecodingPLCCNG: |
| 494 | return "googDecodingPLCCNG"; |
| 495 | case kStatsValueNameDer: |
| 496 | return "googDerBase64"; |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 497 | case kStatsValueNameDtlsCipher: |
| 498 | return "dtlsCipher"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 499 | case kStatsValueNameEchoDelayMedian: |
| 500 | return "googEchoCancellationEchoDelayMedian"; |
| 501 | case kStatsValueNameEchoDelayStdDev: |
| 502 | return "googEchoCancellationEchoDelayStdDev"; |
| 503 | case kStatsValueNameEchoReturnLoss: |
| 504 | return "googEchoCancellationReturnLoss"; |
| 505 | case kStatsValueNameEchoReturnLossEnhancement: |
| 506 | return "googEchoCancellationReturnLossEnhancement"; |
| 507 | case kStatsValueNameEncodeUsagePercent: |
| 508 | return "googEncodeUsagePercent"; |
| 509 | case kStatsValueNameExpandRate: |
| 510 | return "googExpandRate"; |
| 511 | case kStatsValueNameFingerprint: |
| 512 | return "googFingerprint"; |
| 513 | case kStatsValueNameFingerprintAlgorithm: |
| 514 | return "googFingerprintAlgorithm"; |
| 515 | case kStatsValueNameFirsReceived: |
| 516 | return "googFirsReceived"; |
| 517 | case kStatsValueNameFirsSent: |
| 518 | return "googFirsSent"; |
| 519 | case kStatsValueNameFrameHeightInput: |
| 520 | return "googFrameHeightInput"; |
| 521 | case kStatsValueNameFrameHeightReceived: |
| 522 | return "googFrameHeightReceived"; |
| 523 | case kStatsValueNameFrameHeightSent: |
| 524 | return "googFrameHeightSent"; |
| 525 | case kStatsValueNameFrameRateReceived: |
| 526 | return "googFrameRateReceived"; |
| 527 | case kStatsValueNameFrameRateDecoded: |
| 528 | return "googFrameRateDecoded"; |
| 529 | case kStatsValueNameFrameRateOutput: |
| 530 | return "googFrameRateOutput"; |
| 531 | case kStatsValueNameDecodeMs: |
| 532 | return "googDecodeMs"; |
| 533 | case kStatsValueNameMaxDecodeMs: |
| 534 | return "googMaxDecodeMs"; |
| 535 | case kStatsValueNameCurrentDelayMs: |
| 536 | return "googCurrentDelayMs"; |
| 537 | case kStatsValueNameTargetDelayMs: |
| 538 | return "googTargetDelayMs"; |
| 539 | case kStatsValueNameJitterBufferMs: |
| 540 | return "googJitterBufferMs"; |
| 541 | case kStatsValueNameMinPlayoutDelayMs: |
| 542 | return "googMinPlayoutDelayMs"; |
| 543 | case kStatsValueNameRenderDelayMs: |
| 544 | return "googRenderDelayMs"; |
| 545 | case kStatsValueNameCaptureStartNtpTimeMs: |
| 546 | return "googCaptureStartNtpTimeMs"; |
| 547 | case kStatsValueNameFrameRateInput: |
| 548 | return "googFrameRateInput"; |
| 549 | case kStatsValueNameFrameRateSent: |
| 550 | return "googFrameRateSent"; |
| 551 | case kStatsValueNameFrameWidthInput: |
| 552 | return "googFrameWidthInput"; |
| 553 | case kStatsValueNameFrameWidthReceived: |
| 554 | return "googFrameWidthReceived"; |
| 555 | case kStatsValueNameFrameWidthSent: |
| 556 | return "googFrameWidthSent"; |
Åsa Persson | c3ed630 | 2017-11-16 13:04:52 | [diff] [blame] | 557 | case kStatsValueNameHasEnteredLowResolution: |
| 558 | return "googHasEnteredLowResolution"; |
Ilya Nikolaevskiy | 70473fc | 2018-02-28 15:35:03 | [diff] [blame] | 559 | case kStatsValueNameHugeFramesSent: |
| 560 | return "hugeFramesSent"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 561 | case kStatsValueNameInitiator: |
| 562 | return "googInitiator"; |
ilnik | a79cc28 | 2017-08-23 12:24:10 | [diff] [blame] | 563 | case kStatsValueNameInterframeDelayMaxMs: |
| 564 | return "googInterframeDelayMax"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 565 | case kStatsValueNameIssuerId: |
| 566 | return "googIssuerId"; |
| 567 | case kStatsValueNameJitterReceived: |
| 568 | return "googJitterReceived"; |
| 569 | case kStatsValueNameLocalAddress: |
| 570 | return "googLocalAddress"; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 571 | case kStatsValueNameLocalCandidateId: |
| 572 | return "localCandidateId"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 573 | case kStatsValueNameLocalCandidateType: |
| 574 | return "googLocalCandidateType"; |
| 575 | case kStatsValueNameLocalCertificateId: |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 576 | return "localCertificateId"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 577 | case kStatsValueNameAdaptationChanges: |
| 578 | return "googAdaptationChanges"; |
| 579 | case kStatsValueNameNacksReceived: |
| 580 | return "googNacksReceived"; |
| 581 | case kStatsValueNameNacksSent: |
| 582 | return "googNacksSent"; |
Henrik Lundin | 8e6fd46 | 2015-06-02 07:24:52 | [diff] [blame] | 583 | case kStatsValueNamePreemptiveExpandRate: |
| 584 | return "googPreemptiveExpandRate"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 585 | case kStatsValueNamePlisReceived: |
| 586 | return "googPlisReceived"; |
| 587 | case kStatsValueNamePlisSent: |
| 588 | return "googPlisSent"; |
| 589 | case kStatsValueNamePreferredJitterBufferMs: |
| 590 | return "googPreferredJitterBufferMs"; |
Peter Thatcher | 04ac81f | 2015-09-21 18:48:28 | [diff] [blame] | 591 | case kStatsValueNameReceiving: |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 592 | return "googReadable"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 593 | case kStatsValueNameRemoteAddress: |
| 594 | return "googRemoteAddress"; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 595 | case kStatsValueNameRemoteCandidateId: |
| 596 | return "remoteCandidateId"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 597 | case kStatsValueNameRemoteCandidateType: |
| 598 | return "googRemoteCandidateType"; |
| 599 | case kStatsValueNameRemoteCertificateId: |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 600 | return "remoteCertificateId"; |
ivoc | 8c63a82 | 2016-10-21 11:10:03 | [diff] [blame] | 601 | case kStatsValueNameResidualEchoLikelihood: |
| 602 | return "googResidualEchoLikelihood"; |
ivoc | 4e477a1 | 2017-01-15 16:29:46 | [diff] [blame] | 603 | case kStatsValueNameResidualEchoLikelihoodRecentMax: |
| 604 | return "googResidualEchoLikelihoodRecentMax"; |
ivoc | e1198e0 | 2017-09-08 15:13:19 | [diff] [blame] | 605 | case kStatsValueNameAnaBitrateActionCounter: |
| 606 | return "googAnaBitrateActionCounter"; |
| 607 | case kStatsValueNameAnaChannelActionCounter: |
| 608 | return "googAnaChannelActionCounter"; |
| 609 | case kStatsValueNameAnaDtxActionCounter: |
| 610 | return "googAnaDtxActionCounter"; |
| 611 | case kStatsValueNameAnaFecActionCounter: |
| 612 | return "googAnaFecActionCounter"; |
ivoc | 0d0b912 | 2017-09-08 20:24:21 | [diff] [blame] | 613 | case kStatsValueNameAnaFrameLengthIncreaseCounter: |
| 614 | return "googAnaFrameLengthIncreaseCounter"; |
| 615 | case kStatsValueNameAnaFrameLengthDecreaseCounter: |
| 616 | return "googAnaFrameLengthDecreaseCounter"; |
| 617 | case kStatsValueNameAnaUplinkPacketLossFraction: |
| 618 | return "googAnaUplinkPacketLossFraction"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 619 | case kStatsValueNameRetransmitBitrate: |
| 620 | return "googRetransmitBitrate"; |
| 621 | case kStatsValueNameRtt: |
| 622 | return "googRtt"; |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 | [diff] [blame] | 623 | case kStatsValueNameSecondaryDecodedRate: |
| 624 | return "googSecondaryDecodedRate"; |
minyue-webrtc | 0e320ec | 2017-08-28 11:51:27 | [diff] [blame] | 625 | case kStatsValueNameSecondaryDiscardedRate: |
| 626 | return "googSecondaryDiscardedRate"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 627 | case kStatsValueNameSendPacketsDiscarded: |
| 628 | return "packetsDiscardedOnSend"; |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 | [diff] [blame] | 629 | case kStatsValueNameSpeechExpandRate: |
| 630 | return "googSpeechExpandRate"; |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 631 | case kStatsValueNameSrtpCipher: |
| 632 | return "srtpCipher"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 633 | case kStatsValueNameTargetEncBitrate: |
| 634 | return "googTargetEncBitrate"; |
zstein | e76bd3a | 2017-07-14 19:17:49 | [diff] [blame] | 635 | case kStatsValueNameTotalAudioEnergy: |
| 636 | return "totalAudioEnergy"; |
| 637 | case kStatsValueNameTotalSamplesDuration: |
| 638 | return "totalSamplesDuration"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 639 | case kStatsValueNameTransmitBitrate: |
| 640 | return "googTransmitBitrate"; |
| 641 | case kStatsValueNameTransportType: |
| 642 | return "googTransportType"; |
| 643 | case kStatsValueNameTrackId: |
| 644 | return "googTrackId"; |
ilnik | 2edc684 | 2017-07-06 10:06:50 | [diff] [blame] | 645 | case kStatsValueNameTimingFrameInfo: |
| 646 | return "googTimingFrameInfo"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 647 | case kStatsValueNameTypingNoiseState: |
| 648 | return "googTypingNoiseState"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 649 | case kStatsValueNameWritable: |
| 650 | return "googWritable"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | return nullptr; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 654 | } |
| 655 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 656 | std::string StatsReport::Value::ToString() const { |
| 657 | switch (type_) { |
| 658 | case kInt: |
| 659 | return rtc::ToString(value_.int_); |
| 660 | case kInt64: |
| 661 | return rtc::ToString(value_.int64_); |
| 662 | case kFloat: |
| 663 | return rtc::ToString(value_.float_); |
| 664 | case kStaticString: |
| 665 | return std::string(value_.static_string_); |
| 666 | case kString: |
| 667 | return *value_.string_; |
| 668 | case kBool: |
| 669 | return value_.bool_ ? "true" : "false"; |
| 670 | case kId: |
| 671 | return (*value_.id_)->ToString(); |
| 672 | } |
| 673 | RTC_NOTREACHED(); |
| 674 | return std::string(); |
tommi@webrtc.org | afa6d16 | 2015-03-02 11:27:48 | [diff] [blame] | 675 | } |
| 676 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 677 | StatsReport::StatsReport(const Id& id) : id_(id), timestamp_(0.0) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 678 | RTC_DCHECK(id_.get()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 679 | } |
| 680 | |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 681 | StatsReport::~StatsReport() = default; |
| 682 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 683 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 684 | StatsReport::Id StatsReport::NewBandwidthEstimationId() { |
| 685 | return Id(new RefCountedObject<BandwidthEstimationId>()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 689 | StatsReport::Id StatsReport::NewTypedId(StatsType type, const std::string& id) { |
| 690 | return Id(new RefCountedObject<TypedId>(type, id)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 694 | StatsReport::Id StatsReport::NewTypedIntId(StatsType type, int id) { |
| 695 | return Id(new RefCountedObject<TypedIntId>(type, id)); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 699 | StatsReport::Id StatsReport::NewIdWithDirection( |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 700 | StatsType type, |
| 701 | const std::string& id, |
| 702 | StatsReport::Direction direction) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 703 | return Id(new RefCountedObject<IdWithDirection>(type, id, direction)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 707 | StatsReport::Id StatsReport::NewCandidateId(bool local, const std::string& id) { |
| 708 | return Id(new RefCountedObject<CandidateId>(local, id)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | // static |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 712 | StatsReport::Id StatsReport::NewComponentId(const std::string& content_name, |
| 713 | int component) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 714 | return Id(new RefCountedObject<ComponentId>(content_name, component)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | // static |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 718 | StatsReport::Id StatsReport::NewCandidatePairId(const std::string& content_name, |
| 719 | int component, |
| 720 | int index) { |
| 721 | return Id( |
| 722 | new RefCountedObject<CandidatePairId>(content_name, component, index)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | const char* StatsReport::TypeToString() const { |
| 726 | return InternalTypeToString(id_->type()); |
| 727 | } |
| 728 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 729 | void StatsReport::AddString(StatsReport::StatsValueName name, |
| 730 | const std::string& value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 731 | const Value* found = FindValue(name); |
| 732 | if (!found || !(*found == value)) |
| 733 | values_[name] = ValuePtr(new Value(name, value)); |
| 734 | } |
| 735 | |
| 736 | void StatsReport::AddString(StatsReport::StatsValueName name, |
| 737 | const char* value) { |
| 738 | const Value* found = FindValue(name); |
| 739 | if (!found || !(*found == value)) |
| 740 | values_[name] = ValuePtr(new Value(name, value)); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 741 | } |
| 742 | |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 743 | void StatsReport::AddInt64(StatsReport::StatsValueName name, int64_t value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 744 | const Value* found = FindValue(name); |
| 745 | if (!found || !(*found == value)) |
| 746 | values_[name] = ValuePtr(new Value(name, value, Value::kInt64)); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 747 | } |
| 748 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 749 | void StatsReport::AddInt(StatsReport::StatsValueName name, int value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 750 | const Value* found = FindValue(name); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 751 | if (!found || !(*found == static_cast<int64_t>(value))) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 752 | values_[name] = ValuePtr(new Value(name, value, Value::kInt)); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 753 | } |
| 754 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 755 | void StatsReport::AddFloat(StatsReport::StatsValueName name, float value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 756 | const Value* found = FindValue(name); |
| 757 | if (!found || !(*found == value)) |
| 758 | values_[name] = ValuePtr(new Value(name, value)); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 759 | } |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 760 | |
| 761 | void StatsReport::AddBoolean(StatsReport::StatsValueName name, bool value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 762 | const Value* found = FindValue(name); |
| 763 | if (!found || !(*found == value)) |
| 764 | values_[name] = ValuePtr(new Value(name, value)); |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 765 | } |
| 766 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 767 | void StatsReport::AddId(StatsReport::StatsValueName name, const Id& value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 768 | const Value* found = FindValue(name); |
| 769 | if (!found || !(*found == value)) |
| 770 | values_[name] = ValuePtr(new Value(name, value)); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 771 | } |
| 772 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 773 | const StatsReport::Value* StatsReport::FindValue(StatsValueName name) const { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 774 | Values::const_iterator it = values_.find(name); |
| 775 | return it == values_.end() ? nullptr : it->second.get(); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 776 | } |
| 777 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 778 | StatsCollection::StatsCollection() {} |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 779 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 780 | StatsCollection::~StatsCollection() { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 781 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 782 | for (auto* r : list_) |
| 783 | delete r; |
| 784 | } |
| 785 | |
| 786 | StatsCollection::const_iterator StatsCollection::begin() const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 787 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 788 | return list_.begin(); |
| 789 | } |
| 790 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 791 | StatsCollection::const_iterator StatsCollection::end() const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 792 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 793 | return list_.end(); |
| 794 | } |
| 795 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 796 | size_t StatsCollection::size() const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 797 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 798 | return list_.size(); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 799 | } |
| 800 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 801 | StatsReport* StatsCollection::InsertNew(const StatsReport::Id& id) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 802 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 803 | RTC_DCHECK(Find(id) == nullptr); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 804 | StatsReport* report = new StatsReport(id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 805 | list_.push_back(report); |
| 806 | return report; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 807 | } |
| 808 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 809 | StatsReport* StatsCollection::FindOrAddNew(const StatsReport::Id& id) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 810 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 811 | StatsReport* ret = Find(id); |
| 812 | return ret ? ret : InsertNew(id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 813 | } |
| 814 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 815 | StatsReport* StatsCollection::ReplaceOrAddNew(const StatsReport::Id& id) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 816 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 817 | RTC_DCHECK(id.get()); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 818 | Container::iterator it = std::find_if( |
| 819 | list_.begin(), list_.end(), |
| 820 | [&id](const StatsReport* r) -> bool { return r->id()->Equals(id); }); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 821 | if (it != end()) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 822 | StatsReport* report = new StatsReport((*it)->id()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 823 | delete *it; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 824 | *it = report; |
| 825 | return report; |
| 826 | } |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 827 | return InsertNew(id); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 828 | } |
| 829 | |
deadbeef | 8d60a94 | 2017-02-27 22:47:33 | [diff] [blame] | 830 | // Looks for a report with the given |id|. If one is not found, null |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 831 | // will be returned. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 832 | StatsReport* StatsCollection::Find(const StatsReport::Id& id) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 833 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 834 | Container::iterator it = std::find_if( |
| 835 | list_.begin(), list_.end(), |
| 836 | [&id](const StatsReport* r) -> bool { return r->id()->Equals(id); }); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 837 | return it == list_.end() ? nullptr : *it; |
| 838 | } |
| 839 | |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 | [diff] [blame] | 840 | } // namespace webrtc |