My Project
ClientReceiverStats.h
1 // Copyright 2023 DreamWorks Animation LLC
2 // SPDX-License-Identifier: Apache-2.0
3 
4 //
5 // -- ProgressiveFrame message receiver statistic information --
6 //
7 // This file includes ClientReceiverStats class and it is used for performance analyzing about
8 // ProgressiveFrame receiver by frontend client in order to breakdown latency value, data receive fps,
9 // and received message size information. Only used for debugging purpose.<br>
10 //
11 #pragma once
12 
13 #include <scene_rdl2/common/platform/Platform.h> // finline
14 #include <scene_rdl2/common/rec_time/RecTime.h>
15 
16 namespace mcrt_dataio {
17 
19 public:
21  mLatencyAll(0.0f),
22  mLatencyTotal(0),
23  mRecvMsgIntervalAll(0.0f),
24  mRecvMsgIntervalTotal(0),
25  mRecvMsgSizeAll(0),
26  mRecvMsgSizeTotal(0)
27  {}
28 
29  // Reset all internal information and back to default condition
30  finline void reset();
31 
32  // Update onMessage() call interval
33  // This API is updated internal info to measure onMessage() call interval.
34  // Everytime you receive message inside onMessage() you should call this API once.
35  void updateMsgInterval();
36 
37  // Update snapshot latency timing log
38  // latencySec : Seconds since snapshot at backend computation to process at the client.
39  // This API is updated latency info from snapshotStartTime to current time.
40  // Everytime you receive message inside onMessage() you should call this API once with proper argument
41  // for update latency.
42  void updateLatency(const float latencySec);
43 
44  // Update received message size log
45  // byte : Received message size
46  // This API is updated received data size.
47  // Everytime you receive message inside onMessage() you should call this API once with proper argument
48  // for update received message size info.
49  void updateRecvMsgSize(const uint64_t byte);
50 
51  // Show client receiver statistical info
52  // elapsedSecFromStart : Elapsed second from start rendering. This is only used for header of output strings
53  // return : Formatted strings to dump all statistical information about client receiver
54  // Return formatted strings to dump all statistical information about client receiver.
55  // This includes latency (= time from MCRT snapshot to current), fps (= frequency of received message) and
56  // received message size (byte).
57  // All recorded informations are averaged between every show() call and created formatted strings for
58  // display.
59  // Argument elapsedSecFromStart is just used for elapsed time display purpose and not used for other
60  // internal result calculation.
61  std::string show(const float elapsedSecFromStart) const;
62 
63 protected:
64  float mLatencyAll;
65  uint64_t mLatencyTotal;;
66 
67  scene_rdl2::rec_time::RecTime mRecvMsgIntervalTime;
68  float mRecvMsgIntervalAll; // interval (sec) of onMessage()
69  uint64_t mRecvMsgIntervalTotal;
70 
71  uint64_t mRecvMsgSizeAll;
72  uint64_t mRecvMsgSizeTotal;
73 
74  //------------------------------
75 
76  float calcAveLatency() const {
77  return (mLatencyTotal)? (mLatencyAll / (float)mLatencyTotal * 1000.0f): 0.0f; // ms
78  }
79  finline float calcFps() const; // Frame Per Sec
80  finline float calcBps() const; // Byte Per Sec
81  finline uint64_t calcAveRecvMsgSize() const;
82  std::string byteStr(const uint64_t size) const; // convert byte size to string
83  std::string bpsStr(const float bps) const; // convert byte/sec info to string
84 }; // ClientReceiverStats
85 
86 finline void
87 ClientReceiverStats::reset()
88 {
89  mLatencyAll = 0.0f;
90  mLatencyTotal = 0;
91  mRecvMsgIntervalAll = 0.0f;
92  mRecvMsgIntervalTotal = 0;
93  mRecvMsgSizeAll = 0;
94  mRecvMsgSizeTotal = 0;
95 }
96 
97 finline float
98 ClientReceiverStats::calcFps() const
99 {
100  if (mRecvMsgIntervalAll > 0.0f && mRecvMsgIntervalTotal > 0) {
101  return (1.0f / (mRecvMsgIntervalAll / (float)mRecvMsgIntervalTotal));
102  }
103  return 0.0f;
104 }
105 
106 finline float
107 ClientReceiverStats::calcBps() const
108 {
109  if (mRecvMsgIntervalAll > 0.0f) {
110  return (float)mRecvMsgSizeAll / mRecvMsgIntervalAll;
111  }
112  return 0.0f;
113 }
114 
115 finline uint64_t
116 ClientReceiverStats::calcAveRecvMsgSize() const
117 {
118  if (mRecvMsgSizeTotal) {
119  return mRecvMsgSizeAll / mRecvMsgSizeTotal;
120  }
121  return 0;
122 }
123 
124 } // namespace mcrt_dataio
Definition: ClientReceiverStats.h:18
Definition: ClientReceiverConsoleDriver.cc:9