2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "GUIControl.h"
15 class CGUIControlProfiler
;
18 class CGUIControlProfilerItem
21 CGUIControlProfiler
*m_pProfiler
;
22 CGUIControlProfilerItem
* m_pParent
;
23 CGUIControl
*m_pControl
;
24 std::vector
<CGUIControlProfilerItem
*> m_vecChildren
;
25 std::string m_strDescription
;
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;
33 CGUIControlProfilerItem(CGUIControlProfiler
*pProfiler
, CGUIControlProfilerItem
*pParent
, CGUIControl
*pControl
);
34 ~CGUIControlProfilerItem(void);
36 void Reset(CGUIControlProfiler
*pProfiler
);
37 void BeginVisibility(void);
38 void EndVisibility(void);
39 void BeginRender(void);
41 void SaveToXML(TiXmlElement
*parent
);
42 unsigned int GetTotalTime(void) const { return m_visTime
+ m_renderTime
; }
44 CGUIControlProfilerItem
*AddControl(CGUIControl
*pControl
);
45 CGUIControlProfilerItem
*FindOrAddControl(CGUIControl
*pControl
, bool recurse
);
48 class CGUIControlProfiler
51 static CGUIControlProfiler
&Instance(void);
52 static bool IsRunning(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(); }
69 CGUIControlProfiler(void);
70 ~CGUIControlProfiler(void) = default;
71 CGUIControlProfiler(const CGUIControlProfiler
&that
) = delete;
72 CGUIControlProfiler
&operator=(const CGUIControlProfiler
&that
) = delete;
74 CGUIControlProfilerItem m_ItemHead
;
75 CGUIControlProfilerItem
*m_pLastItem
;
76 CGUIControlProfilerItem
*FindOrAddControl(CGUIControl
*pControl
);
78 static bool m_bIsRunning
;
79 std::string m_strOutputFile
;
80 int m_iMaxFrameCount
= 200;
81 int m_iFrameCount
= 0;
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); }