Overte C++ Documentation
OctreeSceneStats.h
1 //
2 // OctreeSceneStats.h
3 // libraries/octree/src
4 //
5 // Created by Brad Hefta-Gaub on 7/18/13.
6 // Copyright 2013 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_OctreeSceneStats_h
13 #define hifi_OctreeSceneStats_h
14 
15 #include <stdint.h>
16 
17 #include <NodeList.h>
18 #include <shared/ReadWriteLockable.h>
19 
20 #include "OctreePacketData.h"
21 #include "SequenceNumberStats.h"
22 #include "OctalCode.h"
23 
24 #define GREENISH 0x40ff40d0
25 #define YELLOWISH 0xffef40c0
26 #define GREYISH 0xd0d0d0a0
27 
28 class OctreeElement;
29 
32 public:
35  void reset();
36 
37  OctreeSceneStats(const OctreeSceneStats& other); // copy constructor
38  OctreeSceneStats& operator= (const OctreeSceneStats& other); // copy assignment
39 
41  void sceneStarted(bool fullScene, bool moving, const OctreeElementPointer& root);
42  bool getIsSceneStarted() const { return _isStarted; }
43 
45  void sceneCompleted();
46 
47  void printDebugDetails();
48 
50  void packetSent(int bytes);
51 
53  void encodeStarted();
54 
56  void encodeStopped();
57 
59  void traversed(const OctreeElementPointer& element);
60 
62  void skippedDistance(const OctreeElementPointer& element);
63 
65  void skippedOutOfView(const OctreeElementPointer& element);
66 
68  void skippedWasInView(const OctreeElementPointer& element);
69 
71  void skippedNoChange(const OctreeElementPointer& element);
72 
74  void skippedOccluded(const OctreeElementPointer& element);
75 
77  void colorSent(const OctreeElementPointer& element);
78 
80  void didntFit(const OctreeElementPointer& element);
81 
83  void existsBitsWritten();
84 
87 
89  void childBitsRemoved(bool includesExistsBits);
90 
92  int packIntoPacket();
93 
95  int unpackFromPacket(ReceivedMessage& packet);
96 
98  bool isReadyToSend() const { return _isReadyToSend; }
99 
101  void markAsSent() { _isReadyToSend = false; }
102 
103  NLPacket& getStatsMessage() { return *_statsPacket; }
104 
106  enum Item {
107  ITEM_ELAPSED,
108  ITEM_ENCODE,
109  ITEM_PACKETS,
110  ITEM_VOXELS_SERVER,
111  ITEM_VOXELS,
112  ITEM_COLORS,
113  ITEM_BITS,
114  ITEM_TRAVERSED,
115  ITEM_SKIPPED,
116  ITEM_SKIPPED_DISTANCE,
117  ITEM_SKIPPED_OUT_OF_VIEW,
118  ITEM_SKIPPED_WAS_IN_VIEW,
119  ITEM_SKIPPED_NO_CHANGE,
120  ITEM_SKIPPED_OCCLUDED,
121  ITEM_DIDNT_FIT,
122  ITEM_MODE,
123  ITEM_COUNT
124  };
125 
127  struct ItemInfo {
128  char const* const caption;
129  unsigned colorRGBA;
130  int detailsCount;
131  const char* detailsLabels;
132  };
133 
136  ItemInfo& getItemInfo(Item item) { return _ITEMS[item]; }
137 
140  const char* getItemValue(Item item);
141 
142  bool isMoving() const { return _isMoving; }
143  bool isFullScene() const { return _isFullScene; }
144  quint64 getTotalElements() const { return _totalElements; }
145  quint64 getTotalInternal() const { return _totalInternal; }
146  quint64 getTotalLeaves() const { return _totalLeaves; }
147  quint64 getTotalEncodeTime() const { return _totalEncodeTime; }
148  quint64 getElapsedTime() const { return _elapsed; }
149 
150  quint64 getLastFullElapsedTime() const { return _lastFullElapsed; }
151  quint64 getLastFullTotalEncodeTime() const { return _lastFullTotalEncodeTime; }
152  quint32 getLastFullTotalPackets() const { return _lastFullTotalPackets; }
153  quint64 getLastFullTotalBytes() const { return _lastFullTotalBytes; }
154 
155  // Used in client implementations to track individual octree packets
156  void trackIncomingOctreePacket(ReceivedMessage& message, bool wasStatsPacket, qint64 nodeClockSkewUsec);
157 
158  quint32 getIncomingPackets() const { return _incomingPacket; }
159  quint64 getIncomingBytes() const { return _incomingBytes; }
160  quint64 getIncomingWastedBytes() const { return _incomingWastedBytes; }
161  float getIncomingFlightTimeAverage() { return _incomingFlightTimeAverage.getAverage(); }
162 
163  const SequenceNumberStats& getIncomingOctreeSequenceNumberStats() const { return _incomingOctreeSequenceNumberStats; }
164  SequenceNumberStats& getIncomingOctreeSequenceNumberStats() { return _incomingOctreeSequenceNumberStats; }
165 
166 private:
167 
168  void copyFromOther(const OctreeSceneStats& other);
169 
170  bool _isReadyToSend;
171 
172  std::unique_ptr<NLPacket> _statsPacket = NLPacket::create(PacketType::OctreeStats, -1, true);
173 
174  // scene timing data in usecs
175  bool _isStarted;
176  quint64 _start;
177  quint64 _end;
178  quint64 _elapsed;
179 
180  quint64 _lastFullElapsed;
181  quint64 _lastFullTotalEncodeTime;
182  quint32 _lastFullTotalPackets;
183  quint64 _lastFullTotalBytes;
184 
185  SimpleMovingAverage _elapsedAverage;
186  SimpleMovingAverage _bitsPerOctreeAverage;
187 
188  quint64 _totalEncodeTime;
189  quint64 _encodeStart;
190 
191  // scene octree related data
192  quint64 _totalElements;
193  quint64 _totalInternal;
194  quint64 _totalLeaves;
195 
196  quint64 _traversed;
197  quint64 _internal;
198  quint64 _leaves;
199 
200  quint64 _skippedDistance;
201  quint64 _internalSkippedDistance;
202  quint64 _leavesSkippedDistance;
203 
204  quint64 _skippedOutOfView;
205  quint64 _internalSkippedOutOfView;
206  quint64 _leavesSkippedOutOfView;
207 
208  quint64 _skippedWasInView;
209  quint64 _internalSkippedWasInView;
210  quint64 _leavesSkippedWasInView;
211 
212  quint64 _skippedNoChange;
213  quint64 _internalSkippedNoChange;
214  quint64 _leavesSkippedNoChange;
215 
216  quint64 _skippedOccluded;
217  quint64 _internalSkippedOccluded;
218  quint64 _leavesSkippedOccluded;
219 
220  quint64 _colorSent;
221  quint64 _internalColorSent;
222  quint64 _leavesColorSent;
223 
224  quint64 _didntFit;
225  quint64 _internalDidntFit;
226  quint64 _leavesDidntFit;
227 
228  quint64 _colorBitsWritten;
229  quint64 _existsBitsWritten;
230  quint64 _existsInPacketBitsWritten;
231  quint64 _treesRemoved;
232 
233  // Accounting Notes:
234  //
235  // 1) number of octrees sent can be calculated as _colorSent + _colorBitsWritten. This works because each internal
236  // element in a packet will have a _colorBitsWritten included for it and each "leaf" in the packet will have a
237  // _colorSent written for it. Note that these "leaf" elements in the packets may not be actual leaves in the full
238  // tree, because LOD may cause us to send an average color for an internal element instead of recursing deeper to
239  // the leaves.
240  //
241  // 2) the stats balance if: (working assumption)
242  // if _colorSent > 0
243  // _traversed = all skipped + _colorSent + _colorBitsWritten
244  // else
245  // _traversed = all skipped + _colorSent + _colorBitsWritten + _treesRemoved
246  //
247 
248  // scene network related data
249  quint32 _packets;
250  quint64 _bytes;
251  quint32 _passes;
252 
253  // incoming packets stats
254  quint32 _incomingPacket;
255  quint64 _incomingBytes;
256  quint64 _incomingWastedBytes;
257 
258  SequenceNumberStats _incomingOctreeSequenceNumberStats;
259 
260  SimpleMovingAverage _incomingFlightTimeAverage;
261 
262  // features related items
263  bool _isMoving;
264  bool _isFullScene;
265 
266 
267  static ItemInfo _ITEMS[];
268  static const int MAX_ITEM_VALUE_LENGTH = 128;
269  char _itemValueBuffer[MAX_ITEM_VALUE_LENGTH];
270 };
271 
274 class NodeToOctreeSceneStats : public std::map<QUuid, OctreeSceneStats>, public ReadWriteLockable {};
275 typedef NodeToOctreeSceneStats::iterator NodeToOctreeSceneStatsIterator;
276 
277 #endif // hifi_OctreeSceneStats_h
Definition: OctreeSceneStats.h:274
Collects statistics for calculating and sending a scene from a octree server to an interface client.
Definition: OctreeSceneStats.h:31
void sceneStarted(bool fullScene, bool moving, const OctreeElementPointer &root)
Call when beginning the computation of a scene. Initializes internal structures.
Definition: OctreeSceneStats.cpp:122
int packIntoPacket()
Pack the details of the statistics into a buffer for sending as a network packet.
Definition: OctreeSceneStats.cpp:304
const char * getItemValue(Item item)
Definition: OctreeSceneStats.cpp:478
void traversed(const OctreeElementPointer &element)
Track that a element was traversed as part of computation of a scene.
Definition: OctreeSceneStats.cpp:215
void skippedOccluded(const OctreeElementPointer &element)
Track that a element was skipped as part of computation of a scene due to being occluded.
Definition: OctreeSceneStats.cpp:260
void existsInPacketBitsWritten()
Track that the exists in packet bitmask was was sent as part of computation of a scene.
Definition: OctreeSceneStats.cpp:291
void skippedDistance(const OctreeElementPointer &element)
Track that a element was skipped as part of computation of a scene due to being beyond the LOD distan...
Definition: OctreeSceneStats.cpp:224
void existsBitsWritten()
Track that the exists in tree bitmask was was sent as part of computation of a scene.
Definition: OctreeSceneStats.cpp:287
bool isReadyToSend() const
Indicates that a scene has been completed and the statistics are ready to be sent.
Definition: OctreeSceneStats.h:98
void encodeStopped()
Tracks the ending of an encode pass during scene calculation.
Definition: OctreeSceneStats.cpp:156
void childBitsRemoved(bool includesExistsBits)
Fix up tracking statistics in case where bitmasks were removed for some reason.
Definition: OctreeSceneStats.cpp:295
void didntFit(const OctreeElementPointer &element)
Track that a element was due to be sent, but didn't fit in the packet and was moved to next packet.
Definition: OctreeSceneStats.cpp:278
int unpackFromPacket(ReceivedMessage &packet)
Unpack the details of the statistics from a network packet.
Definition: OctreeSceneStats.cpp:342
void sceneCompleted()
Call when the computation of a scene is completed. Finalizes internal structures.
Definition: OctreeSceneStats.cpp:135
void skippedWasInView(const OctreeElementPointer &element)
Track that a element was skipped as part of computation of a scene due to previously being in view wh...
Definition: OctreeSceneStats.cpp:242
void skippedNoChange(const OctreeElementPointer &element)
Track that a element was skipped as part of computation of a scene due to not having changed since la...
Definition: OctreeSceneStats.cpp:251
void packetSent(int bytes)
Track that a packet was sent as part of the scene.
Definition: OctreeSceneStats.cpp:210
Item
List of various items tracked by OctreeSceneStats which can be accessed via getItemInfo() and getItem...
Definition: OctreeSceneStats.h:106
void skippedOutOfView(const OctreeElementPointer &element)
Track that a element was skipped as part of computation of a scene due to being out of view.
Definition: OctreeSceneStats.cpp:233
void markAsSent()
Mark that the scene statistics have been sent.
Definition: OctreeSceneStats.h:101
ItemInfo & getItemInfo(Item item)
Definition: OctreeSceneStats.h:136
void colorSent(const OctreeElementPointer &element)
Track that a element's color was was sent as part of computation of a scene.
Definition: OctreeSceneStats.cpp:269
void encodeStarted()
Tracks the beginning of an encode pass during scene calculation.
Definition: OctreeSceneStats.cpp:152
Meta information about each stats item.
Definition: OctreeSceneStats.h:127