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