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