Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
ProfileViewer.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18/*
19 * Viewing profiling information (timing and other statistics)
20 */
21
22#ifndef INCLUDED_PROFILE_VIEWER
23#define INCLUDED_PROFILE_VIEWER
24
25#include "ps/CStr.h"
26#include "ps/Singleton.h"
27
28#include <cstddef>
29#include <vector>
30
31class CCanvas2D;
32
33/**
34 * Struct ProfileColumn: Describes one column of an AbstractProfileTable.
35 */
37{
38 /// Title of the column
39 CStr title;
40
41 /// Recommended width of the column, in pixels.
42 size_t width;
43
44 ProfileColumn(const CStr& t, size_t w) : title(t), width(w) { }
45};
46
47
48/**
49 * Class AbstractProfileTable: Profile table data model.
50 *
51 * Clients that wish to display debug information in the profile viewer
52 * have to implement this class and hook it into CProfileViewer.
53 *
54 * Note that the profiling system is robust against deletion of
55 * object instances in the sense that it will automatically remove
56 * an AbstractProfileTable instance from its internal records when
57 * you delete it.
58 * Conversely, deleting an AbstractProfileTable instance is the responsibility
59 * of its creator.
60 */
62{
63public:
64 virtual ~AbstractProfileTable();
65
66 /**
67 * GetName: Short descriptive name of this table (should be static).
68 *
69 * @return Descriptive name of this table.
70 */
71 virtual CStr GetName() = 0;
72
73 /**
74 * GetTitle: Longer, explanatory text (can be dynamic).
75 *
76 * @return Title for the table.
77 */
78 virtual CStr GetTitle() = 0;
79
80
81 /**
82 * GetNumberRows
83 *
84 * @return Number of rows in this table.
85 */
86 virtual size_t GetNumberRows() = 0;
87
88 /**
89 * GetColumnDescriptions
90 *
91 * @return A vector describing all columns of the table.
92 */
93 virtual const std::vector<ProfileColumn>& GetColumns() = 0;
94
95 /**
96 * GetCellText
97 *
98 * @param row Row index (the first row has index 0).
99 * @param col Column index (the first column has index 0).
100 *
101 * @return Text to be displayed in the given cell.
102 */
103 virtual CStr GetCellText(size_t row, size_t col) = 0;
104
105 /**
106 * GetChild: Return a row's child table if the child is expandable.
107 *
108 * @param row Row index (the first row has index 0).
109 *
110 * @return Pointer to the child table if the given row has one.
111 * Otherwise, return 0.
112 */
113 virtual AbstractProfileTable* GetChild(size_t row) = 0;
114
115 /**
116 * IsHighlightRow
117 *
118 * @param row Row index (the first row has index 0).
119 *
120 * @return true if the row should be highlighted in a special color.
121 */
122 virtual bool IsHighlightRow(size_t /*row*/) { return false; }
123};
124
125
127
128/**
129 * Class CProfileViewer: Manage and display profiling tables.
130 */
131class CProfileViewer : public Singleton<CProfileViewer>
132{
134
135public:
138
139 /**
140 * RenderProfile: Render the profile display using OpenGL if the user
141 * has enabled it.
142 */
143 void RenderProfile(CCanvas2D& canvas);
144
145 /**
146 * AddRootTable: Add a new profile table as a root table (i.e. the
147 * tables that you cycle through via the profile hotkey).
148 *
149 * @note Tables added via this function are automatically removed from
150 * the list of root tables when they are deleted.
151 *
152 * @param table This table is added as a root table.
153 * @param front If true then the table will be the new first in the list,
154 * else it will be the last.
155 */
156 void AddRootTable(AbstractProfileTable* table, bool front = false);
157
158 /**
159 * SaveToFile: Save the current profiler data (for all profile tables)
160 * to a file in the 'logs' directory.
161 */
162 void SaveToFile();
163
164 /**
165 * ShowTable: Set the named profile table to be the displayed one. If it
166 * is not found, no profile is displayed.
167 *
168 * @param table The table name (matching AbstractProfileTable::GetName),
169 * or the empty string to display no table.
170 */
171 void ShowTable(const CStr& table);
172
173private:
175};
176
177#define g_ProfileViewer CProfileViewer::GetSingleton()
178
179#endif
Class AbstractProfileTable: Profile table data model.
Definition: ProfileViewer.h:62
virtual CStr GetName()=0
GetName: Short descriptive name of this table (should be static).
virtual size_t GetNumberRows()=0
GetNumberRows.
virtual const std::vector< ProfileColumn > & GetColumns()=0
GetColumnDescriptions.
virtual bool IsHighlightRow(size_t)
IsHighlightRow.
Definition: ProfileViewer.h:122
virtual CStr GetTitle()=0
GetTitle: Longer, explanatory text (can be dynamic).
virtual ~AbstractProfileTable()
Definition: ProfileViewer.cpp:99
virtual AbstractProfileTable * GetChild(size_t row)=0
GetChild: Return a row's child table if the child is expandable.
virtual CStr GetCellText(size_t row, size_t col)=0
GetCellText.
Definition: Canvas2D.h:36
Class CProfileViewer: Manage and display profiling tables.
Definition: ProfileViewer.h:132
CProfileViewer()
Definition: ProfileViewer.cpp:165
~CProfileViewer()
Definition: ProfileViewer.cpp:171
void ShowTable(const CStr &table)
ShowTable: Set the named profile table to be the displayed one.
Definition: ProfileViewer.cpp:580
void AddRootTable(AbstractProfileTable *table, bool front=false)
AddRootTable: Add a new profile table as a root table (i.e.
Definition: ProfileViewer.cpp:357
void RenderProfile(CCanvas2D &canvas)
RenderProfile: Render the profile display using OpenGL if the user has enabled it.
Definition: ProfileViewer.cpp:178
void SaveToFile()
SaveToFile: Save the current profiler data (for all profile tables) to a file in the 'logs' directory...
Definition: ProfileViewer.cpp:539
CProfileViewerInternals * m
Definition: ProfileViewer.h:174
Template base class for singletons.
Definition: Singleton.h:35
Definition: ProfileViewer.cpp:56
Struct ProfileColumn: Describes one column of an AbstractProfileTable.
Definition: ProfileViewer.h:37
ProfileColumn(const CStr &t, size_t w)
Definition: ProfileViewer.h:44
size_t width
Recommended width of the column, in pixels.
Definition: ProfileViewer.h:42
CStr title
Title of the column.
Definition: ProfileViewer.h:39