ManaPlus
statdebugtab.cpp
Go to the documentation of this file.
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 
23 
24 #include "const/utils/timer.h"
25 
26 #include "gui/widgets/button.h"
28 #include "gui/widgets/label.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 StatDebugTab::StatDebugTab(const Widget2 *const widget) :
41  DebugTab(widget),
42  // TRANSLATORS: debug window label, logic per second
43  mLPSLabel(new Label(this, strprintf(_("LPS: %d"), 0))),
44  // TRANSLATORS: debug window stats reset button
45  mResetButton(new Button(this, _("Reset"), "reset", BUTTON_SKIN, this)),
46  // TRANSLATORS: debug window stats copy button
47  mCopyButton(new Button(this, _("Copy"), "copy", BUTTON_SKIN, this)),
48  mStatLabels(),
49  mWorseStatLabels(),
50  mDrawIndex(0)
51 {
52  LayoutHelper h(this);
53  ContainerPlacer place = h.getPlacer(0, 0);
54 
57 
58  place(0, 0, mLPSLabel, 2, 1);
59  place(0, 1, mResetButton, 1, 1);
60  place(1, 1, mCopyButton, 1, 1);
61  for (size_t f = 1; f < PERFSTAT_LAST_STAT; f ++)
62  {
63  mStatLabels[f - 1] = new Label(this,
64  // TRANSLATORS: debug window stat label
65  strprintf(_("stat%u: %d ms"), CAST_U32(f), 1000));
66  mStatLabels[f - 1]->adjustSize();
67  mWorseStatLabels[f - 1] = new Label(this,
68  // TRANSLATORS: debug window stat label
69  strprintf(_("%d ms"), 1000));
70  place(0, CAST_S32(f + 1), mStatLabels[f - 1], 3, 1);
71  place(3, CAST_S32(f + 1), mWorseStatLabels[f - 1], 1, 1);
72  }
73 
74  setDimension(Rect(0, 0, 200, 300));
75 }
76 
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),
91  // TRANSLATORS: debug window stat label
92  strprintf(_("%d ms"),
94  }
96  BLOCK_END("StatDebugTab::logic")
97 }
98 
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",
113  }
114  data.append(",");
115  for (size_t f = 1; f < PERFSTAT_LAST_STAT; f ++)
116  {
117  data.append(strprintf(" %d",
119  }
121  true);
122  }
123 }
const std::string BUTTON_SKIN
Definition: button.h:89
#define CAST_S32
Definition: cast.h:30
#define CAST_U32
Definition: cast.h:31
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
Definition: button.h:102
void adjustSize()
Definition: button.cpp:799
void addInputText(const std::string &text, const bool space)
Definition: label.h:91
void adjustSize()
Definition: label.cpp:200
void setCaption(const std::string &caption)
Definition: label.cpp:264
ContainerPlacer getPlacer(const int x, const int y)
Definition: rect.h:74
Label * mWorseStatLabels[PERFSTAT_LAST_STAT - 1]
Definition: statdebugtab.h:53
Label * mLPSLabel
Definition: statdebugtab.h:49
void action(const ActionEvent &event)
size_t mDrawIndex
Definition: statdebugtab.h:54
Button * mResetButton
Definition: statdebugtab.h:50
Label * mStatLabels[PERFSTAT_LAST_STAT - 1]
Definition: statdebugtab.h:52
Button * mCopyButton
Definition: statdebugtab.h:51
StatDebugTab(const Widget2 *const widget)
void setDimension(const Rect &dimension)
Definition: widget.cpp:169
static const size_t PERFSTAT_LAST_STAT
Definition: perfstat.h:28
static const int MILLISECONDS_IN_A_TICK
Definition: timer.h:30
#define new
Definition: debug_new.h:147
#define _(s)
Definition: gettext.h:35
uint32_t data
int getWorstTime(const size_t counterId)
Definition: perfstat.cpp:122
int getTime(const size_t frameId, const size_t counterId)
Definition: perfstat.cpp:111
void init()
Definition: perfstat.cpp:41
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79
size_t prevPerfFrameId
Definition: perfstat.cpp:33
std::string strprintf(const char *const format,...)
volatile int lps
Definition: timer.cpp:55