kodi
GUIControlProfiler.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "GUIControl.h"
12 
13 #include <vector>
14 
16 class TiXmlElement;
17 
19 {
20 public:
21  CGUIControlProfiler *m_pProfiler;
22  CGUIControlProfilerItem * m_pParent;
23  CGUIControl *m_pControl;
24  std::vector<CGUIControlProfilerItem *> m_vecChildren;
25  std::string m_strDescription;
26  int m_controlID;
27  CGUIControl::GUICONTROLTYPES m_ControlType;
28  unsigned int m_visTime = 0;
29  unsigned int m_renderTime = 0;
30  int64_t m_i64VisStart = 0;
31  int64_t m_i64RenderStart = 0;
32 
35 
36  void Reset(CGUIControlProfiler *pProfiler);
37  void BeginVisibility(void);
38  void EndVisibility(void);
39  void BeginRender(void);
40  void EndRender(void);
41  void SaveToXML(TiXmlElement *parent);
42  unsigned int GetTotalTime(void) const { return m_visTime + m_renderTime; }
43 
44  CGUIControlProfilerItem *AddControl(CGUIControl *pControl);
45  CGUIControlProfilerItem *FindOrAddControl(CGUIControl *pControl, bool recurse);
46 };
47 
49 {
50 public:
51  static CGUIControlProfiler &Instance(void);
52  static bool IsRunning(void);
53 
54  void Start(void);
55  void EndFrame(void);
56  void BeginVisibility(CGUIControl *pControl);
57  void EndVisibility(CGUIControl *pControl);
58  void BeginRender(CGUIControl *pControl);
59  void EndRender(CGUIControl *pControl);
60  int GetMaxFrameCount(void) const { return m_iMaxFrameCount; }
61  void SetMaxFrameCount(int iMaxFrameCount) { m_iMaxFrameCount = iMaxFrameCount; }
62  void SetOutputFile(const std::string& strOutputFile) { m_strOutputFile = strOutputFile; }
63  const std::string& GetOutputFile(void) const { return m_strOutputFile; }
64  bool SaveResults(void);
65  unsigned int GetTotalTime(void) const { return m_ItemHead.GetTotalTime(); }
66 
67  float m_fPerfScale;
68 private:
69  CGUIControlProfiler(void);
70  ~CGUIControlProfiler(void) = default;
71  CGUIControlProfiler(const CGUIControlProfiler &that) = delete;
72  CGUIControlProfiler &operator=(const CGUIControlProfiler &that) = delete;
73 
74  CGUIControlProfilerItem m_ItemHead;
75  CGUIControlProfilerItem *m_pLastItem;
76  CGUIControlProfilerItem *FindOrAddControl(CGUIControl *pControl);
77 
78  static bool m_bIsRunning;
79  std::string m_strOutputFile;
80  int m_iMaxFrameCount = 200;
81  int m_iFrameCount = 0;
82 };
83 
84 #define GUIPROFILER_VISIBILITY_BEGIN(x) { if (CGUIControlProfiler::IsRunning()) CGUIControlProfiler::Instance().BeginVisibility(x); }
85 #define GUIPROFILER_VISIBILITY_END(x) { if (CGUIControlProfiler::IsRunning()) CGUIControlProfiler::Instance().EndVisibility(x); }
86 #define GUIPROFILER_RENDER_BEGIN(x) { if (CGUIControlProfiler::IsRunning()) CGUIControlProfiler::Instance().BeginRender(x); }
87 #define GUIPROFILER_RENDER_END(x) { if (CGUIControlProfiler::IsRunning()) CGUIControlProfiler::Instance().EndRender(x); }
88 
Definition: GUIControlProfiler.h:48
Base class for controls.
Definition: GUIControl.h:83
Definition: GUIControlProfiler.h:18