Add JS memory usage to profiler.

Add dumpHeaps() console function for debugging JS memory usage.
Increase default JS heap size.
Make call-time profile table appear first when toggling.
Remove some unused script functions.

This was SVN commit r7842.
This commit is contained in:
Ykkrosh
2010-08-02 19:23:58 +00:00
parent 95047013d0
commit b292a32505
13 changed files with 237 additions and 48 deletions
+14 -3
View File
@@ -18,6 +18,7 @@
#include "precompiled.h"
#include "ScriptInterface.h"
#include "ScriptStats.h"
#include "AutoRooters.h"
#include "lib/debug.h"
@@ -34,7 +35,7 @@
#include "valgrind.h"
const int RUNTIME_SIZE = 4 * 1024 * 1024; // TODO: how much memory is needed?
const int RUNTIME_SIZE = 8 * 1024 * 1024; // TODO: how much memory is needed?
const int STACK_CHUNK_SIZE = 8192;
#ifdef NDEBUG
@@ -241,6 +242,7 @@ ScriptInterface_impl::ScriptInterface_impl(const char* nativeScopeName, JSContex
JS_SetOptions(m_cx, JSOPTION_STRICT // "warn on dubious practice"
| JSOPTION_XML // "ECMAScript for XML support: parse <!-- --> as a token"
| JSOPTION_VAROBJFIX // "recommended" (fixes variable scoping)
// | JSOPTION_JIT
);
JS_SetVersion(m_cx, JSVERSION_LATEST);
@@ -281,13 +283,17 @@ void ScriptInterface_impl::Register(const char* name, JSNative fptr, uintN nargs
JS_DefineFunction(m_cx, m_nativeScope, name, fptr, nargs, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT);
}
ScriptInterface::ScriptInterface(const char* nativeScopeName, JSContext* cx) :
m(new ScriptInterface_impl(nativeScopeName, cx))
ScriptInterface::ScriptInterface(const char* nativeScopeName, const char* debugName) :
m(new ScriptInterface_impl(nativeScopeName, NULL))
{
if (g_ScriptStatsTable)
g_ScriptStatsTable->Add(this, debugName);
}
ScriptInterface::~ScriptInterface()
{
if (g_ScriptStatsTable)
g_ScriptStatsTable->Remove(this);
}
void ScriptInterface::ShutDown()
@@ -335,6 +341,11 @@ JSContext* ScriptInterface::GetContext() const
return m->m_cx;
}
JSRuntime* ScriptInterface::GetRuntime() const
{
return m->m_rt;
}
bool ScriptInterface::AddRoot(void* ptr, const char* name)
{
return JS_AddNamedRoot(m->m_cx, ptr, name) ? true : false;
+2 -1
View File
@@ -50,7 +50,7 @@ public:
* @param cx NULL if the object should create and manage its own context; otherwise
* an existing context which it will share
*/
ScriptInterface(const char* nativeScopeName, JSContext* cx = NULL);
ScriptInterface(const char* nativeScopeName, const char* debugName = "Unknown");
~ScriptInterface();
@@ -64,6 +64,7 @@ public:
static void* GetCallbackData(JSContext* cx);
JSContext* GetContext() const;
JSRuntime* GetRuntime() const;
void ReplaceNondeterministicFunctions(boost::rand48& rng);
+121
View File
@@ -0,0 +1,121 @@
/* Copyright (C) 2010 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#include "precompiled.h"
#include "ScriptStats.h"
#include "scriptinterface/ScriptInterface.h"
#include "js/jsapi.h"
CScriptStatsTable* g_ScriptStatsTable;
enum
{
Row_MaxBytes,
Row_MaxMallocBytes,
Row_Bytes,
Row_NumberGC,
NumberRows
};
CScriptStatsTable::CScriptStatsTable()
{
}
void CScriptStatsTable::Add(const ScriptInterface* scriptInterface, const std::string& title)
{
m_ScriptInterfaces.push_back(std::make_pair(scriptInterface, title));
}
void CScriptStatsTable::Remove(const ScriptInterface* scriptInterface)
{
for (size_t i = 0; i < m_ScriptInterfaces.size(); )
{
if (m_ScriptInterfaces[i].first == scriptInterface)
m_ScriptInterfaces.erase(m_ScriptInterfaces.begin() + i);
else
++i;
}
}
CStr CScriptStatsTable::GetName()
{
return "script";
}
CStr CScriptStatsTable::GetTitle()
{
return "Script statistics";
}
size_t CScriptStatsTable::GetNumberRows()
{
return NumberRows;
}
const std::vector<ProfileColumn>& CScriptStatsTable::GetColumns()
{
m_ColumnDescriptions.clear();
m_ColumnDescriptions.push_back(ProfileColumn("Name", 200));
for (size_t i = 0; i < m_ScriptInterfaces.size(); ++i)
m_ColumnDescriptions.push_back(ProfileColumn(m_ScriptInterfaces[i].second, 80));
return m_ColumnDescriptions;
}
CStr CScriptStatsTable::GetCellText(size_t row, size_t col)
{
switch(row)
{
case Row_MaxBytes:
{
if (col == 0)
return "max nominal heap bytes";
uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetRuntime(), JSGC_MAX_BYTES);
return CStr(n);
}
case Row_MaxMallocBytes:
{
if (col == 0)
return "max JS_malloc bytes";
uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetRuntime(), JSGC_MAX_MALLOC_BYTES);
return CStr(n);
}
case Row_Bytes:
{
if (col == 0)
return "allocated bytes";
uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetRuntime(), JSGC_BYTES);
return CStr(n);
}
case Row_NumberGC:
{
if (col == 0)
return "number of GCs";
uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetRuntime(), JSGC_NUMBER);
return CStr(n);
}
default:
return "???";
}
}
AbstractProfileTable* CScriptStatsTable::GetChild(size_t UNUSED(row))
{
return 0;
}
+50
View File
@@ -0,0 +1,50 @@
/* Copyright (C) 2010 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* 0 A.D. is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_SCRIPTSTATS
#define INCLUDED_SCRIPTSTATS
#include "ps/ProfileViewer.h"
class ScriptInterface;
class CScriptStatsTable : public AbstractProfileTable
{
NONCOPYABLE(CScriptStatsTable);
public:
CScriptStatsTable();
void Add(const ScriptInterface* scriptInterface, const std::string& title);
void Remove(const ScriptInterface* scriptInterface);
virtual CStr GetName();
virtual CStr GetTitle();
virtual size_t GetNumberRows();
virtual const std::vector<ProfileColumn>& GetColumns();
virtual CStr GetCellText(size_t row, size_t col);
virtual AbstractProfileTable* GetChild(size_t row);
private:
std::vector<std::pair<const ScriptInterface*, std::string> > m_ScriptInterfaces;
std::vector<ProfileColumn> m_ColumnDescriptions;
};
// To simplify the UI we want to use a single table for all script interfaces,
// so just make it a global that they can all add themselves to
extern CScriptStatsTable* g_ScriptStatsTable;
#endif // INCLUDED_SCRIPTSTATS