LCOV - code coverage report
Current view: top level - source/scriptinterface - ScriptStats.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 44 0.0 %
Date: 2023-01-19 00:18:29 Functions: 0 9 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2020 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             : 
      22             : #include "scriptinterface/ScriptInterface.h"
      23             : 
      24             : CScriptStatsTable* g_ScriptStatsTable;
      25             : 
      26             : enum
      27             : {
      28             :     Row_MaxBytes,
      29             :     Row_Bytes,
      30             :     Row_NumberGC,
      31             :     NumberRows
      32             : };
      33             : 
      34           0 : CScriptStatsTable::CScriptStatsTable()
      35             : {
      36           0 : }
      37             : 
      38           0 : void CScriptStatsTable::Add(const ScriptInterface* scriptInterface, const std::string& title)
      39             : {
      40           0 :     m_ScriptInterfaces.emplace_back(scriptInterface, title);
      41           0 : }
      42             : 
      43           0 : void CScriptStatsTable::Remove(const ScriptInterface* scriptInterface)
      44             : {
      45           0 :     for (size_t i = 0; i < m_ScriptInterfaces.size(); )
      46             :     {
      47           0 :         if (m_ScriptInterfaces[i].first == scriptInterface)
      48           0 :             m_ScriptInterfaces.erase(m_ScriptInterfaces.begin() + i);
      49             :         else
      50           0 :             ++i;
      51             :     }
      52           0 : }
      53             : 
      54           0 : CStr CScriptStatsTable::GetName()
      55             : {
      56           0 :     return "script";
      57             : }
      58             : 
      59           0 : CStr CScriptStatsTable::GetTitle()
      60             : {
      61           0 :     return "Script statistics";
      62             : }
      63             : 
      64           0 : size_t CScriptStatsTable::GetNumberRows()
      65             : {
      66           0 :     return NumberRows;
      67             : }
      68             : 
      69           0 : const std::vector<ProfileColumn>& CScriptStatsTable::GetColumns()
      70             : {
      71           0 :     m_ColumnDescriptions.clear();
      72           0 :     m_ColumnDescriptions.push_back(ProfileColumn("Name", 200));
      73           0 :     for (size_t i = 0; i < m_ScriptInterfaces.size(); ++i)
      74           0 :         m_ColumnDescriptions.push_back(ProfileColumn(m_ScriptInterfaces[i].second, 80));
      75           0 :     return m_ColumnDescriptions;
      76             : }
      77             : 
      78           0 : CStr CScriptStatsTable::GetCellText(size_t row, size_t col)
      79             : {
      80           0 :     switch(row)
      81             :     {
      82           0 :     case Row_MaxBytes:
      83             :     {
      84           0 :         if (col == 0)
      85           0 :             return "max nominal heap bytes";
      86           0 :         uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetGeneralJSContext(), JSGC_MAX_BYTES);
      87           0 :         return CStr::FromUInt(n);
      88             :     }
      89           0 :     case Row_Bytes:
      90             :     {
      91           0 :         if (col == 0)
      92           0 :             return "allocated bytes";
      93           0 :         uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetGeneralJSContext(), JSGC_BYTES);
      94           0 :         return CStr::FromUInt(n);
      95             :     }
      96           0 :     case Row_NumberGC:
      97             :     {
      98           0 :         if (col == 0)
      99           0 :             return "number of GCs";
     100           0 :         uint32_t n = JS_GetGCParameter(m_ScriptInterfaces.at(col-1).first->GetGeneralJSContext(), JSGC_NUMBER);
     101           0 :         return CStr::FromUInt(n);
     102             :     }
     103           0 :     default:
     104           0 :         return "???";
     105             :     }
     106             : }
     107             : 
     108           0 : AbstractProfileTable* CScriptStatsTable::GetChild(size_t UNUSED(row))
     109             : {
     110           0 :     return 0;
     111             : }

Generated by: LCOV version 1.13