OpenClonk
C4MainStat Class Reference

#include <C4Stat.h>

Collaboration diagram for C4MainStat:
[legend]

Public Member Functions

 C4MainStat ()
 
 ~C4MainStat ()
 
void Show ()
 
void ShowPart (int FrameCounter)
 
void Reset ()
 
void ResetPart ()
 

Protected Member Functions

void RegisterStat (C4Stat *pStat)
 
void UnRegStat (C4Stat *pStat)
 

Protected Attributes

C4StatpFirst {nullptr}
 

Friends

class C4Stat
 

Detailed Description

Definition at line 24 of file C4Stat.h.

Constructor & Destructor Documentation

◆ C4MainStat()

C4MainStat::C4MainStat ( )
default

◆ ~C4MainStat()

C4MainStat::~C4MainStat ( )
default

Member Function Documentation

◆ RegisterStat()

void C4MainStat::RegisterStat ( C4Stat pStat)
protected

Definition at line 27 of file C4Stat.cpp.

28 {
29  // add to list
30  if (!pFirst)
31  {
32  pFirst = pStat;
33  pStat->pNext = nullptr;
34  pStat->pPrev = nullptr;
35  }
36  else
37  {
38  pStat->pNext = pFirst;
39  pFirst->pPrev = pStat;
40  pStat->pPrev = nullptr;
41  pFirst = pStat;
42  }
43 }
C4Stat * pFirst
Definition: C4Stat.h:39
C4Stat * pPrev
Definition: C4Stat.h:88
C4Stat * pNext
Definition: C4Stat.h:87

References pFirst, C4Stat::pNext, and C4Stat::pPrev.

Referenced by C4Stat::C4Stat().

Here is the caller graph for this function:

◆ Reset()

void C4MainStat::Reset ( )

Definition at line 68 of file C4Stat.cpp.

69 {
70  for (C4Stat* pAkt = pFirst; pAkt; pAkt = pAkt->pNext)
71  pAkt->Reset();
72 }
Definition: C4Stat.h:50

References pFirst, and C4Stat::pNext.

◆ ResetPart()

void C4MainStat::ResetPart ( )

Definition at line 74 of file C4Stat.cpp.

75 {
76  for (C4Stat* pAkt = pFirst; pAkt; pAkt = pAkt->pNext)
77  pAkt->ResetPart();
78 }

References pFirst, and C4Stat::pNext.

◆ Show()

void C4MainStat::Show ( )

Definition at line 81 of file C4Stat.cpp.

82 {
83 
84  // count stats
85  unsigned int iCnt = 0;
86  C4Stat* pAkt;
87  for (pAkt = pFirst; pAkt; pAkt = pAkt->pNext)
88  iCnt++;
89 
90  // create array
91  auto** StatArray = new C4Stat*[iCnt];
92  auto* bHS = new bool[iCnt];
93 
94  // sort it
95  unsigned int i,ii;
96  for (ii=0; ii<iCnt; ii++) bHS[ii] = false;
97  for (i=0; i<iCnt; i++)
98  {
99  C4Stat* pBestStat = nullptr;
100  unsigned int iBestNr = ~0;
101 
102  for (ii=0, pAkt = pFirst; ii<iCnt; ii++, pAkt = pAkt->pNext)
103  if (!bHS[ii])
104  {
105  if (iBestNr == ~0u)
106  {
107  iBestNr = ii;
108  pBestStat = pAkt;
109  }
110  else if (stricmp(pBestStat->strName, pAkt->strName) > 0)
111  {
112  iBestNr = ii;
113  pBestStat = pAkt;
114  }
115  }
116 
117  if (iBestNr == (unsigned int) -1)
118  break;
119  bHS[iBestNr] = true;
120 
121  StatArray[i] = pBestStat;
122  }
123 
124  delete [] bHS;
125 
126  LogSilent("** Stat");
127 
128  // output in order
129  for (i=0; i<iCnt; i++)
130  {
131  pAkt = StatArray[i];
132 
133  // output it!
134  if (pAkt->iCount)
135  LogSilentF("%s: n = %u, t = %u, td = %.2f",
136  pAkt->strName, pAkt->iCount, pAkt->tTimeSum,
137  double(pAkt->tTimeSum) / pAkt->iCount * 1000);
138  }
139 
140  // delete...
141  delete[] StatArray;
142 
143  // ok. job done
144  LogSilent("** Stat end");
145 }
bool LogSilent(const char *szMessage, bool fConsole)
Definition: C4Log.cpp:126
bool LogSilentF(const char *strMessage,...)
Definition: C4Log.cpp:272
int stricmp(const char *s1, const char *s2)
int iCnt
Definition: TstC4NetIO.cpp:32
const char * strName
Definition: C4Stat.h:114

References iCnt, C4Stat::iCount, LogSilent(), LogSilentF(), pFirst, C4Stat::pNext, stricmp(), C4Stat::strName, and C4Stat::tTimeSum.

Here is the call graph for this function:

◆ ShowPart()

void C4MainStat::ShowPart ( int  FrameCounter)

Definition at line 147 of file C4Stat.cpp.

148 {
149  C4Stat* pAkt;
150 
151  // insert tick nr
152  LogSilentF("** PartStat begin %d", FrameCounter);
153 
154  // insert all stats
155  for (pAkt = pFirst; pAkt; pAkt = pAkt->pNext)
156  LogSilentF("%s: n=%u, t=%u", pAkt->strName, pAkt->iCountPart, pAkt->tTimeSumPart);
157 
158  // insert part stat end idtf
159  LogSilentF("** PartStat end\n");
160 }
unsigned int iCountPart
Definition: C4Stat.h:110
uint32_t tTimeSumPart
Definition: C4Stat.h:107

References C4Stat::iCountPart, LogSilentF(), pFirst, C4Stat::pNext, C4Stat::strName, and C4Stat::tTimeSumPart.

Here is the call graph for this function:

◆ UnRegStat()

void C4MainStat::UnRegStat ( C4Stat pStat)
protected

Definition at line 45 of file C4Stat.cpp.

46 {
47  // first item?
48  if (!pStat->pPrev)
49  {
50  pFirst = pStat->pNext;
51  pStat->pNext = nullptr;
52  }
53  // last item?
54  else if (!pStat->pNext)
55  {
56  pStat->pPrev->pNext = nullptr;
57  pStat->pPrev = nullptr;
58  }
59  else
60  {
61  pStat->pNext->pPrev = pStat->pPrev;
62  pStat->pPrev->pNext = pStat->pNext;
63  pStat->pNext = nullptr;
64  pStat->pPrev = nullptr;
65  }
66 }

References pFirst, C4Stat::pNext, and C4Stat::pPrev.

Referenced by C4Stat::~C4Stat().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ C4Stat

friend class C4Stat
friend

Definition at line 26 of file C4Stat.h.

Member Data Documentation

◆ pFirst

C4Stat* C4MainStat::pFirst {nullptr}
protected

Definition at line 39 of file C4Stat.h.

Referenced by RegisterStat(), Reset(), ResetPart(), Show(), ShowPart(), and UnRegStat().


The documentation for this class was generated from the following files: