Add some rough performance reporting.

Make the profiler converge a bit faster.

This was SVN commit r8939.
This commit is contained in:
Ykkrosh 2011-02-19 03:14:37 +00:00
parent 3e13c300cc
commit f3372bf11d
8 changed files with 115 additions and 5 deletions

View File

@ -83,6 +83,23 @@ function init(initData, hotloadData)
getGUIObjectByName("civIcon").sprite = "stretched:"+g_CivData[g_Players[Engine.GetPlayerID()].civ].Emblem;
onSimulationUpdate();
// Report the performance after 5 seconds (when we're still near
// the initial camera view) and a minute (when the profiler will
// have settled down if framerates as very low), to give some
// extremely rough indications of performance
setTimeout(function() { reportPerformance(5); }, 5000);
setTimeout(function() { reportPerformance(60); }, 60000);
}
function reportPerformance(time)
{
var data = {
time: time,
map: Engine.GetMapSettings().Name,
profiler: Engine.GetProfilerState()
};
Engine.SubmitUserReport("profile", 1, JSON.stringify(data));
}
function leaveGame()

View File

@ -279,7 +279,7 @@ void CMapWriter::WriteXML(const VfsPath& filename,
if (pSimulation2)
{
std::string settings = pSimulation2->GetMapSettings();
std::string settings = pSimulation2->GetMapSettingsString();
if (!settings.empty())
{
XML_Element("ScriptSettings");

View File

@ -36,6 +36,7 @@
#include "ps/Game.h"
#include "ps/Hotkey.h"
#include "ps/Overlay.h"
#include "ps/ProfileViewer.h"
#include "ps/Pyrogenesis.h"
#include "ps/UserReport.h"
#include "ps/GameSetup/Atlas.h"
@ -317,6 +318,18 @@ CScriptVal LoadMapSettings(void* cbdata, std::wstring pathname)
return reader.GetMapSettings(guiManager->GetScriptInterface()).get();
}
CScriptVal GetMapSettings(void* cbdata)
{
CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
if (!g_Game)
return CScriptVal();
return guiManager->GetScriptInterface().CloneValueFromOtherContext(
g_Game->GetSimulation2()->GetScriptInterface(),
g_Game->GetSimulation2()->GetMapSettings().get());
}
/**
* Start / stop camera following mode
* @param entityid unit id to follow. If zero, stop following mode
@ -343,6 +356,12 @@ void DisplayErrorDialog(void* UNUSED(cbdata), std::wstring msg)
debug_DisplayError(msg.c_str(), DE_NO_DEBUG_INFO, NULL, NULL, NULL, 0, NULL, NULL);
}
CScriptVal GetProfilerState(void* cbdata)
{
CGUIManager* guiManager = static_cast<CGUIManager*> (cbdata);
return g_ProfileViewer.SaveToJS(guiManager->GetScriptInterface());
}
bool IsUserReportEnabled(void* UNUSED(cbdata))
@ -469,10 +488,12 @@ void GuiScriptingInit(ScriptInterface& scriptInterface)
scriptInterface.RegisterFunction<void, &RestartInAtlas>("RestartInAtlas");
scriptInterface.RegisterFunction<bool, &AtlasIsAvailable>("AtlasIsAvailable");
scriptInterface.RegisterFunction<CScriptVal, std::wstring, &LoadMapSettings>("LoadMapSettings");
scriptInterface.RegisterFunction<CScriptVal, &GetMapSettings>("GetMapSettings");
scriptInterface.RegisterFunction<void, entity_id_t, &CameraFollow>("CameraFollow");
scriptInterface.RegisterFunction<void, entity_id_t, &CameraFollowFPS>("CameraFollowFPS");
scriptInterface.RegisterFunction<bool, std::string, &HotkeyIsPressed_>("HotkeyIsPressed");
scriptInterface.RegisterFunction<void, std::wstring, &DisplayErrorDialog>("DisplayErrorDialog");
scriptInterface.RegisterFunction<CScriptVal, &GetProfilerState>("GetProfilerState");
// User report functions
scriptInterface.RegisterFunction<bool, &IsUserReportEnabled>("IsUserReportEnabled");

View File

@ -28,7 +28,7 @@
#include "ps/ThreadUtil.h"
#define PROFILE_AMORTIZE
#define PROFILE_AMORTIZE_FRAMES 50
#define PROFILE_AMORTIZE_FRAMES 30
class CProfileManager;
class CProfileNodeTable;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2011 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -36,6 +36,7 @@
#include "lib/external_libraries/sdl.h"
#include "lib/res/graphics/unifont.h"
#include "renderer/Renderer.h"
#include "scriptinterface/ScriptInterface.h"
extern int g_xres, g_yres;
@ -429,6 +430,47 @@ namespace
const WriteTable& operator=(const WriteTable&);
};
struct DumpTable
{
ScriptInterface& scriptInterface;
CScriptVal root;
DumpTable(ScriptInterface& scriptInterface, CScriptVal root) :
scriptInterface(scriptInterface), root(root)
{
}
void operator() (AbstractProfileTable* table)
{
scriptInterface.SetProperty(root.get(), table->GetTitle().c_str(), DumpRows(table));
}
CScriptVal DumpRows(AbstractProfileTable* table)
{
CScriptVal data;
scriptInterface.Eval("({})", data);
const std::vector<ProfileColumn>& columns = table->GetColumns();
for (size_t r = 0; r < table->GetNumberRows(); ++r)
{
CScriptVal 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)));
}
return data;
}
private:
const DumpTable& operator=(const DumpTable&);
};
bool SortByName(AbstractProfileTable* a, AbstractProfileTable* b)
{
return (a->GetName() < b->GetName());
@ -467,6 +509,18 @@ void CProfileViewer::SaveToFile()
m->outputStream.flush();
}
CScriptVal CProfileViewer::SaveToJS(ScriptInterface& scriptInterface)
{
CScriptVal root;
scriptInterface.Eval("({})", root);
std::vector<AbstractProfileTable*> tables = m->rootTables;
sort(tables.begin(), tables.end(), SortByName);
for_each(tables.begin(), tables.end(), DumpTable(scriptInterface, root));
return root;
}
void CProfileViewer::ShowTable(const CStr& table)
{
m->path.clear();

View File

@ -26,6 +26,8 @@
#include "ps/CStr.h"
#include "ps/Singleton.h"
class ScriptInterface;
class CScriptVal;
/**
* Struct ProfileColumn: Describes one column of an AbstractProfileTable.
@ -181,6 +183,12 @@ public:
*/
void SaveToFile();
/**
* SaveToJS: Return a script value containing the current profiler data
* (for all profile tables).
*/
CScriptVal SaveToJS(ScriptInterface& scriptInterface);
/**
* ShowTable: Set the named profile table to be the displayed one. If it
* is not found, no profile is displayed.

View File

@ -419,11 +419,16 @@ void CSimulation2::SetMapSettings(const CScriptValRooted& settings)
m->m_MapSettings = settings;
}
std::string CSimulation2::GetMapSettings()
std::string CSimulation2::GetMapSettingsString()
{
return m->m_ComponentManager.GetScriptInterface().StringifyJSON(m->m_MapSettings.get());
}
CScriptVal CSimulation2::GetMapSettings()
{
return m->m_MapSettings.get();
}
void CSimulation2::LoadPlayerSettings()
{
GetScriptInterface().CallFunctionVoid(GetScriptInterface().GetGlobalObject(), "LoadPlayerSettings", m->m_MapSettings);

View File

@ -100,7 +100,12 @@ public:
/**
* Get the current map settings as a UTF-8 JSON string.
*/
std::string GetMapSettings();
std::string GetMapSettingsString();
/**
* Get the current map settings.
*/
CScriptVal GetMapSettings();
/**
* Reload any scripts that were loaded from the given filename.