2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #ifndef GUILIB_GUICONTROLPROFILER_H__
22 #define GUILIB_GUICONTROLPROFILER_H__
25 #include "GUIControl.h"
27 class CGUIControlProfiler;
30 class CGUIControlProfilerItem
33 CGUIControlProfiler *m_pProfiler;
34 CGUIControlProfilerItem * m_pParent;
35 CGUIControl *m_pControl;
36 std::vector<CGUIControlProfilerItem *> m_vecChildren;
37 CStdString m_strDescription;
39 CGUIControl::GUICONTROLTYPES m_ControlType;
40 unsigned int m_visTime;
41 unsigned int m_renderTime;
42 int64_t m_i64VisStart;
43 int64_t m_i64RenderStart;
45 CGUIControlProfilerItem(CGUIControlProfiler *pProfiler, CGUIControlProfilerItem *pParent, CGUIControl *pControl);
46 ~CGUIControlProfilerItem(void);
48 void Reset(CGUIControlProfiler *pProfiler);
49 void BeginVisibility(void);
50 void EndVisibility(void);
51 void BeginRender(void);
53 void SaveToXML(TiXmlElement *parent);
54 unsigned int GetTotalTime(void) const { return m_visTime + m_renderTime; };
56 CGUIControlProfilerItem *AddControl(CGUIControl *pControl);
57 CGUIControlProfilerItem *FindOrAddControl(CGUIControl *pControl, bool recurse);
60 class CGUIControlProfiler
63 static CGUIControlProfiler &Instance(void);
64 static bool IsRunning(void);
68 void BeginVisibility(CGUIControl *pControl);
69 void EndVisibility(CGUIControl *pControl);
70 void BeginRender(CGUIControl *pControl);
71 void EndRender(CGUIControl *pControl);
72 int GetMaxFrameCount(void) const { return m_iMaxFrameCount; };
73 void SetMaxFrameCount(int iMaxFrameCount) { m_iMaxFrameCount = iMaxFrameCount; };
74 void SetOutputFile(const CStdString &strOutputFile) { m_strOutputFile = strOutputFile; };
75 const CStdString &GetOutputFile(void) const { return m_strOutputFile; };
76 bool SaveResults(void);
77 unsigned int GetTotalTime(void) const { return m_ItemHead.GetTotalTime(); };
81 CGUIControlProfiler(void);
82 ~CGUIControlProfiler(void) {};
83 CGUIControlProfiler(const CGUIControlProfiler &that);
84 CGUIControlProfiler &operator=(const CGUIControlProfiler &that);
86 CGUIControlProfilerItem m_ItemHead;
87 CGUIControlProfilerItem *m_pLastItem;
88 CGUIControlProfilerItem *FindOrAddControl(CGUIControl *pControl);
90 static bool m_bIsRunning;
91 CStdString m_strOutputFile;
96 #define GUIPROFILER_VISIBILITY_BEGIN(x) { if (CGUIControlProfiler::IsRunning()) CGUIControlProfiler::Instance().BeginVisibility(x); }
97 #define GUIPROFILER_VISIBILITY_END(x) { if (CGUIControlProfiler::IsRunning()) CGUIControlProfiler::Instance().EndVisibility(x); }
98 #define GUIPROFILER_RENDER_BEGIN(x) { if (CGUIControlProfiler::IsRunning()) CGUIControlProfiler::Instance().BeginRender(x); }
99 #define GUIPROFILER_RENDER_END(x) { if (CGUIControlProfiler::IsRunning()) CGUIControlProfiler::Instance().EndRender(x); }