My Project
TelemetryLayout.h
1 // Copyright 2023 DreamWorks Animation LLC
2 // SPDX-License-Identifier: Apache-2.0
3 #pragma once
4 
5 #include "TelemetryOverlay.h"
6 
7 #include <mcrt_dataio/engine/mcrt/McrtNodeInfo.h>
8 #include <mcrt_messages/BaseFrame.h>
9 
10 namespace mcrt_dataio {
11 
12 class GlobalNodeInfo;
13 
14 namespace telemetry {
15 
16 class DisplayInfo;
17 
19 {
20 public:
21  using Arg = scene_rdl2::grid_util::Arg;
22  using Parser = scene_rdl2::grid_util::Parser;
23 
24  LayoutBase(std::shared_ptr<Overlay> overlay, std::shared_ptr<Font> font);
25  virtual ~LayoutBase() {}
26 
27  virtual const char* getName() const = 0;
28 
29  virtual void drawMain(const DisplayInfo& info) = 0;
30 
31  Parser& getParser() { return mParser; }
32 
33 protected:
34 
35  void parserConfigure();
36 
37  //
38  // draw utility functions
39  //
40  std::string colFg(const C3& c) const;
41  std::string colBg(const C3& c) const;
42  std::string colReset() const { return colFg(mCharFg) + colBg(mCharBg); }
43  std::string strFps(float v) const;
44  std::string strPct(float fraction) const;
45  std::string strSec(float sec) const;
46  std::string strMillisec(float millisec) const;
47  std::string strByte(size_t size) const;
48  std::string strBps(float bps) const;
49  std::string strBar(unsigned barWidth,
50  unsigned fontStepX,
51  const std::string& title,
52  float fraction,
53  bool usageMode,
54  unsigned* barStartOffsetPixX = nullptr,
55  unsigned* barEndOffsetPixX = nullptr,
56  unsigned* barHeight = nullptr) const;
57  std::string strBool(bool flag) const;
58  std::string strFrameStatus(const mcrt::BaseFrame::Status& status,
59  const float renderPrepProgress) const;
60  std::string strPassStatus(bool isCoarsePass) const;
61  std::string strExecMode(const McrtNodeInfo::ExecMode& execMode) const;
62 
63  void drawBoxBar(unsigned leftX, unsigned leftY,
64  unsigned barStartOffsetPixX, unsigned barEndOffsetPixX,
65  unsigned barHeight,
66  float fraction,
67  const C3& c, unsigned char alpha);
68 
69  std::string showC3(const C3& c) const;
70 
71  unsigned char getArgC0255(Arg& arg) const;
72  C3 getArgC3(Arg& arg) const;
73 
74  //------------------------------
75 
76  C3 mCharFg {255, 255, 255};
77  C3 mCharBg {0, 0, 0};
78 
79  C3 mPanelBg {32, 32, 32};
80  float mPanelBgAlpha {200};
81 
82  std::shared_ptr<Overlay> mOverlay;
83  std::shared_ptr<Font> mFont;
84 
85  unsigned mMaxYLines {0};
86  unsigned mOffsetBottomPixY {0};
87  unsigned mStepPixY {0};
88 
89  std::string mError;
90 
91  Parser mParser;
92 };
93 
94 class LayoutUtil : public LayoutBase
95 {
96 public:
97  LayoutUtil(std::shared_ptr<Overlay> overlay, std::shared_ptr<Font> font)
98  : LayoutBase(overlay, font)
99  {}
100 
101 protected:
102  void drawUtilGlobalInfo(const std::string& msg,
103  unsigned x,
104  unsigned y,
105  Overlay::BBox2i& bboxGlobalInfo);
106  void drawUtilGlobalProgressBar(unsigned barLeftBottomX,
107  unsigned barLeftBottomY,
108  unsigned barWidth,
109  const DisplayInfo& info,
110  Overlay::BBox2i& bboxGlobalProgressBar);
111 };
112 
113 class LayoutDevel : public LayoutUtil
114 {
115 public:
116  using Arg = scene_rdl2::grid_util::Arg;
117  using Parser = scene_rdl2::grid_util::Parser;
118 
119  LayoutDevel(std::shared_ptr<Overlay> overlay, std::shared_ptr<Font> font)
120  : LayoutUtil(overlay, font)
121  {
122  parserConfigure();
123  }
124 
125  const char* getName() const override { return "devel"; }
126 
127  void drawMain(const DisplayInfo& info) override;
128 
129 private:
130 
131  void drawGlobalInfo(const DisplayInfo& info);
132  void drawDispatchMergeComputation(const DisplayInfo& info);
133  void drawGlobalProgressBar(const DisplayInfo& info);
134  void drawMcrtComputation(const DisplayInfo& info);
135 
136  void parserConfigure();
137 
138  //------------------------------
139 
140  Overlay::BBox2i mBBoxGlobalInfo;
141  Overlay::BBox2i mBBoxGlobalProgressBar;
142  Overlay::BBox2i mBBoxDispatchMergeComputation;
143  Overlay::BBox2i mBBoxMcrtComputation;
144 
145  struct BarPos {
146  unsigned mY;
147  unsigned mXoffset[3] {0,0,0};
148  unsigned mXmin[3] {0,0,0};
149  unsigned mXmax[3] {0,0,0};
150  unsigned mHeight[3] {0,0,0};
151  float mFraction[3] {0.0f, 0.0f, 0.0f};
152  };
153  std::vector<BarPos> mBarPosArray;
154 };
155 
157 {
158 public:
159  LayoutCorePerf(std::shared_ptr<Overlay> overlay, std::shared_ptr<Font> font)
160  : LayoutUtil(overlay, font)
161  {}
162 
163  const char* getName() const override { return "corePerf"; }
164 
165  void drawMain(const DisplayInfo& info) override;
166 
167 private:
168  struct McrtPos {
169  unsigned mY {0}; // Left top character output position
170  unsigned mYStep {0};
171 
172  unsigned mRowCoreNum {0};
173  unsigned mNumOfRows {0}; // row count
174 
175  unsigned mTitleWidthChar {0};
176 
177  unsigned mCoreWinXMin {0};
178  unsigned mCoreWinXMax {0};
179  unsigned mCoreWinYMin {0};
180  unsigned mCoreWinYMax {0};
181  unsigned mSingleCoreGapX {0};
182  unsigned mSingleCoreWidth {0};
183  };
184 
185  void drawGlobalInfo(const DisplayInfo& info);
186  void drawGlobalProgressBar(const DisplayInfo& info);
187  void drawMcrtComputation(const DisplayInfo& info);
188 
189  bool setupCorePerfRowInfo(const GlobalNodeInfo* gNodeinfo, unsigned yMax);
190  unsigned calcMinRowCoreNum(const GlobalNodeInfo* gNodeInfo, unsigned yMax) const;
191  unsigned calcMinRowMcrtComputation(const GlobalNodeInfo* gNodeInfo) const;
192 
193  std::string drawSingleNodeTitle(size_t mcrtTotal,
194  std::shared_ptr<McrtNodeInfo> node,
195  unsigned numOfRow) const;
196  void drawCorePerfSingleNode(std::shared_ptr<McrtNodeInfo> node, const McrtPos& mcrtPos);
197 
198  //------------------------------
199 
200  unsigned mComputeRowInfoMcrtTotal {0};
201  unsigned mRowCoreNum {0};
202  unsigned mMinRowMcrtComputation {0};
203 
204  Overlay::BBox2i mBBoxGlobalInfo;
205  Overlay::BBox2i mBBoxGlobalProgressBar;
206  Overlay::BBox2i mBBoxMcrtComputation;
207 
208  std::vector<McrtPos> mMcrtPosArray;
209 };
210 
211 } // namespace telemetry
212 } // namespace mcrt_dataio
Definition: TelemetryOverlay.h:25
Definition: TelemetryDisplay.h:20
Definition: TelemetryLayout.h:94
Definition: TelemetryLayout.h:18
Definition: TelemetryLayout.h:113
Definition: ClientReceiverConsoleDriver.cc:9
Definition: TelemetryLayout.h:156