23 #include "precompiled.h"
55 std::vector<AbstractProfileTable*>
path;
90 for(
int idx = (
int)
rootTables.size()-1; idx >= 0; --idx)
96 for(
size_t idx = 0; idx <
path.size(); ++idx)
98 if (
path[idx] != table)
102 if (
path.size() == 0)
121 for(
size_t row = 0; row < numrows; ++row)
131 path.push_back(child);
167 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
170 const std::vector<ProfileColumn>& columns = table->
GetColumns();
173 CStrW font_name = L
"mono-stroke-10";
174 CFont font(font_name);
178 GLint estimate_height;
179 GLint estimate_width;
182 for(
size_t i = 0; i < columns.size(); ++i)
183 estimate_width += (GLint)columns[i].width;
185 estimate_height = 3 + (GLint)numrows;
186 if (
m->
path.size() > 1)
187 estimate_height += 2;
188 estimate_height = lineSpacing*estimate_height;
191 solidTech->BeginPass();
194 solidShader->Uniform(str_color, 0.0f, 0.0f, 0.0f, 0.5f);
197 solidShader->Uniform(str_transform, transform);
199 float backgroundVerts[] = {
200 (float)estimate_width, 0.0f,
202 0.0f, (
float)estimate_height,
203 0.0f, (float)estimate_height,
204 (
float)estimate_width, (float)estimate_height,
205 (
float)estimate_width, 0.0f
207 solidShader->VertexPointer(2, GL_FLOAT, 0, backgroundVerts);
208 solidShader->AssertPointersBound();
209 glDrawArrays(GL_TRIANGLES, 0, 6);
212 solidShader->Uniform(str_transform, transform);
215 for (
size_t row = 0; row < numrows; ++row)
218 solidShader->Uniform(str_color, 1.0f, 1.0f, 1.0f, 0.1f);
220 solidShader->Uniform(str_color, 0.0f, 0.0f, 0.0f, 0.1f);
224 estimate_width-22.f, 2.f,
225 estimate_width-22.f, 2.f-lineSpacing,
227 estimate_width-22.f, 2.f-lineSpacing,
228 -22.f, 2.f-lineSpacing,
231 solidShader->VertexPointer(2, GL_FLOAT, 0, rowVerts);
232 solidShader->AssertPointersBound();
233 glDrawArrays(GL_TRIANGLES, 0, 6);
236 solidShader->Uniform(str_transform, transform);
239 solidTech->EndPass();
244 textTech->BeginPass();
247 textRenderer.
Font(font_name);
248 textRenderer.Color(1.0f, 1.0f, 1.0f);
250 textRenderer.PrintfAt(2.0f, lineSpacing, L
"%hs", table->
GetTitle().c_str());
252 textRenderer.Translate(22.0f, lineSpacing*2.0f, 0.0f);
255 for (
size_t col = 0; col < columns.size(); ++col)
257 CStrW text = columns[col].title.FromUTF8();
263 x += columns[col].width - w;
264 textRenderer.Put(x, 0.0f, text.c_str());
266 colX += columns[col].width;
269 textRenderer.Translate(0.0f, lineSpacing, 0.0f);
272 int currentExpandId = 1;
274 for (
size_t row = 0; row < numrows; ++row)
277 textRenderer.Color(1.0f, 0.5f, 0.5f);
279 textRenderer.Color(1.0f, 1.0f, 1.0f);
283 textRenderer.PrintfAt(-15.0f, 0.0f, L
"%d", currentExpandId);
288 for (
size_t col = 0; col < columns.size(); ++col)
290 CStrW text = table->
GetCellText(row, col).FromUTF8();
296 x += columns[col].width - w;
297 textRenderer.Put(x, 0.0f, text.c_str());
299 colX += columns[col].width;
302 textRenderer.Translate(0.0f, lineSpacing, 0.0f);
305 textRenderer.Color(1.0f, 1.0f, 1.0f);
307 if (
m->
path.size() > 1)
309 textRenderer.Translate(0.0f, lineSpacing, 0.0f);
310 textRenderer.Put(-15.0f, 0.0f, L
"0");
311 textRenderer.Put(0.0f, 0.0f, L
"back to parent");
314 textRenderer.Render();
319 glEnable(GL_DEPTH_TEST);
334 if (k >= SDLK_0 && k <= SDLK_9)
342 std::string hotkey =
static_cast<const char*
>(ev->
ev.
user.
data1);
344 if( hotkey ==
"profile.toggle" )
366 if (i < m->rootTables.size())
377 else if( hotkey ==
"profile.save" )
414 std::vector<CStr> data;
416 const std::vector<ProfileColumn>& columns = table->
GetColumns();
419 for (std::vector<ProfileColumn>::const_iterator col_it = columns.begin();
420 col_it != columns.end(); ++col_it)
421 data.push_back(col_it->title);
424 WriteRows(1, table, data);
428 std::vector<size_t> columnWidths;
429 size_t cols = columns.size();
430 for (
size_t c = 0; c < cols; ++c)
433 for (
size_t i = c; i < data.size(); i += cols)
434 max = std::max(max, data[i].length());
435 columnWidths.push_back(max);
440 f <<
"\n\n" << table->
GetTitle() <<
"\n";
445 for (
size_t r = 0; r < data.size()/cols; ++r)
447 for (
size_t c = 0; c < cols; ++c)
448 f << (c ?
" | " :
"\n")
454 for (
size_t c = 0; c < cols; ++c)
455 f << (c ?
"-|-" :
"\n")
456 << CStr::Repeat(
"-", columnWidths[c]);
462 const std::vector<ProfileColumn>& columns = table->
GetColumns();
467 CStr indentation = CStr::Repeat(
"| ", indent-1);
473 for (
size_t c = 0; c < columns.size(); ++c)
475 data.push_back(indentation + table->
GetCellText(r, c));
480 WriteRows(indent+1, table->
GetChild(r), data);
493 scriptInterface(scriptInterface), root(root)
500 scriptInterface.Eval(L
"({})", t);
501 scriptInterface.SetProperty(t.
get(),
"cols", DumpCols(table));
502 scriptInterface.SetProperty(t.
get(),
"data", DumpRows(table));
504 scriptInterface.SetProperty(root.get(), table->
GetTitle().c_str(), t);
509 std::vector<std::string> titles;
511 const std::vector<ProfileColumn>& columns = table->
GetColumns();
513 for (
size_t c = 0; c < columns.size(); ++c)
514 titles.push_back(columns[c].title);
522 scriptInterface.Eval(
"({})", data);
524 const std::vector<ProfileColumn>& columns = table->
GetColumns();
529 scriptInterface.Eval(
"([])", row);
530 scriptInterface.SetProperty(data.
get(), table->
GetCellText(r, 0).c_str(), row);
533 scriptInterface.SetPropertyInt(row.
get(), 0, DumpRows(table->
GetChild(r)));
535 for (
size_t c = 1; c < columns.size(); ++c)
536 scriptInterface.SetPropertyInt(row.
get(), c, table->
GetCellText(r, c));
566 LOGERROR(L
"Failed to open profile log file");
577 m->
outputStream <<
"================================================================\n\n";
578 m->
outputStream <<
"PS profiler snapshot - " << asctime(localtime(&t));
581 sort(tables.begin(), tables.end(),
SortByName);
582 for_each(tables.begin(), tables.end(), WriteTable(
m->
outputStream));
584 m->
outputStream <<
"\n\n================================================================\n";
591 scriptInterface.
Eval(
"({})", root);
594 sort(tables.begin(), tables.end(),
SortByName);
595 for_each(tables.begin(), tables.end(), DumpTable(scriptInterface, root));
604 if (table.length() > 0)
CMatrix3D GetDefaultGuiMatrix()
ScriptInterface & scriptInterface
bool SortByName(AbstractProfileTable *a, AbstractProfileTable *b)
Trim all white space from the beginning of the string.
void CalculateStringSize(const wchar_t *string, int &w, int &h)
const OsPath & psLogDir()
virtual const std::vector< ProfileColumn > & GetColumns()=0
GetColumnDescriptions.
Class AbstractProfileTable: Profile table data model.
static void out(const wchar_t *fmt,...)
virtual CStr GetName()=0
GetName: Short descriptive name of this table (should be static).
std::vector< AbstractProfileTable * > path
Path from a root table (path[0]) to the currently visible table (path[size-1])
const jsval & get() const
Returns the current value.
std::vector< std::string > DumpCols(AbstractProfileTable *table)
InReaction Input(const SDL_Event_ *ev)
Input: Filter and handle any input events that the profile display is interested in.
A trivial wrapper around a jsval.
shared_ptr< CShaderTechnique > CShaderTechniquePtr
void RenderProfile()
RenderProfile: Render the profile display using OpenGL if the user has enabled it.
void SaveToFile()
SaveToFile: Save the current profiler data (for all profile tables) to a file in the 'logs' directory...
void PostTranslate(float x, float y, float z)
bool profileVisible
Whether the profiling display is currently visible.
void AddRootTable(AbstractProfileTable *table, bool front=false)
AddRootTable: Add a new profile table as a root table (i.e.
void ShowTable(const CStr &table)
ShowTable: Set the named profile table to be the displayed one.
const CProfileViewerInternals & operator=(const CProfileViewerInternals &rhs)
const String & string() const
bool Eval(const char *code)
static bool IsInitialised()
CScriptVal DumpRows(AbstractProfileTable *table)
virtual size_t GetNumberRows()=0
GetNumberRows.
void WriteRows(int indent, AbstractProfileTable *table, std::vector< CStr > &data)
std::vector< AbstractProfileTable * > rootTables
List of root tables.
static InReaction InputThunk(const SDL_Event_ *ev)
InputThunk: Delegate to the singleton's Input() member function if the singleton has been initialized...
CProfileViewerInternals * m
DumpTable(ScriptInterface &scriptInterface, CScriptVal root)
static const AcpiTable ** tables
virtual AbstractProfileTable * GetChild(size_t row)=0
GetChild: Return a row's child table if the child is expandable.
virtual CStr GetTitle()=0
GetTitle: Longer, explanatory text (can be dynamic).
CScriptVal SaveToJS(ScriptInterface &scriptInterface)
SaveToJS: Return a script value containing the current profiler data (for all profile tables)...
WriteTable(std::ofstream &f)
void Font(const CStrW &font)
Set the font for subsequent print calls.
virtual CStr GetCellText(size_t row, size_t col)=0
GetCellText.
void TableIsDeleted(AbstractProfileTable *table)
Helper functions.
void NavigateTree(int id)
Abstraction around a SpiderMonkey JSContext.
#define PROFILE3_GPU(name)
std::ofstream outputStream
File for saved profile output (reset when the game is restarted)
virtual bool IsHighlightRow(size_t row)
IsHighlightRow.
CProfileViewerInternals()
virtual ~AbstractProfileTable()
shared_ptr< CShaderProgram > CShaderProgramPtr
static std::string OsString(const OsPath &path)