My Project
TimingAnalysis.h
1 // Copyright 2023 DreamWorks Animation LLC
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include "TimingRecorderHydra.h"
7 
8 #include <mcrt_dataio/engine/merger/GlobalNodeInfo.h>
9 #include <scene_rdl2/common/grid_util/Parser.h>
10 
11 namespace mcrt_dataio {
12 
14 //
15 // A single event of the analysis result
16 //
17 {
18 public:
19  TimingLogEvent(int rankId, float timeStamp, float localTimeStamp, const std::string& description)
20  : mRankId(rankId)
21  , mTimeStamp(timeStamp)
22  , mLocalTimeStamp(localTimeStamp)
23  , mDescription(description)
24  {}
25 
26  int rankIdLen() const;
27  int secStrLenTimeStamp() const { return secStrLen(mTimeStamp); }
28  int secStrLenLocalTimeStamp() const { return secStrLen(mLocalTimeStamp); }
29  int secStrLenDeltaTimeStamp(const TimingLogEvent* prev) const;
30 
31  std::string show(int rankIdLen = 0,
32  int maxTimeLen = 0,
33  int maxLocalTimeLen = 0,
34  int maxDeltaTimeLen = 0,
35  const TimingLogEvent* prev = nullptr) const;
36 
37 private:
38 
39  std::string showClient() const;
40  std::string showRankId() const;
41 
42  static int secStrLen(float sec);
43 
44  //------------------------------
45 
46  int mRankId; // -1:client 0orPositive:mcrt
47  float mTimeStamp; // sec from baseTime
48  float mLocalTimeStamp; // sec from local block
49  std::string mDescription;
50 };
51 
52 class TimingLog
53 //
54 // Timing analysis result from the beginning of render starts at the client to the end of displaying
55 // 1st received an image from backend via backend computation.
56 //
57 {
58 public:
59  TimingLog()
60  : mBaseTime(0)
61  {}
62 
63  void setBaseTime(uint64_t time) { mBaseTime = time; }
64  void setRecvImgSenderMachineId(const std::string& name) { mRecvImgSenderMachineId = name; }
65 
66  // rankId = -1 : client
67  // rankId >= 0 : mcrt computation
68  void enqEvent(int rankId, float timeStamp, float localTimeStamp, const std::string& description) {
69  mEventTable.emplace_back(rankId, timeStamp, localTimeStamp, description);
70  }
71 
72  std::string show() const;
73 
74 private:
75  uint64_t mBaseTime;
76  std::string mRecvImgSenderMachineId;
77 
78  std::vector<TimingLogEvent> mEventTable;
79 };
80 
82 //
83 // Timing analysis of TimingRecorderHydra.
84 //
85 {
86 public:
87  using Arg = scene_rdl2::grid_util::Arg;
88  using Parser = scene_rdl2::grid_util::Parser;
89 
90  TimingAnalysis(GlobalNodeInfo& globalNodeInfo);
91 
92  void setTimingRecorderHydra(std::shared_ptr<TimingRecorderHydra> timingRecorderHydra);
93 
94  Parser& getParser() { return mParser; }
95 
96 private:
97  using TimingLogShPtr = std::shared_ptr<TimingLog>;
98 
99  void parserConfigure();
100 
101  TimingLogShPtr make1stRecvImgTimingLogHydra() const;
102  void makeTimingLogMcrt(std::shared_ptr<McrtNodeInfo> nodeInfo, TimingLogShPtr log) const;
103 
104  float deltaSecMcrtToClient(float mcrtDeltaSec, std::shared_ptr<McrtNodeInfo> nodeInfo) const;
105 
106  std::string show1stRecvImgLogHydra() const;
107 
108  //------------------------------
109 
110  GlobalNodeInfo& mGlobalNodeInfo;
111  std::shared_ptr<TimingRecorderHydra> mTimingRecorderHydra;
112 
113  Parser mParser;
114 };
115 
116 } // namespace mcrt_dataio
Definition: TimingAnalysis.h:13
Definition: TimingAnalysis.h:52
Definition: ClientReceiverConsoleDriver.cc:9
Definition: TimingAnalysis.h:81