GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/* |
||
2 |
* The ManaPlus Client |
||
3 |
* Copyright (C) 2011-2019 The ManaPlus Developers |
||
4 |
* Copyright (C) 2019-2021 Andrei Karas |
||
5 |
* |
||
6 |
* This file is part of The ManaPlus Client. |
||
7 |
* |
||
8 |
* This program is free software; you can redistribute it and/or modify |
||
9 |
* it under the terms of the GNU General Public License as published by |
||
10 |
* the Free Software Foundation; either version 2 of the License, or |
||
11 |
* any later version. |
||
12 |
* |
||
13 |
* This program is distributed in the hope that it will be useful, |
||
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 |
* GNU General Public License for more details. |
||
17 |
* |
||
18 |
* You should have received a copy of the GNU General Public License |
||
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
20 |
*/ |
||
21 |
|||
22 |
#include "gui/widgets/tabs/statdebugtab.h" |
||
23 |
|||
24 |
#include "const/utils/timer.h" |
||
25 |
|||
26 |
#include "gui/widgets/button.h" |
||
27 |
#include "gui/widgets/containerplacer.h" |
||
28 |
#include "gui/widgets/label.h" |
||
29 |
#include "gui/widgets/layouthelper.h" |
||
30 |
|||
31 |
#include "gui/windows/chatwindow.h" |
||
32 |
|||
33 |
#include "utils/gettext.h" |
||
34 |
#include "utils/perfstat.h" |
||
35 |
#include "utils/stringutils.h" |
||
36 |
#include "utils/timer.h" |
||
37 |
|||
38 |
#include "debug.h" |
||
39 |
|||
40 |
2 |
StatDebugTab::StatDebugTab(const Widget2 *const widget) : |
|
41 |
DebugTab(widget), |
||
42 |
// TRANSLATORS: debug window label, logic per second |
||
43 |
✓✗✓✗ ✓✗ |
4 |
mLPSLabel(new Label(this, strprintf(_("LPS: %d"), 0))), |
44 |
// TRANSLATORS: debug window stats reset button |
||
45 |
✓✗✓✗ |
4 |
mResetButton(new Button(this, _("Reset"), "reset", BUTTON_SKIN, this)), |
46 |
// TRANSLATORS: debug window stats copy button |
||
47 |
✓✗✓✗ |
4 |
mCopyButton(new Button(this, _("Copy"), "copy", BUTTON_SKIN, this)), |
48 |
mStatLabels(), |
||
49 |
mWorseStatLabels(), |
||
50 |
✓✗✓✗ ✓✗✓✗ ✓✓✓✓ |
38 |
mDrawIndex(0) |
51 |
{ |
||
52 |
✓✗ | 4 |
LayoutHelper h(this); |
53 |
✓✗ | 2 |
ContainerPlacer place = h.getPlacer(0, 0); |
54 |
|||
55 |
✓✗ | 2 |
mResetButton->adjustSize(); |
56 |
✓✗ | 2 |
mCopyButton->adjustSize(); |
57 |
|||
58 |
✓✗ | 2 |
place(0, 0, mLPSLabel, 2, 1); |
59 |
✓✗ | 2 |
place(0, 1, mResetButton, 1, 1); |
60 |
✓✗ | 2 |
place(1, 1, mCopyButton, 1, 1); |
61 |
✓✓ | 50 |
for (size_t f = 1; f < PERFSTAT_LAST_STAT; f ++) |
62 |
{ |
||
63 |
24 |
mStatLabels[f - 1] = new Label(this, |
|
64 |
// TRANSLATORS: debug window stat label |
||
65 |
✓✗✓✗ ✓✗ |
48 |
strprintf(_("stat%u: %d ms"), CAST_U32(f), 1000)); |
66 |
✓✗ | 24 |
mStatLabels[f - 1]->adjustSize(); |
67 |
24 |
mWorseStatLabels[f - 1] = new Label(this, |
|
68 |
// TRANSLATORS: debug window stat label |
||
69 |
✓✗✓✗ ✓✗ |
48 |
strprintf(_("%d ms"), 1000)); |
70 |
✓✗ | 24 |
place(0, CAST_S32(f + 1), mStatLabels[f - 1], 3, 1); |
71 |
✓✗ | 24 |
place(3, CAST_S32(f + 1), mWorseStatLabels[f - 1], 1, 1); |
72 |
} |
||
73 |
|||
74 |
✓✗ | 2 |
setDimension(Rect(0, 0, 200, 300)); |
75 |
2 |
} |
|
76 |
|||
77 |
void StatDebugTab::logic() |
||
78 |
{ |
||
79 |
BLOCK_START("StatDebugTab::logic") |
||
80 |
// TRANSLATORS: debug window label, logic per second |
||
81 |
mLPSLabel->setCaption(strprintf(_("LPS: %d"), lps)); |
||
82 |
|||
83 |
for (size_t f = 1; f < PERFSTAT_LAST_STAT; f ++) |
||
84 |
{ |
||
85 |
mStatLabels[f - 1]->setCaption( |
||
86 |
// TRANSLATORS: debug window stat label |
||
87 |
strprintf(_("stat%u: %d ms"), |
||
88 |
CAST_U32(f), |
||
89 |
Perf::getTime(prevPerfFrameId, f) * MILLISECONDS_IN_A_TICK)); |
||
90 |
mWorseStatLabels[f - 1]->setCaption( |
||
91 |
// TRANSLATORS: debug window stat label |
||
92 |
strprintf(_("%d ms"), |
||
93 |
Perf::getWorstTime(f) * MILLISECONDS_IN_A_TICK)); |
||
94 |
} |
||
95 |
mDrawIndex = prevPerfFrameId; |
||
96 |
BLOCK_END("StatDebugTab::logic") |
||
97 |
} |
||
98 |
|||
99 |
void StatDebugTab::action(const ActionEvent &event) |
||
100 |
{ |
||
101 |
const std::string &eventId = event.getId(); |
||
102 |
if (eventId == "reset") |
||
103 |
{ |
||
104 |
Perf::init(); |
||
105 |
} |
||
106 |
else if (eventId == "copy") |
||
107 |
{ |
||
108 |
std::string data("perf:"); |
||
109 |
for (size_t f = 1; f < PERFSTAT_LAST_STAT; f ++) |
||
110 |
{ |
||
111 |
data.append(strprintf(" %d", |
||
112 |
Perf::getTime(mDrawIndex, f) * MILLISECONDS_IN_A_TICK)); |
||
113 |
} |
||
114 |
data.append(","); |
||
115 |
for (size_t f = 1; f < PERFSTAT_LAST_STAT; f ++) |
||
116 |
{ |
||
117 |
data.append(strprintf(" %d", |
||
118 |
Perf::getWorstTime(f) * MILLISECONDS_IN_A_TICK)); |
||
119 |
} |
||
120 |
chatWindow->addInputText(data, |
||
121 |
true); |
||
122 |
} |
||
123 |
✓✗✓✗ |
3 |
} |
Generated by: GCOVR (Version 3.3) |