Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ScriptStats.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2010 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 #include "precompiled.h"
19 
20 #include "ScriptStats.h"
21 
23 
24 #include "js/jsapi.h"
25 
27 
28 enum
29 {
35 };
36 
38 {
39 }
40 
41 void CScriptStatsTable::Add(const ScriptInterface* scriptInterface, const std::string& title)
42 {
43  m_ScriptInterfaces.push_back(std::make_pair(scriptInterface, title));
44 }
45 
46 void CScriptStatsTable::Remove(const ScriptInterface* scriptInterface)
47 {
48  for (size_t i = 0; i < m_ScriptInterfaces.size(); )
49  {
50  if (m_ScriptInterfaces[i].first == scriptInterface)
51  m_ScriptInterfaces.erase(m_ScriptInterfaces.begin() + i);
52  else
53  ++i;
54  }
55 }
56 
58 {
59  return "script";
60 }
61 
63 {
64  return "Script statistics";
65 }
66 
68 {
69  return NumberRows;
70 }
71 
72 const std::vector<ProfileColumn>& CScriptStatsTable::GetColumns()
73 {
74  m_ColumnDescriptions.clear();
75  m_ColumnDescriptions.push_back(ProfileColumn("Name", 200));
76  for (size_t i = 0; i < m_ScriptInterfaces.size(); ++i)
77  m_ColumnDescriptions.push_back(ProfileColumn(m_ScriptInterfaces[i].second, 80));
78  return m_ColumnDescriptions;
79 }
80 
81 CStr CScriptStatsTable::GetCellText(size_t row, size_t col)
82 {
83  switch(row)
84  {
85  case Row_MaxBytes:
86  {
87  if (col == 0)
88  return "max nominal heap bytes";
89  uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetRuntime(), JSGC_MAX_BYTES);
90  return CStr::FromUInt(n);
91  }
92  case Row_MaxMallocBytes:
93  {
94  if (col == 0)
95  return "max JS_malloc bytes";
96  uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetRuntime(), JSGC_MAX_MALLOC_BYTES);
97  return CStr::FromUInt(n);
98  }
99  case Row_Bytes:
100  {
101  if (col == 0)
102  return "allocated bytes";
103  uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetRuntime(), JSGC_BYTES);
104  return CStr::FromUInt(n);
105  }
106  case Row_NumberGC:
107  {
108  if (col == 0)
109  return "number of GCs";
110  uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetRuntime(), JSGC_NUMBER);
111  return CStr::FromUInt(n);
112  }
113  default:
114  return "???";
115  }
116 }
117 
119 {
120  return 0;
121 }
virtual CStr GetTitle()
GetTitle: Longer, explanatory text (can be dynamic).
Definition: ScriptStats.cpp:62
std::vector< std::pair< const ScriptInterface *, std::string > > m_ScriptInterfaces
Definition: ScriptStats.h:42
CScriptStatsTable * g_ScriptStatsTable
Definition: ScriptStats.cpp:26
void Add(const ScriptInterface *scriptInterface, const std::string &title)
Definition: ScriptStats.cpp:41
virtual const std::vector< ProfileColumn > & GetColumns()
GetColumnDescriptions.
Definition: ScriptStats.cpp:72
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
std::vector< ProfileColumn > m_ColumnDescriptions
Definition: ScriptStats.h:43
Class AbstractProfileTable: Profile table data model.
Definition: ProfileViewer.h:60
virtual size_t GetNumberRows()
GetNumberRows.
Definition: ScriptStats.cpp:67
virtual CStr GetName()
GetName: Short descriptive name of this table (should be static).
Definition: ScriptStats.cpp:57
virtual AbstractProfileTable * GetChild(size_t row)
GetChild: Return a row&#39;s child table if the child is expandable.
void Remove(const ScriptInterface *scriptInterface)
Definition: ScriptStats.cpp:46
virtual CStr GetCellText(size_t row, size_t col)
GetCellText.
Definition: ScriptStats.cpp:81
unsigned int uint32_t
Definition: wposix_types.h:53
Struct ProfileColumn: Describes one column of an AbstractProfileTable.
Definition: ProfileViewer.h:35
Abstraction around a SpiderMonkey JSContext.