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 | |
Henrik Kjellander | 15583c1 | 2016-02-10 09:53:12 | [diff] [blame] | 11 | #include "webrtc/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 | |
| 15 | #include "webrtc/base/checks.h" |
| 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"; |
| 374 | case kStatsValueNamePacketsSent: |
| 375 | return "packetsSent"; |
| 376 | case kStatsValueNameBytesReceived: |
| 377 | return "bytesReceived"; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 | [diff] [blame] | 378 | case kStatsValueNameLabel: |
| 379 | return "label"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 380 | case kStatsValueNamePacketsReceived: |
| 381 | return "packetsReceived"; |
| 382 | case kStatsValueNamePacketsLost: |
| 383 | return "packetsLost"; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 | [diff] [blame] | 384 | case kStatsValueNameProtocol: |
| 385 | return "protocol"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 386 | case kStatsValueNameTransportId: |
| 387 | return "transportId"; |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 388 | case kStatsValueNameSelectedCandidatePairId: |
| 389 | return "selectedCandidatePairId"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 390 | case kStatsValueNameSsrc: |
| 391 | return "ssrc"; |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 | [diff] [blame] | 392 | case kStatsValueNameState: |
| 393 | return "state"; |
| 394 | case kStatsValueNameDataChannelId: |
| 395 | return "datachannelid"; |
sakal | e5ba44e | 2016-10-26 14:09:24 | [diff] [blame] | 396 | case kStatsValueNameFramesDecoded: |
| 397 | return "framesDecoded"; |
sakal | 43536c3 | 2016-10-24 08:46:43 | [diff] [blame] | 398 | case kStatsValueNameFramesEncoded: |
| 399 | return "framesEncoded"; |
Peter Boström | b7d9a97 | 2015-12-18 15:01:11 | [diff] [blame] | 400 | case kStatsValueNameCodecImplementationName: |
| 401 | return "codecImplementationName"; |
fippo | bec70ab | 2016-01-28 09:27:15 | [diff] [blame] | 402 | case kStatsValueNameMediaType: |
| 403 | return "mediaType"; |
sakal | 87da404 | 2016-10-31 13:53:47 | [diff] [blame] | 404 | case kStatsValueNameQpSum: |
| 405 | return "qpSum"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 406 | // 'goog' prefixed constants. |
Henrik Lundin | 8e6fd46 | 2015-06-02 07:24:52 | [diff] [blame] | 407 | case kStatsValueNameAccelerateRate: |
| 408 | return "googAccelerateRate"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 409 | case kStatsValueNameActiveConnection: |
| 410 | return "googActiveConnection"; |
| 411 | case kStatsValueNameActualEncBitrate: |
| 412 | return "googActualEncBitrate"; |
| 413 | case kStatsValueNameAvailableReceiveBandwidth: |
| 414 | return "googAvailableReceiveBandwidth"; |
| 415 | case kStatsValueNameAvailableSendBandwidth: |
| 416 | return "googAvailableSendBandwidth"; |
| 417 | case kStatsValueNameAvgEncodeMs: |
| 418 | return "googAvgEncodeMs"; |
| 419 | case kStatsValueNameBucketDelay: |
| 420 | return "googBucketDelay"; |
| 421 | case kStatsValueNameBandwidthLimitedResolution: |
| 422 | return "googBandwidthLimitedResolution"; |
zhihuang | 5ecf16c | 2016-06-02 00:09:15 | [diff] [blame] | 423 | // STUN ping related attributes. |
| 424 | // TODO(zhihuang) Rename these stats to follow the standards. |
| 425 | case kStatsValueNameSentPingRequestsTotal: |
| 426 | return "requestsSent"; |
| 427 | case kStatsValueNameSentPingRequestsBeforeFirstResponse: |
| 428 | return "consentRequestsSent"; |
| 429 | case kStatsValueNameSentPingResponses: |
| 430 | return "responsesSent"; |
| 431 | case kStatsValueNameRecvPingRequests: |
| 432 | return "requestsReceived"; |
| 433 | case kStatsValueNameRecvPingResponses: |
| 434 | return "responsesReceived"; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 435 | |
| 436 | // Candidate related attributes. Values are taken from |
| 437 | // http://w3c.github.io/webrtc-stats/#rtcstatstype-enum*. |
| 438 | case kStatsValueNameCandidateIPAddress: |
| 439 | return "ipAddress"; |
| 440 | case kStatsValueNameCandidateNetworkType: |
| 441 | return "networkType"; |
| 442 | case kStatsValueNameCandidatePortNumber: |
| 443 | return "portNumber"; |
| 444 | case kStatsValueNameCandidatePriority: |
| 445 | return "priority"; |
| 446 | case kStatsValueNameCandidateTransportType: |
| 447 | return "transport"; |
| 448 | case kStatsValueNameCandidateType: |
| 449 | return "candidateType"; |
| 450 | |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 451 | case kStatsValueNameChannelId: |
| 452 | return "googChannelId"; |
| 453 | case kStatsValueNameCodecName: |
| 454 | return "googCodecName"; |
| 455 | case kStatsValueNameComponent: |
| 456 | return "googComponent"; |
| 457 | case kStatsValueNameContentName: |
| 458 | return "googContentName"; |
| 459 | case kStatsValueNameCpuLimitedResolution: |
| 460 | return "googCpuLimitedResolution"; |
| 461 | case kStatsValueNameDecodingCTSG: |
| 462 | return "googDecodingCTSG"; |
| 463 | case kStatsValueNameDecodingCTN: |
| 464 | return "googDecodingCTN"; |
henrik.lundin | 6348978 | 2016-09-20 08:47:12 | [diff] [blame] | 465 | case kStatsValueNameDecodingMutedOutput: |
| 466 | return "googDecodingMuted"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 467 | case kStatsValueNameDecodingNormal: |
| 468 | return "googDecodingNormal"; |
| 469 | case kStatsValueNameDecodingPLC: |
| 470 | return "googDecodingPLC"; |
| 471 | case kStatsValueNameDecodingCNG: |
| 472 | return "googDecodingCNG"; |
| 473 | case kStatsValueNameDecodingPLCCNG: |
| 474 | return "googDecodingPLCCNG"; |
| 475 | case kStatsValueNameDer: |
| 476 | return "googDerBase64"; |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 477 | case kStatsValueNameDtlsCipher: |
| 478 | return "dtlsCipher"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 479 | case kStatsValueNameEchoCancellationQualityMin: |
| 480 | return "googEchoCancellationQualityMin"; |
| 481 | case kStatsValueNameEchoDelayMedian: |
| 482 | return "googEchoCancellationEchoDelayMedian"; |
| 483 | case kStatsValueNameEchoDelayStdDev: |
| 484 | return "googEchoCancellationEchoDelayStdDev"; |
| 485 | case kStatsValueNameEchoReturnLoss: |
| 486 | return "googEchoCancellationReturnLoss"; |
| 487 | case kStatsValueNameEchoReturnLossEnhancement: |
| 488 | return "googEchoCancellationReturnLossEnhancement"; |
| 489 | case kStatsValueNameEncodeUsagePercent: |
| 490 | return "googEncodeUsagePercent"; |
| 491 | case kStatsValueNameExpandRate: |
| 492 | return "googExpandRate"; |
| 493 | case kStatsValueNameFingerprint: |
| 494 | return "googFingerprint"; |
| 495 | case kStatsValueNameFingerprintAlgorithm: |
| 496 | return "googFingerprintAlgorithm"; |
| 497 | case kStatsValueNameFirsReceived: |
| 498 | return "googFirsReceived"; |
| 499 | case kStatsValueNameFirsSent: |
| 500 | return "googFirsSent"; |
| 501 | case kStatsValueNameFrameHeightInput: |
| 502 | return "googFrameHeightInput"; |
| 503 | case kStatsValueNameFrameHeightReceived: |
| 504 | return "googFrameHeightReceived"; |
| 505 | case kStatsValueNameFrameHeightSent: |
| 506 | return "googFrameHeightSent"; |
| 507 | case kStatsValueNameFrameRateReceived: |
| 508 | return "googFrameRateReceived"; |
| 509 | case kStatsValueNameFrameRateDecoded: |
| 510 | return "googFrameRateDecoded"; |
| 511 | case kStatsValueNameFrameRateOutput: |
| 512 | return "googFrameRateOutput"; |
| 513 | case kStatsValueNameDecodeMs: |
| 514 | return "googDecodeMs"; |
| 515 | case kStatsValueNameMaxDecodeMs: |
| 516 | return "googMaxDecodeMs"; |
| 517 | case kStatsValueNameCurrentDelayMs: |
| 518 | return "googCurrentDelayMs"; |
| 519 | case kStatsValueNameTargetDelayMs: |
| 520 | return "googTargetDelayMs"; |
| 521 | case kStatsValueNameJitterBufferMs: |
| 522 | return "googJitterBufferMs"; |
| 523 | case kStatsValueNameMinPlayoutDelayMs: |
| 524 | return "googMinPlayoutDelayMs"; |
| 525 | case kStatsValueNameRenderDelayMs: |
| 526 | return "googRenderDelayMs"; |
| 527 | case kStatsValueNameCaptureStartNtpTimeMs: |
| 528 | return "googCaptureStartNtpTimeMs"; |
| 529 | case kStatsValueNameFrameRateInput: |
| 530 | return "googFrameRateInput"; |
| 531 | case kStatsValueNameFrameRateSent: |
| 532 | return "googFrameRateSent"; |
| 533 | case kStatsValueNameFrameWidthInput: |
| 534 | return "googFrameWidthInput"; |
| 535 | case kStatsValueNameFrameWidthReceived: |
| 536 | return "googFrameWidthReceived"; |
| 537 | case kStatsValueNameFrameWidthSent: |
| 538 | return "googFrameWidthSent"; |
| 539 | case kStatsValueNameInitiator: |
| 540 | return "googInitiator"; |
| 541 | case kStatsValueNameIssuerId: |
| 542 | return "googIssuerId"; |
| 543 | case kStatsValueNameJitterReceived: |
| 544 | return "googJitterReceived"; |
| 545 | case kStatsValueNameLocalAddress: |
| 546 | return "googLocalAddress"; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 547 | case kStatsValueNameLocalCandidateId: |
| 548 | return "localCandidateId"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 549 | case kStatsValueNameLocalCandidateType: |
| 550 | return "googLocalCandidateType"; |
| 551 | case kStatsValueNameLocalCertificateId: |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 552 | return "localCertificateId"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 553 | case kStatsValueNameAdaptationChanges: |
| 554 | return "googAdaptationChanges"; |
| 555 | case kStatsValueNameNacksReceived: |
| 556 | return "googNacksReceived"; |
| 557 | case kStatsValueNameNacksSent: |
| 558 | return "googNacksSent"; |
Henrik Lundin | 8e6fd46 | 2015-06-02 07:24:52 | [diff] [blame] | 559 | case kStatsValueNamePreemptiveExpandRate: |
| 560 | return "googPreemptiveExpandRate"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 561 | case kStatsValueNamePlisReceived: |
| 562 | return "googPlisReceived"; |
| 563 | case kStatsValueNamePlisSent: |
| 564 | return "googPlisSent"; |
| 565 | case kStatsValueNamePreferredJitterBufferMs: |
| 566 | return "googPreferredJitterBufferMs"; |
Peter Thatcher | 04ac81f | 2015-09-21 18:48:28 | [diff] [blame] | 567 | case kStatsValueNameReceiving: |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 568 | return "googReadable"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 569 | case kStatsValueNameRemoteAddress: |
| 570 | return "googRemoteAddress"; |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 | [diff] [blame] | 571 | case kStatsValueNameRemoteCandidateId: |
| 572 | return "remoteCandidateId"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 573 | case kStatsValueNameRemoteCandidateType: |
| 574 | return "googRemoteCandidateType"; |
| 575 | case kStatsValueNameRemoteCertificateId: |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 576 | return "remoteCertificateId"; |
ivoc | 8c63a82 | 2016-10-21 11:10:03 | [diff] [blame] | 577 | case kStatsValueNameResidualEchoLikelihood: |
| 578 | return "googResidualEchoLikelihood"; |
ivoc | 4e477a1 | 2017-01-15 16:29:46 | [diff] [blame] | 579 | case kStatsValueNameResidualEchoLikelihoodRecentMax: |
| 580 | return "googResidualEchoLikelihoodRecentMax"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 581 | case kStatsValueNameRetransmitBitrate: |
| 582 | return "googRetransmitBitrate"; |
| 583 | case kStatsValueNameRtt: |
| 584 | return "googRtt"; |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 | [diff] [blame] | 585 | case kStatsValueNameSecondaryDecodedRate: |
| 586 | return "googSecondaryDecodedRate"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 587 | case kStatsValueNameSendPacketsDiscarded: |
| 588 | return "packetsDiscardedOnSend"; |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 | [diff] [blame] | 589 | case kStatsValueNameSpeechExpandRate: |
| 590 | return "googSpeechExpandRate"; |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 | [diff] [blame] | 591 | case kStatsValueNameSrtpCipher: |
| 592 | return "srtpCipher"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 593 | case kStatsValueNameTargetEncBitrate: |
| 594 | return "googTargetEncBitrate"; |
| 595 | case kStatsValueNameTransmitBitrate: |
| 596 | return "googTransmitBitrate"; |
| 597 | case kStatsValueNameTransportType: |
| 598 | return "googTransportType"; |
| 599 | case kStatsValueNameTrackId: |
| 600 | return "googTrackId"; |
ilnik | 2edc684 | 2017-07-06 10:06:50 | [diff] [blame^] | 601 | case kStatsValueNameTimingFrameInfo: |
| 602 | return "googTimingFrameInfo"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 603 | case kStatsValueNameTypingNoiseState: |
| 604 | return "googTypingNoiseState"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 605 | case kStatsValueNameWritable: |
| 606 | return "googWritable"; |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | return nullptr; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 610 | } |
| 611 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 612 | std::string StatsReport::Value::ToString() const { |
| 613 | switch (type_) { |
| 614 | case kInt: |
| 615 | return rtc::ToString(value_.int_); |
| 616 | case kInt64: |
| 617 | return rtc::ToString(value_.int64_); |
| 618 | case kFloat: |
| 619 | return rtc::ToString(value_.float_); |
| 620 | case kStaticString: |
| 621 | return std::string(value_.static_string_); |
| 622 | case kString: |
| 623 | return *value_.string_; |
| 624 | case kBool: |
| 625 | return value_.bool_ ? "true" : "false"; |
| 626 | case kId: |
| 627 | return (*value_.id_)->ToString(); |
| 628 | } |
| 629 | RTC_NOTREACHED(); |
| 630 | return std::string(); |
tommi@webrtc.org | afa6d16 | 2015-03-02 11:27:48 | [diff] [blame] | 631 | } |
| 632 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 633 | StatsReport::StatsReport(const Id& id) : id_(id), timestamp_(0.0) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 634 | RTC_DCHECK(id_.get()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 635 | } |
| 636 | |
ossu | 7bb87ee | 2017-01-23 12:56:25 | [diff] [blame] | 637 | StatsReport::~StatsReport() = default; |
| 638 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 639 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 640 | StatsReport::Id StatsReport::NewBandwidthEstimationId() { |
| 641 | return Id(new RefCountedObject<BandwidthEstimationId>()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 645 | StatsReport::Id StatsReport::NewTypedId(StatsType type, const std::string& id) { |
| 646 | return Id(new RefCountedObject<TypedId>(type, id)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 650 | StatsReport::Id StatsReport::NewTypedIntId(StatsType type, int id) { |
| 651 | return Id(new RefCountedObject<TypedIntId>(type, id)); |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 655 | StatsReport::Id StatsReport::NewIdWithDirection( |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 656 | StatsType type, const std::string& id, StatsReport::Direction direction) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 657 | return Id(new RefCountedObject<IdWithDirection>(type, id, direction)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 661 | StatsReport::Id StatsReport::NewCandidateId(bool local, const std::string& id) { |
| 662 | return Id(new RefCountedObject<CandidateId>(local, id)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 666 | StatsReport::Id StatsReport::NewComponentId( |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 667 | const std::string& content_name, int component) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 668 | return Id(new RefCountedObject<ComponentId>(content_name, component)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | // static |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 672 | StatsReport::Id StatsReport::NewCandidatePairId( |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 673 | const std::string& content_name, int component, int index) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 674 | return Id(new RefCountedObject<CandidatePairId>( |
| 675 | content_name, component, index)); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | const char* StatsReport::TypeToString() const { |
| 679 | return InternalTypeToString(id_->type()); |
| 680 | } |
| 681 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 682 | void StatsReport::AddString(StatsReport::StatsValueName name, |
| 683 | const std::string& value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 684 | const Value* found = FindValue(name); |
| 685 | if (!found || !(*found == value)) |
| 686 | values_[name] = ValuePtr(new Value(name, value)); |
| 687 | } |
| 688 | |
| 689 | void StatsReport::AddString(StatsReport::StatsValueName name, |
| 690 | const char* value) { |
| 691 | const Value* found = FindValue(name); |
| 692 | if (!found || !(*found == value)) |
| 693 | values_[name] = ValuePtr(new Value(name, value)); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 694 | } |
| 695 | |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 696 | void StatsReport::AddInt64(StatsReport::StatsValueName name, int64_t value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 697 | const Value* found = FindValue(name); |
| 698 | if (!found || !(*found == value)) |
| 699 | values_[name] = ValuePtr(new Value(name, value, Value::kInt64)); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 700 | } |
| 701 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 702 | void StatsReport::AddInt(StatsReport::StatsValueName name, int value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 703 | const Value* found = FindValue(name); |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 704 | if (!found || !(*found == static_cast<int64_t>(value))) |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 705 | values_[name] = ValuePtr(new Value(name, value, Value::kInt)); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 706 | } |
| 707 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 708 | void StatsReport::AddFloat(StatsReport::StatsValueName name, float value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 709 | const Value* found = FindValue(name); |
| 710 | if (!found || !(*found == value)) |
| 711 | values_[name] = ValuePtr(new Value(name, value)); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 712 | } |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 713 | |
| 714 | void StatsReport::AddBoolean(StatsReport::StatsValueName name, bool value) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 715 | const Value* found = FindValue(name); |
| 716 | if (!found || !(*found == value)) |
| 717 | values_[name] = ValuePtr(new Value(name, value)); |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 | [diff] [blame] | 718 | } |
| 719 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 720 | void StatsReport::AddId(StatsReport::StatsValueName name, |
| 721 | const Id& value) { |
| 722 | const Value* found = FindValue(name); |
| 723 | if (!found || !(*found == value)) |
| 724 | values_[name] = ValuePtr(new Value(name, value)); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 725 | } |
| 726 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 727 | const StatsReport::Value* StatsReport::FindValue(StatsValueName name) const { |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 | [diff] [blame] | 728 | Values::const_iterator it = values_.find(name); |
| 729 | return it == values_.end() ? nullptr : it->second.get(); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 730 | } |
| 731 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 732 | StatsCollection::StatsCollection() { |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 733 | } |
| 734 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 735 | StatsCollection::~StatsCollection() { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 736 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 737 | for (auto* r : list_) |
| 738 | delete r; |
| 739 | } |
| 740 | |
| 741 | StatsCollection::const_iterator StatsCollection::begin() const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 742 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 743 | return list_.begin(); |
| 744 | } |
| 745 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 746 | StatsCollection::const_iterator StatsCollection::end() const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 747 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 748 | return list_.end(); |
| 749 | } |
| 750 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 751 | size_t StatsCollection::size() const { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 752 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 753 | return list_.size(); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 754 | } |
| 755 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 756 | StatsReport* StatsCollection::InsertNew(const StatsReport::Id& id) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 757 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 758 | RTC_DCHECK(Find(id) == nullptr); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 759 | StatsReport* report = new StatsReport(id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 760 | list_.push_back(report); |
| 761 | return report; |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 762 | } |
| 763 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 764 | StatsReport* StatsCollection::FindOrAddNew(const StatsReport::Id& id) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 765 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 766 | StatsReport* ret = Find(id); |
| 767 | return ret ? ret : InsertNew(id); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 768 | } |
| 769 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 770 | StatsReport* StatsCollection::ReplaceOrAddNew(const StatsReport::Id& id) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 771 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
| 772 | RTC_DCHECK(id.get()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 773 | Container::iterator it = std::find_if(list_.begin(), list_.end(), |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 774 | [&id](const StatsReport* r)->bool { return r->id()->Equals(id); }); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 775 | if (it != end()) { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 776 | StatsReport* report = new StatsReport((*it)->id()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 777 | delete *it; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 778 | *it = report; |
| 779 | return report; |
| 780 | } |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 781 | return InsertNew(id); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 | [diff] [blame] | 782 | } |
| 783 | |
deadbeef | 8d60a94 | 2017-02-27 22:47:33 | [diff] [blame] | 784 | // 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] | 785 | // will be returned. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 786 | StatsReport* StatsCollection::Find(const StatsReport::Id& id) { |
henrikg | 91d6ede | 2015-09-17 07:24:34 | [diff] [blame] | 787 | RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 788 | Container::iterator it = std::find_if(list_.begin(), list_.end(), |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 | [diff] [blame] | 789 | [&id](const StatsReport* r)->bool { return r->id()->Equals(id); }); |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 | [diff] [blame] | 790 | return it == list_.end() ? nullptr : *it; |
| 791 | } |
| 792 | |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 | [diff] [blame] | 793 | } // namespace webrtc |