1
1
forked from 0ad/0ad

Make profiler JSON output much more concise.

Right-align values in in-game profile viewer.
Add alternating row shading in profile viewer, to make it easier to
read.

This was SVN commit r9004.
This commit is contained in:
Ykkrosh 2011-03-03 01:09:19 +00:00
parent 16a4eb36dd
commit 1c1564daaf
3 changed files with 59 additions and 19 deletions

View File

@ -99,7 +99,7 @@ function reportPerformance(time)
map: Engine.GetMapSettings().Name,
profiler: Engine.GetProfilerState()
};
Engine.SubmitUserReport("profile", 1, JSON.stringify(data));
Engine.SubmitUserReport("profile", 2, JSON.stringify(data));
}
function leaveGame()

View File

@ -183,13 +183,13 @@ CStr CProfileNodeTable::GetCellText(size_t row, size_t col)
}
if (col == 2)
sprintf_s(buf, ARRAY_SIZE(buf), "%7.3f", unlogged_time_frame * 1000.0f);
sprintf_s(buf, ARRAY_SIZE(buf), "%.3f", unlogged_time_frame * 1000.0f);
else if (col == 3)
sprintf_s(buf, ARRAY_SIZE(buf), "%7.1f", unlogged_mallocs_frame);
sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", unlogged_mallocs_frame);
else if (col == 5)
sprintf_s(buf, ARRAY_SIZE(buf), "%7.3f", unlogged_time_turn * 1000.f);
sprintf_s(buf, ARRAY_SIZE(buf), "%.3f", unlogged_time_turn * 1000.f);
else if (col == 6)
sprintf_s(buf, ARRAY_SIZE(buf), "%7.1f", unlogged_mallocs_turn);
sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", unlogged_mallocs_turn);
return CStr(buf);
}
@ -201,22 +201,22 @@ CStr CProfileNodeTable::GetCellText(size_t row, size_t col)
return child->GetName();
case 1:
sprintf_s(buf, ARRAY_SIZE(buf), "%5.1f", child->GetFrameCalls());
sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", child->GetFrameCalls());
break;
case 2:
sprintf_s(buf, ARRAY_SIZE(buf), "%7.3f", child->GetFrameTime() * 1000.0f);
sprintf_s(buf, ARRAY_SIZE(buf), "%.3f", child->GetFrameTime() * 1000.0f);
break;
case 3:
sprintf_s(buf, ARRAY_SIZE(buf), "%7.1f", child->GetFrameMallocs());
sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", child->GetFrameMallocs());
break;
case 4:
sprintf_s(buf, ARRAY_SIZE(buf), "%5.1f", child->GetTurnCalls());
sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", child->GetTurnCalls());
break;
case 5:
sprintf_s(buf, ARRAY_SIZE(buf), "%7.3f", child->GetTurnTime() * 1000.0f);
sprintf_s(buf, ARRAY_SIZE(buf), "%.3f", child->GetTurnTime() * 1000.0f);
break;
case 6:
sprintf_s(buf, ARRAY_SIZE(buf), "%7.1f", child->GetTurnMallocs());
sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", child->GetTurnMallocs());
break;
}
return CStr(buf);

View File

@ -208,8 +208,13 @@ void CProfileViewer::RenderProfile()
glPushMatrix();
for(size_t col = 0; col < columns.size(); ++col)
{
CStr text = columns[col].title;
int w, h;
font.CalculateStringSize(text.FromUTF8(), w, h);
glPushMatrix();
glwprintf(L"%hs", columns[col].title.c_str());
if (col > 0) // right-align all but the first column
glTranslatef(columns[col].width - w, 0, 0);
glwprintf(L"%hs", text.c_str());
glPopMatrix();
glTranslatef(columns[col].width, 0, 0);
}
@ -223,6 +228,19 @@ void CProfileViewer::RenderProfile()
{
glPushMatrix();
glDisable(GL_TEXTURE_2D);
if (row % 2)
glColor4ub(255, 255, 255, 16);
else
glColor4ub(0, 0, 0, 16);
glBegin(GL_QUADS);
glVertex2i(-22.f, 2.f);
glVertex2i(estimate_width-22.f, 2.f);
glVertex2i(estimate_width-22.f, 2.f-lineSpacing);
glVertex2i(-22.f, 2.f-lineSpacing);
glEnd();
glEnable(GL_TEXTURE_2D);
if (table->IsHighlightRow(row))
glColor3ub(255, 128, 128);
else
@ -239,8 +257,13 @@ void CProfileViewer::RenderProfile()
for(size_t col = 0; col < columns.size(); ++col)
{
CStr text = table->GetCellText(row, col);
int w, h;
font.CalculateStringSize(text.FromUTF8(), w, h);
glPushMatrix();
glwprintf(L"%hs", table->GetCellText(row, col).c_str());
if (col > 0) // right-align all but the first column
glTranslatef(columns[col].width - w, 0, 0);
glwprintf(L"%hs", text.c_str());
glPopMatrix();
glTranslatef(columns[col].width, 0, 0);
}
@ -441,7 +464,24 @@ namespace
void operator() (AbstractProfileTable* table)
{
scriptInterface.SetProperty(root.get(), table->GetTitle().c_str(), DumpRows(table));
CScriptVal t;
scriptInterface.Eval(L"({})", t);
scriptInterface.SetProperty(t.get(), "cols", DumpCols(table));
scriptInterface.SetProperty(t.get(), "data", DumpRows(table));
scriptInterface.SetProperty(root.get(), table->GetTitle().c_str(), t);
}
std::vector<std::string> DumpCols(AbstractProfileTable* table)
{
std::vector<std::string> titles;
const std::vector<ProfileColumn>& columns = table->GetColumns();
for (size_t c = 0; c < columns.size(); ++c)
titles.push_back(columns[c].title);
return titles;
}
CScriptVal DumpRows(AbstractProfileTable* table)
@ -454,14 +494,14 @@ namespace
for (size_t r = 0; r < table->GetNumberRows(); ++r)
{
CScriptVal row;
scriptInterface.Eval("({})", row);
scriptInterface.Eval("([])", row);
scriptInterface.SetProperty(data.get(), table->GetCellText(r, 0).c_str(), row);
for (size_t c = 1; c < columns.size(); ++c)
scriptInterface.SetProperty(row.get(), columns[c].title.c_str(), table->GetCellText(r, c));
if (table->GetChild(r))
scriptInterface.SetProperty(row.get(), "children", DumpRows(table->GetChild(r)));
scriptInterface.SetPropertyInt(row.get(), 0, DumpRows(table->GetChild(r)));
for (size_t c = 1; c < columns.size(); ++c)
scriptInterface.SetPropertyInt(row.get(), c, table->GetCellText(r, c));
}
return data;