Audacity 3.2.0
FrameStatisticsDialog.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 FrameStatisticsDialog.cpp
7
8 Dmitry Vedenko
9
10**********************************************************************/
12
13#include "MemoryX.h"
14#include "FrameStatistics.h"
15
16#include "ShuttleGui.h"
17#include "wxPanelWrapper.h"
18
19#include <string>
20
21#include <wx/stattext.h>
22
23namespace
24{
25class Dialog : public wxDialogWrapper
26{
27public:
28
30 : wxDialogWrapper(nullptr, wxID_ANY, Verbatim("Frame Statistics"))
31 {
33
34 S.Style(wxNO_BORDER | wxTAB_TRAVERSAL).Prop(true).StartPanel();
35 {
36 S.StartVerticalLay(true);
37 {
38 S.AddFixedText(Verbatim("Track Panel Rendering"));
40 S.AddFixedText(Verbatim("Waveform Rendering (per clip)"));
42 S.AddFixedText(Verbatim("WaveDataCache Lookups"));
44 S.AddFixedText(Verbatim("WaveBitmapCache Preprocess"));
46 S.AddFixedText(Verbatim("WaveBitmapCache Lookups"));
48 }
49 S.EndVerticalLay();
50 }
51 S.EndPanel();
52
53 Layout();
54 Fit();
55
56 mStatisticsUpdated = FrameStatistics::Subscribe(
57 [this](FrameStatistics::SectionID sectionID) {
58 mSections[size_t(sectionID)].Dirty = true;
59 });
60
61 Bind(
62 wxEVT_IDLE,
63 [this](wxIdleEvent& evt)
64 {
65 for (size_t i = 0; i < size_t(FrameStatistics::SectionID::Count);
66 ++i)
67 {
68 if (mSections[i].Dirty)
69 SectionUpdated(FrameStatistics::SectionID(i));
70 }
71 });
72 }
73
74private:
76 {
77 S.StartMultiColumn(2, wxEXPAND);
78 {
79 S.AddFixedText(Verbatim("Last:"));
80 mSections[size_t(sectionID)].Last = S.AddVariableText({});
81
82 S.AddFixedText(Verbatim("Min:"));
83 mSections[size_t(sectionID)].Min = S.AddVariableText({});
84
85 S.AddFixedText(Verbatim("Max:"));
86 mSections[size_t(sectionID)].Max = S.AddVariableText({});
87
88 S.AddFixedText(Verbatim("Avg:"));
89 mSections[size_t(sectionID)].Avg = S.AddVariableText({});
90
91 S.AddFixedText(Verbatim("Events:"));
92 mSections[size_t(sectionID)].Events = S.AddVariableText({});
93 }
94 S.EndMultiColumn();
95
96 SectionUpdated(sectionID);
97 }
98
100 {
101 using namespace std::chrono;
102
103 const auto mcs = duration_cast<microseconds>(duration);
104
105 return std::to_string(mcs.count() / 1000.0) + " ms";
106 }
107
109 {
110 Section& section = mSections[size_t(sectionID)];
111 const auto& profilerSection = FrameStatistics::GetSection(sectionID);
112
113 if (profilerSection.GetEventsCount() > 0)
114 {
115 section.Last->SetLabel(FormatTime(profilerSection.GetLastDuration()));
116 section.Min->SetLabel(FormatTime(profilerSection.GetMinDuration()));
117 section.Max->SetLabel(FormatTime(profilerSection.GetMaxDuration()));
118 section.Avg->SetLabel(FormatTime(profilerSection.GetAverageDuration()));
119 }
120 else
121 {
122 section.Last->SetLabel(L"n/a");
123 section.Min->SetLabel(L"n/a");
124 section.Max->SetLabel(L"n/a");
125 section.Avg->SetLabel(L"n/a");
126 }
127
128 section.Events->SetLabel(std::to_string(profilerSection.GetEventsCount()));
129
130 section.Dirty = false;
131 }
132
133 struct Section final
134 {
135 wxStaticText* Last;
136 wxStaticText* Min;
137 wxStaticText* Max;
138 wxStaticText* Avg;
139 wxStaticText* Events;
140
141 bool Dirty { true };
142 };
143
145
147};
148
150}
151
153{
154 if (!show)
155 {
156 if (sDialog != nullptr)
157 sDialog->Show(false);
158
159 return;
160 }
161
162 if (sDialog == nullptr)
163 sDialog.reset(safenew Dialog);
164
165 sDialog->Show(true);
166}
167
169{
170 sDialog.reset();
171}
#define safenew
Definition: MemoryX.h:10
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Definition: MemoryX.h:164
@ eIsCreating
Definition: ShuttleGui.h:37
#define S(N)
Definition: ToChars.cpp:64
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
static void Show(bool show)
Shows the dialog.
static void Destroy()
Destroys the dialog to prevent Audacity from hanging on exit.
SectionID
ID of the profiling section.
@ WaveformView
Time required to draw a single clip.
@ WaveBitmapCachePreprocess
Time required to build the structures required for the bitmap cache population.
@ TrackPanel
Full repaint time of the TrackPanel.
@ Count
Number of the sections.
@ WaveDataCache
Time required to access the data cache.
@ WaveBitmapCache
Time required to access the wave bitmaps cache.
static const Section & GetSection(SectionID section) noexcept
Get the section data.
Clock::duration Duration
static Observer::Subscription Subscribe(UpdatePublisher::Callback callback)
Subscribe to sections update.
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640
void AddSection(ShuttleGui &S, FrameStatistics::SectionID sectionID)
void SectionUpdated(FrameStatistics::SectionID sectionID)
wxString FormatTime(FrameStatistics::Duration duration)