GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/statdebugtab.cpp Lines: 23 48 47.9 %
Date: 2019-08-19 Branches: 36 94 38.3 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2019  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "gui/widgets/tabs/statdebugtab.h"
22
23
#include "const/utils/timer.h"
24
25
#include "gui/widgets/button.h"
26
#include "gui/widgets/containerplacer.h"
27
#include "gui/widgets/label.h"
28
#include "gui/widgets/layouthelper.h"
29
30
#include "gui/windows/chatwindow.h"
31
32
#include "utils/gettext.h"
33
#include "utils/perfstat.h"
34
#include "utils/stringutils.h"
35
#include "utils/timer.h"
36
37
#include "debug.h"
38
39
2
StatDebugTab::StatDebugTab(const Widget2 *const widget) :
40
    DebugTab(widget),
41
    // TRANSLATORS: debug window label, logic per second
42

4
    mLPSLabel(new Label(this, strprintf(_("LPS: %d"), 0))),
43
    // TRANSLATORS: debug window stats reset button
44

4
    mResetButton(new Button(this, _("Reset"), "reset", BUTTON_SKIN, this)),
45
    // TRANSLATORS: debug window stats copy button
46

4
    mCopyButton(new Button(this, _("Copy"), "copy", BUTTON_SKIN, this)),
47
    mStatLabels(),
48
    mWorseStatLabels(),
49



38
    mDrawIndex(0)
50
{
51
4
    LayoutHelper h(this);
52
2
    ContainerPlacer place = h.getPlacer(0, 0);
53
54
2
    mResetButton->adjustSize();
55
2
    mCopyButton->adjustSize();
56
57
2
    place(0, 0, mLPSLabel, 2, 1);
58
2
    place(0, 1, mResetButton, 1, 1);
59
2
    place(1, 1, mCopyButton, 1, 1);
60
50
    for (size_t f = 1; f < PERFSTAT_LAST_STAT; f ++)
61
    {
62
24
        mStatLabels[f - 1] = new Label(this,
63
            // TRANSLATORS: debug window stat label
64

48
            strprintf(_("stat%u: %d ms"), CAST_U32(f), 1000));
65
24
        mStatLabels[f - 1]->adjustSize();
66
24
        mWorseStatLabels[f - 1] = new Label(this,
67
            // TRANSLATORS: debug window stat label
68

48
            strprintf(_("%d ms"), 1000));
69
24
        place(0, CAST_S32(f + 1), mStatLabels[f - 1], 3, 1);
70
24
        place(3, CAST_S32(f + 1), mWorseStatLabels[f - 1], 1, 1);
71
    }
72
73
2
    setDimension(Rect(0, 0, 200, 300));
74
2
}
75
76
void StatDebugTab::logic()
77
{
78
    BLOCK_START("StatDebugTab::logic")
79
    // TRANSLATORS: debug window label, logic per second
80
    mLPSLabel->setCaption(strprintf(_("LPS: %d"), lps));
81
82
    for (size_t f = 1; f < PERFSTAT_LAST_STAT; f ++)
83
    {
84
        mStatLabels[f - 1]->setCaption(
85
            // TRANSLATORS: debug window stat label
86
            strprintf(_("stat%u: %d ms"),
87
            CAST_U32(f),
88
            Perf::getTime(prevPerfFrameId, f) * MILLISECONDS_IN_A_TICK));
89
        mWorseStatLabels[f - 1]->setCaption(
90
            // TRANSLATORS: debug window stat label
91
            strprintf(_("%d ms"),
92
            Perf::getWorstTime(f) * MILLISECONDS_IN_A_TICK));
93
    }
94
    mDrawIndex = prevPerfFrameId;
95
    BLOCK_END("StatDebugTab::logic")
96
}
97
98
void StatDebugTab::action(const ActionEvent &event)
99
{
100
    const std::string &eventId = event.getId();
101
    if (eventId == "reset")
102
    {
103
        Perf::init();
104
    }
105
    else if (eventId == "copy")
106
    {
107
        std::string data("perf:");
108
        for (size_t f = 1; f < PERFSTAT_LAST_STAT; f ++)
109
        {
110
            data.append(strprintf(" %d",
111
                Perf::getTime(mDrawIndex, f) * MILLISECONDS_IN_A_TICK));
112
        }
113
        data.append(",");
114
        for (size_t f = 1; f < PERFSTAT_LAST_STAT; f ++)
115
        {
116
            data.append(strprintf(" %d",
117
                Perf::getWorstTime(f) * MILLISECONDS_IN_A_TICK));
118
        }
119
        chatWindow->addInputText(data,
120
            true);
121
    }
122

3
}