OpenClonk
C4Stat.cpp
Go to the documentation of this file.
1
/*
2
* OpenClonk, http://www.openclonk.org
3
*
4
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
5
* Copyright (c) 2009-2016, The OpenClonk Team and contributors
6
*
7
* Distributed under the terms of the ISC license; see accompanying file
8
* "COPYING" for details.
9
*
10
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
11
* See accompanying file "TRADEMARK" for details.
12
*
13
* To redistribute this file separately, substitute the full license texts
14
* for the above references.
15
*/
16
// statistics
17
18
#include "
C4Include.h
"
19
#include "
lib/C4Stat.h
"
20
21
// ** implemetation of C4MainStat
22
23
C4MainStat::C4MainStat
() =
default
;
24
25
C4MainStat::~C4MainStat
() =
default
;
26
27
void
C4MainStat::RegisterStat
(
C4Stat
* pStat)
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
}
44
45
void
C4MainStat::UnRegStat
(
C4Stat
* pStat)
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
}
67
68
void
C4MainStat::Reset
()
69
{
70
for
(
C4Stat
* pAkt =
pFirst
; pAkt; pAkt = pAkt->
pNext
)
71
pAkt->Reset();
72
}
73
74
void
C4MainStat::ResetPart
()
75
{
76
for
(
C4Stat
* pAkt =
pFirst
; pAkt; pAkt = pAkt->
pNext
)
77
pAkt->ResetPart();
78
}
79
80
81
void
C4MainStat::Show
()
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
}
146
147
void
C4MainStat::ShowPart
(
int
FrameCounter)
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
}
161
162
// ** implemetation of C4Stat
163
164
C4Stat::C4Stat
(
const
char
* strnName)
165
: strName(strnName)
166
{
167
Reset
();
168
getMainStat
()->
RegisterStat
(
this
);
169
}
170
171
C4Stat::~C4Stat
()
172
{
173
getMainStat
()->
UnRegStat
(
this
);
174
}
175
176
void
C4Stat::Reset
()
177
{
178
iStartCalled
= 0;
179
180
tTimeSum
= 0;
181
iCount
= 0;
182
183
ResetPart
();
184
}
185
186
void
C4Stat::ResetPart
()
187
{
188
tTimeSumPart
= 0;
189
iCountPart
= 0;
190
}
191
192
C4MainStat
*
C4Stat::getMainStat
()
193
{
194
static
C4MainStat
*pMainStat =
new
C4MainStat
();
195
return
pMainStat;
196
}
C4Include.h
LogSilent
bool LogSilent(const char *szMessage, bool fConsole)
Definition:
C4Log.cpp:126
LogSilentF
bool LogSilentF(const char *strMessage,...)
Definition:
C4Log.cpp:272
C4Stat.h
stricmp
int stricmp(const char *s1, const char *s2)
Definition:
PlatformAbstraction.h:139
iCnt
int iCnt
Definition:
TstC4NetIO.cpp:32
C4MainStat
Definition:
C4Stat.h:25
C4MainStat::~C4MainStat
~C4MainStat()
C4MainStat::Show
void Show()
Definition:
C4Stat.cpp:81
C4MainStat::ShowPart
void ShowPart(int FrameCounter)
Definition:
C4Stat.cpp:147
C4MainStat::ResetPart
void ResetPart()
Definition:
C4Stat.cpp:74
C4MainStat::pFirst
C4Stat * pFirst
Definition:
C4Stat.h:39
C4MainStat::RegisterStat
void RegisterStat(C4Stat *pStat)
Definition:
C4Stat.cpp:27
C4MainStat::C4MainStat
C4MainStat()
C4MainStat::Reset
void Reset()
Definition:
C4Stat.cpp:68
C4MainStat::UnRegStat
void UnRegStat(C4Stat *pStat)
Definition:
C4Stat.cpp:45
C4Stat
Definition:
C4Stat.h:50
C4Stat::pPrev
C4Stat * pPrev
Definition:
C4Stat.h:88
C4Stat::C4MainStat
friend class C4MainStat
Definition:
C4Stat.h:51
C4Stat::iCountPart
unsigned int iCountPart
Definition:
C4Stat.h:110
C4Stat::iCount
unsigned int iCount
Definition:
C4Stat.h:102
C4Stat::getMainStat
static C4MainStat * getMainStat()
Definition:
C4Stat.cpp:192
C4Stat::Reset
void Reset()
Definition:
C4Stat.cpp:176
C4Stat::strName
const char * strName
Definition:
C4Stat.h:114
C4Stat::ResetPart
void ResetPart()
Definition:
C4Stat.cpp:186
C4Stat::iStartCalled
unsigned int iStartCalled
Definition:
C4Stat.h:93
C4Stat::C4Stat
C4Stat(const char *strName)
Definition:
C4Stat.cpp:164
C4Stat::pNext
C4Stat * pNext
Definition:
C4Stat.h:87
C4Stat::tTimeSumPart
uint32_t tTimeSumPart
Definition:
C4Stat.h:107
C4Stat::~C4Stat
~C4Stat()
Definition:
C4Stat.cpp:171
C4Stat::tTimeSum
uint32_t tTimeSum
Definition:
C4Stat.h:99
openclonk
src
lib
C4Stat.cpp
Generated on Fri May 16 2025 04:33:18 for OpenClonk by
1.9.1