Twitch SDK (Internal)
sockettracker.h
Go to the documentation of this file.
1 /********************************************************************************************
2 * Twitch Broadcasting SDK
3 *
4 * This software is supplied under the terms of a license agreement with Twitch Interactive, Inc. and
5 * may not be copied or used except in accordance with the terms of that agreement
6 * Copyright (c) 2012-2017 Twitch Interactive, Inc.
7 *********************************************************************************************/
8 
9 #pragma once
10 
11 #include <deque>
12 #include <mutex>
13 
14 namespace ttv
15 {
16  class SocketTracker;
17 }
18 
19 /*
20  * Class that tracks statistical information about usage of a socket.
21  */
23 {
24 public:
25  /*
26  * Adds information about usage of a socket
27  * @param[in] byteCount The number of bytes sent over the socket
28  * @param[in] sentTimestamp The system clock time when the call to send over the socket started.
29  * @param[in] blockTime The duration of the blocking send call, in system clock ticks.
30  */
31  void AddSendInfo(uint32_t byteCount, uint64_t sentTimestamp, uint64_t blockTime);
32 
33  /*
34  * Clears all the data collected by the socket tracker so far.
35  */
36  void Reset();
37 
38  /*
39  * Gets the average outgoing rate of the socket over a sliding window.
40  */
41  TTV_ErrorCode GetAverageOutgoingRate(uint64_t measurementWindow, uint64_t& bitsPerSecond) const;
42 
43  /*
44  * Gets the estimated fraction of time spent blocking on the socket over a sliding window. Ranges from 0.0-1.0.
45  */
46  TTV_ErrorCode GetEstimatedCongestionLevel(uint64_t measurementWindow, double& congestionLevel) const;
47 private:
48  struct SendEntry
49  {
50  uint64_t sentTimestamp;
51  uint64_t blockTime;
52  uint32_t bytesSent;
53  };
54 
55  std::deque<SendEntry> mSendEntries;
56  mutable std::mutex mMutex;
57 };
TTV_ErrorCode GetAverageOutgoingRate(uint64_t measurementWindow, uint64_t &bitsPerSecond) const
std::deque< SendEntry > mSendEntries
Definition: sockettracker.h:55
void AddSendInfo(uint32_t byteCount, uint64_t sentTimestamp, uint64_t blockTime)
uint32_t bytesSent
Definition: sockettracker.h:52
Definition: sockettracker.h:48
JSON (JavaScript Object Notation).
Definition: adsapi.h:16
uint64_t blockTime
Definition: sockettracker.h:51
uint32_t TTV_ErrorCode
Definition: errortypes.h:30
std::mutex mMutex
Definition: sockettracker.h:56
Definition: sockettracker.h:22
TTV_ErrorCode GetEstimatedCongestionLevel(uint64_t measurementWindow, double &congestionLevel) const
uint64_t sentTimestamp
Definition: sockettracker.h:50