henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2012 Google Inc. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | // This file contains structures used for retrieving statistics from an ongoing |
| 29 | // libjingle session. |
| 30 | |
| 31 | #ifndef TALK_APP_WEBRTC_STATSTYPES_H_ |
| 32 | #define TALK_APP_WEBRTC_STATSTYPES_H_ |
| 33 | |
tommi@webrtc.org | 5c3ee4b | 2014-12-09 10:47:01 +0000 | [diff] [blame] | 34 | #include <algorithm> |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 35 | #include <list> |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 36 | #include <map> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 37 | #include <string> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 38 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 39 | #include "webrtc/base/basictypes.h" |
andrew@webrtc.org | 6ae5a6d | 2014-09-16 01:03:29 +0000 | [diff] [blame] | 40 | #include "webrtc/base/common.h" |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 41 | #include "webrtc/base/refcount.h" |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 42 | #include "webrtc/base/scoped_ptr.h" |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 43 | #include "webrtc/base/linked_ptr.h" |
| 44 | #include "webrtc/base/scoped_ref_ptr.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 45 | #include "webrtc/base/stringencode.h" |
jbauch | 25c96d0 | 2015-08-07 09:48:18 -0700 | [diff] [blame] | 46 | #include "webrtc/base/thread_checker.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 47 | |
| 48 | namespace webrtc { |
| 49 | |
| 50 | class StatsReport { |
| 51 | public: |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 52 | // Indicates whether a track is for sending or receiving. |
| 53 | // Used in reports for audio/video tracks. |
| 54 | enum Direction { |
| 55 | kSend = 0, |
| 56 | kReceive, |
| 57 | }; |
tommi@webrtc.org | aa2c342 | 2014-12-09 20:23:06 +0000 | [diff] [blame] | 58 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 59 | enum StatsType { |
| 60 | // StatsReport types. |
| 61 | // A StatsReport of |type| = "googSession" contains overall information |
| 62 | // about the thing libjingle calls a session (which may contain one |
| 63 | // or more RTP sessions. |
| 64 | kStatsReportTypeSession, |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 65 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 66 | // A StatsReport of |type| = "googTransport" contains information |
| 67 | // about a libjingle "transport". |
| 68 | kStatsReportTypeTransport, |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 69 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 70 | // A StatsReport of |type| = "googComponent" contains information |
| 71 | // about a libjingle "channel" (typically, RTP or RTCP for a transport). |
| 72 | // This is intended to be the same thing as an ICE "Component". |
| 73 | kStatsReportTypeComponent, |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 74 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 75 | // A StatsReport of |type| = "googCandidatePair" contains information |
| 76 | // about a libjingle "connection" - a single source/destination port pair. |
| 77 | // This is intended to be the same thing as an ICE "candidate pair". |
| 78 | kStatsReportTypeCandidatePair, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 80 | // A StatsReport of |type| = "VideoBWE" is statistics for video Bandwidth |
| 81 | // Estimation, which is global per-session. The |id| field is "bweforvideo" |
| 82 | // (will probably change in the future). |
| 83 | kStatsReportTypeBwe, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 85 | // A StatsReport of |type| = "ssrc" is statistics for a specific rtp stream. |
| 86 | // The |id| field is the SSRC in decimal form of the rtp stream. |
| 87 | kStatsReportTypeSsrc, |
| 88 | |
| 89 | // A StatsReport of |type| = "remoteSsrc" is statistics for a specific |
| 90 | // rtp stream, generated by the remote end of the connection. |
| 91 | kStatsReportTypeRemoteSsrc, |
| 92 | |
| 93 | // A StatsReport of |type| = "googTrack" is statistics for a specific media |
| 94 | // track. The |id| field is the track id. |
| 95 | kStatsReportTypeTrack, |
| 96 | |
| 97 | // A StatsReport of |type| = "localcandidate" or "remotecandidate" is |
| 98 | // attributes on a specific ICE Candidate. It links to its connection pair |
| 99 | // by candidate id. The string value is taken from |
| 100 | // http://w3c.github.io/webrtc-stats/#rtcstatstype-enum*. |
| 101 | kStatsReportTypeIceLocalCandidate, |
| 102 | kStatsReportTypeIceRemoteCandidate, |
| 103 | |
| 104 | // A StatsReport of |type| = "googCertificate" contains an SSL certificate |
| 105 | // transmitted by one of the endpoints of this connection. The |id| is |
| 106 | // controlled by the fingerprint, and is used to identify the certificate in |
| 107 | // the Channel stats (as "googLocalCertificateId" or |
| 108 | // "googRemoteCertificateId") and in any child certificates (as |
| 109 | // "googIssuerId"). |
| 110 | kStatsReportTypeCertificate, |
| 111 | |
| 112 | // A StatsReport of |type| = "datachannel" with statistics for a |
| 113 | // particular DataChannel. |
| 114 | kStatsReportTypeDataChannel, |
| 115 | }; |
| 116 | |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 117 | enum StatsValueName { |
| 118 | kStatsValueNameActiveConnection, |
| 119 | kStatsValueNameAudioInputLevel, |
| 120 | kStatsValueNameAudioOutputLevel, |
| 121 | kStatsValueNameBytesReceived, |
| 122 | kStatsValueNameBytesSent, |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 123 | kStatsValueNameCodecImplementationName, |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 124 | kStatsValueNameDataChannelId, |
fippo | bec70ab | 2016-01-28 01:27:15 -0800 | [diff] [blame^] | 125 | kStatsValueNameMediaType, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 126 | kStatsValueNamePacketsLost, |
| 127 | kStatsValueNamePacketsReceived, |
| 128 | kStatsValueNamePacketsSent, |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 129 | kStatsValueNameProtocol, |
Peter Thatcher | 04ac81f | 2015-09-21 11:48:28 -0700 | [diff] [blame] | 130 | kStatsValueNameReceiving, |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 131 | kStatsValueNameSelectedCandidatePairId, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 132 | kStatsValueNameSsrc, |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 133 | kStatsValueNameState, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 134 | kStatsValueNameTransportId, |
| 135 | |
| 136 | // Internal StatsValue names. |
Henrik Lundin | 8e6fd46 | 2015-06-02 09:24:52 +0200 | [diff] [blame] | 137 | kStatsValueNameAccelerateRate, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 138 | kStatsValueNameActualEncBitrate, |
| 139 | kStatsValueNameAdaptationChanges, |
| 140 | kStatsValueNameAvailableReceiveBandwidth, |
| 141 | kStatsValueNameAvailableSendBandwidth, |
| 142 | kStatsValueNameAvgEncodeMs, |
| 143 | kStatsValueNameBandwidthLimitedResolution, |
| 144 | kStatsValueNameBucketDelay, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 145 | kStatsValueNameCaptureStartNtpTimeMs, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 146 | kStatsValueNameCandidateIPAddress, |
| 147 | kStatsValueNameCandidateNetworkType, |
| 148 | kStatsValueNameCandidatePortNumber, |
| 149 | kStatsValueNameCandidatePriority, |
| 150 | kStatsValueNameCandidateTransportType, |
| 151 | kStatsValueNameCandidateType, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 152 | kStatsValueNameChannelId, |
| 153 | kStatsValueNameCodecName, |
| 154 | kStatsValueNameComponent, |
| 155 | kStatsValueNameContentName, |
| 156 | kStatsValueNameCpuLimitedResolution, |
| 157 | kStatsValueNameCurrentDelayMs, |
| 158 | kStatsValueNameDecodeMs, |
| 159 | kStatsValueNameDecodingCNG, |
| 160 | kStatsValueNameDecodingCTN, |
| 161 | kStatsValueNameDecodingCTSG, |
| 162 | kStatsValueNameDecodingNormal, |
| 163 | kStatsValueNameDecodingPLC, |
| 164 | kStatsValueNameDecodingPLCCNG, |
| 165 | kStatsValueNameDer, |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 166 | kStatsValueNameDtlsCipher, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 167 | kStatsValueNameEchoCancellationQualityMin, |
| 168 | kStatsValueNameEchoDelayMedian, |
| 169 | kStatsValueNameEchoDelayStdDev, |
| 170 | kStatsValueNameEchoReturnLoss, |
| 171 | kStatsValueNameEchoReturnLossEnhancement, |
| 172 | kStatsValueNameEncodeUsagePercent, |
| 173 | kStatsValueNameExpandRate, |
| 174 | kStatsValueNameFingerprint, |
| 175 | kStatsValueNameFingerprintAlgorithm, |
| 176 | kStatsValueNameFirsReceived, |
| 177 | kStatsValueNameFirsSent, |
| 178 | kStatsValueNameFrameHeightInput, |
| 179 | kStatsValueNameFrameHeightReceived, |
| 180 | kStatsValueNameFrameHeightSent, |
| 181 | kStatsValueNameFrameRateDecoded, |
| 182 | kStatsValueNameFrameRateInput, |
| 183 | kStatsValueNameFrameRateOutput, |
| 184 | kStatsValueNameFrameRateReceived, |
| 185 | kStatsValueNameFrameRateSent, |
| 186 | kStatsValueNameFrameWidthInput, |
| 187 | kStatsValueNameFrameWidthReceived, |
| 188 | kStatsValueNameFrameWidthSent, |
| 189 | kStatsValueNameInitiator, |
| 190 | kStatsValueNameIssuerId, |
| 191 | kStatsValueNameJitterBufferMs, |
| 192 | kStatsValueNameJitterReceived, |
decurtis@webrtc.org | 487a444 | 2015-01-15 22:55:07 +0000 | [diff] [blame] | 193 | kStatsValueNameLabel, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 194 | kStatsValueNameLocalAddress, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 195 | kStatsValueNameLocalCandidateId, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 196 | kStatsValueNameLocalCandidateType, |
| 197 | kStatsValueNameLocalCertificateId, |
| 198 | kStatsValueNameMaxDecodeMs, |
| 199 | kStatsValueNameMinPlayoutDelayMs, |
| 200 | kStatsValueNameNacksReceived, |
| 201 | kStatsValueNameNacksSent, |
| 202 | kStatsValueNamePlisReceived, |
| 203 | kStatsValueNamePlisSent, |
Henrik Lundin | 8e6fd46 | 2015-06-02 09:24:52 +0200 | [diff] [blame] | 204 | kStatsValueNamePreemptiveExpandRate, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 205 | kStatsValueNamePreferredJitterBufferMs, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 206 | kStatsValueNameRemoteAddress, |
guoweis@webrtc.org | 950c518 | 2014-12-16 23:01:31 +0000 | [diff] [blame] | 207 | kStatsValueNameRemoteCandidateId, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 208 | kStatsValueNameRemoteCandidateType, |
| 209 | kStatsValueNameRemoteCertificateId, |
| 210 | kStatsValueNameRenderDelayMs, |
| 211 | kStatsValueNameRetransmitBitrate, |
| 212 | kStatsValueNameRtt, |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 +0000 | [diff] [blame] | 213 | kStatsValueNameSecondaryDecodedRate, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 214 | kStatsValueNameSendPacketsDiscarded, |
minyue@webrtc.org | 652bc37 | 2015-02-18 23:50:46 +0000 | [diff] [blame] | 215 | kStatsValueNameSpeechExpandRate, |
pthatcher@webrtc.org | 7bea1ff | 2015-03-04 01:38:30 +0000 | [diff] [blame] | 216 | kStatsValueNameSrtpCipher, |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 217 | kStatsValueNameTargetDelayMs, |
| 218 | kStatsValueNameTargetEncBitrate, |
| 219 | kStatsValueNameTrackId, |
| 220 | kStatsValueNameTransmitBitrate, |
| 221 | kStatsValueNameTransportType, |
| 222 | kStatsValueNameTypingNoiseState, |
| 223 | kStatsValueNameViewLimitedResolution, |
| 224 | kStatsValueNameWritable, |
| 225 | }; |
| 226 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 227 | class IdBase : public rtc::RefCountInterface { |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 228 | public: |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 229 | ~IdBase() override; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 230 | StatsType type() const; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 231 | |
| 232 | // Users of IdBase will be using the Id typedef, which is compatible with |
| 233 | // this Equals() function. It simply calls the protected (and overridden) |
| 234 | // Equals() method. |
| 235 | bool Equals(const rtc::scoped_refptr<IdBase>& other) const { |
| 236 | return Equals(*other.get()); |
| 237 | } |
| 238 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 239 | virtual std::string ToString() const = 0; |
| 240 | |
| 241 | protected: |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 242 | // Protected since users of the IdBase type will be using the Id typedef. |
| 243 | virtual bool Equals(const IdBase& other) const; |
| 244 | |
| 245 | IdBase(StatsType type); // Only meant for derived classes. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 246 | const StatsType type_; |
decurtis@webrtc.org | 322a564 | 2015-02-03 22:09:37 +0000 | [diff] [blame] | 247 | |
| 248 | static const char kSeparator = '_'; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 249 | }; |
| 250 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 251 | typedef rtc::scoped_refptr<IdBase> Id; |
| 252 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 253 | struct Value { |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 254 | enum Type { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 255 | kInt, // int. |
| 256 | kInt64, // int64_t. |
| 257 | kFloat, // float. |
| 258 | kString, // std::string |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 259 | kStaticString, // const char*. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 260 | kBool, // bool. |
| 261 | kId, // Id. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 262 | }; |
| 263 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 264 | Value(StatsValueName name, int64_t value, Type int_type); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 265 | Value(StatsValueName name, float f); |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 266 | Value(StatsValueName name, const std::string& value); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 267 | Value(StatsValueName name, const char* value); |
| 268 | Value(StatsValueName name, bool b); |
| 269 | Value(StatsValueName name, const Id& value); |
| 270 | |
| 271 | ~Value(); |
| 272 | |
| 273 | // TODO(tommi): This compares name as well as value... |
| 274 | // I think we should only need to compare the value part and |
| 275 | // move the name part into a hash map. |
| 276 | bool Equals(const Value& other) const; |
| 277 | |
| 278 | // Comparison operators. Return true iff the current instance is of the |
| 279 | // correct type and holds the same value. No conversion is performed so |
| 280 | // a string value of "123" is not equal to an int value of 123 and an int |
| 281 | // value of 123 is not equal to a float value of 123.0f. |
| 282 | // One exception to this is that types kInt and kInt64 can be compared and |
| 283 | // kString and kStaticString too. |
| 284 | bool operator==(const std::string& value) const; |
| 285 | bool operator==(const char* value) const; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 286 | bool operator==(int64_t value) const; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 287 | bool operator==(bool value) const; |
| 288 | bool operator==(float value) const; |
| 289 | bool operator==(const Id& value) const; |
| 290 | |
| 291 | // Getters that allow getting the native value directly. |
| 292 | // The caller must know the type beforehand or else hit a check. |
| 293 | int int_val() const; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 294 | int64_t int64_val() const; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 295 | float float_val() const; |
| 296 | const char* static_string_val() const; |
| 297 | const std::string& string_val() const; |
| 298 | bool bool_val() const; |
| 299 | const Id& id_val() const; |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 +0000 | [diff] [blame] | 300 | |
tommi@webrtc.org | c57310b | 2014-12-12 17:41:28 +0000 | [diff] [blame] | 301 | // Returns the string representation of |name|. |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 302 | const char* display_name() const; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 303 | |
| 304 | // Converts the native value to a string representation of the value. |
| 305 | std::string ToString() const; |
| 306 | |
| 307 | Type type() const { return type_; } |
| 308 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 309 | // TODO(tommi): Move |name| and |display_name| out of the Value struct. |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 +0000 | [diff] [blame] | 310 | const StatsValueName name; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 311 | |
| 312 | private: |
| 313 | const Type type_; |
| 314 | // TODO(tommi): Use C++ 11 union and make value_ const. |
| 315 | union InternalType { |
| 316 | int int_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 317 | int64_t int64_; |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 318 | float float_; |
| 319 | bool bool_; |
| 320 | std::string* string_; |
| 321 | const char* static_string_; |
| 322 | Id* id_; |
| 323 | } value_; |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 +0000 | [diff] [blame] | 324 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 325 | private: |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 326 | RTC_DISALLOW_COPY_AND_ASSIGN(Value); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 327 | }; |
| 328 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 329 | // TODO(tommi): Consider using a similar approach to how we store Ids using |
| 330 | // scoped_refptr for values. |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 331 | typedef rtc::linked_ptr<Value> ValuePtr; |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 332 | typedef std::map<StatsValueName, ValuePtr> Values; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 333 | |
| 334 | // Ownership of |id| is passed to |this|. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 335 | explicit StatsReport(const Id& id); |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 336 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 337 | // Factory functions for various types of stats IDs. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 338 | static Id NewBandwidthEstimationId(); |
| 339 | static Id NewTypedId(StatsType type, const std::string& id); |
| 340 | static Id NewTypedIntId(StatsType type, int id); |
| 341 | static Id NewIdWithDirection( |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 342 | StatsType type, const std::string& id, Direction direction); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 343 | static Id NewCandidateId(bool local, const std::string& id); |
| 344 | static Id NewComponentId( |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 345 | const std::string& content_name, int component); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 346 | static Id NewCandidatePairId( |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 347 | const std::string& content_name, int component, int index); |
| 348 | |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 349 | const Id& id() const { return id_; } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 350 | StatsType type() const { return id_->type(); } |
| 351 | double timestamp() const { return timestamp_; } |
| 352 | void set_timestamp(double t) { timestamp_ = t; } |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 353 | bool empty() const { return values_.empty(); } |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 354 | const Values& values() const { return values_; } |
| 355 | |
| 356 | const char* TypeToString() const; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 357 | |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 358 | void AddString(StatsValueName name, const std::string& value); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 359 | void AddString(StatsValueName name, const char* value); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 360 | void AddInt64(StatsValueName name, int64_t value); |
tommi@webrtc.org | 92f4018 | 2015-03-04 15:25:19 +0000 | [diff] [blame] | 361 | void AddInt(StatsValueName name, int value); |
| 362 | void AddFloat(StatsValueName name, float value); |
tommi@webrtc.org | 242068d | 2014-07-14 20:19:56 +0000 | [diff] [blame] | 363 | void AddBoolean(StatsValueName name, bool value); |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 364 | void AddId(StatsValueName name, const Id& value); |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 365 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 366 | const Value* FindValue(StatsValueName name) const; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 367 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 368 | private: |
| 369 | // The unique identifier for this object. |
| 370 | // This is used as a key for this report in ordered containers, |
| 371 | // so it must never be changed. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 372 | const Id id_; |
tommi@webrtc.org | 8e327c4 | 2015-01-19 20:41:26 +0000 | [diff] [blame] | 373 | double timestamp_; // Time since 1970-01-01T00:00:00Z in milliseconds. |
| 374 | Values values_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 375 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 376 | RTC_DISALLOW_COPY_AND_ASSIGN(StatsReport); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 377 | }; |
| 378 | |
| 379 | // Typedef for an array of const StatsReport pointers. |
| 380 | // Ownership of the pointers held by this implementation is assumed to lie |
| 381 | // elsewhere and lifetime guarantees are made by the implementation that uses |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 382 | // this type. In the StatsCollector, object ownership lies with the |
| 383 | // StatsCollection class. |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 384 | typedef std::vector<const StatsReport*> StatsReports; |
| 385 | |
| 386 | // A map from the report id to the report. |
| 387 | // This class wraps an STL container and provides a limited set of |
| 388 | // functionality in order to keep things simple. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 389 | class StatsCollection { |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 390 | public: |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 391 | StatsCollection(); |
| 392 | ~StatsCollection(); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 393 | |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 394 | typedef std::list<StatsReport*> Container; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 395 | typedef Container::iterator iterator; |
| 396 | typedef Container::const_iterator const_iterator; |
| 397 | |
tommi@webrtc.org | c9d155f | 2014-12-09 18:18:06 +0000 | [diff] [blame] | 398 | const_iterator begin() const; |
| 399 | const_iterator end() const; |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 400 | size_t size() const; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 401 | |
| 402 | // Creates a new report object with |id| that does not already |
| 403 | // exist in the list of reports. |
tommi@webrtc.org | d390029 | 2015-03-12 16:35:55 +0000 | [diff] [blame] | 404 | StatsReport* InsertNew(const StatsReport::Id& id); |
| 405 | StatsReport* FindOrAddNew(const StatsReport::Id& id); |
| 406 | StatsReport* ReplaceOrAddNew(const StatsReport::Id& id); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 407 | |
| 408 | // Looks for a report with the given |id|. If one is not found, NULL |
| 409 | // will be returned. |
tommi@webrtc.org | 4fb7e25 | 2015-01-21 11:36:18 +0000 | [diff] [blame] | 410 | StatsReport* Find(const StatsReport::Id& id); |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 411 | |
| 412 | private: |
| 413 | Container list_; |
jbauch | 25c96d0 | 2015-08-07 09:48:18 -0700 | [diff] [blame] | 414 | rtc::ThreadChecker thread_checker_; |
tommi@webrtc.org | 5b06b06 | 2014-08-15 08:38:30 +0000 | [diff] [blame] | 415 | }; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 416 | |
| 417 | } // namespace webrtc |
| 418 | |
| 419 | #endif // TALK_APP_WEBRTC_STATSTYPES_H_ |