Audacity 3.2.0
FrameStatistics.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 FrameStatistics.cpp
7
8 Dmitry Vedenko
9
10**********************************************************************/
11
12#include "FrameStatistics.h"
13
14#include <algorithm>
15#include <numeric>
16
17namespace
18{
20{
21 static FrameStatistics frameStatistics;
22 return frameStatistics;
23}
24}
25
27{
28 GetInstance().AddEvent(mSection, FrameStatistics::Clock::now() - mStart);
29}
30
32 : mSection(section)
33 , mStart(FrameStatistics::Clock::now())
34{
35}
36
39{
40 return mLastDuration;
41}
42
45{
46 return mMinDuration;
47}
48
51{
52 return mMaxDuration;
53}
54
57{
58 return mAvgDuration;
59}
60
62{
63 return mEventsCount;
64}
65
67{
68 ++mEventsCount;
69
70 mLastDuration = duration;
71
72 mMinDuration = std::min(mMinDuration, duration);
73 mMaxDuration = std::max(mMaxDuration, duration);
74
75 // Kernel is initialized with zeroes
76 mAvgAccum = mAvgAccum - mFilteringKernel[mNextIndex] + duration;
77
78 mFilteringKernel[mNextIndex] = duration;
79
80 mNextIndex = (mNextIndex + 1) % KERNEL_SIZE;
81
82 if (mKernelItems < KERNEL_SIZE)
83 ++mKernelItems;
84
85 mAvgDuration = mAvgAccum / mKernelItems;
86}
87
90{
91 // New frame has started
92 if (section == SectionID::TrackPanel)
93 {
94 auto& instance = GetInstance();
95
96 instance.mSections[size_t(SectionID::WaveformView)] = {};
97 instance.mSections[size_t(SectionID::WaveDataCache)] = {};
98 instance.mSections[size_t(SectionID::WaveBitmapCachePreprocess)] = {};
99 instance.mSections[size_t(SectionID::WaveBitmapCache)] = {};
100 }
101
102 return Stopwatch(section);
103}
104
107{
108 if (section < SectionID::Count)
109 return GetInstance().mSections[size_t(section)];
110
111 static Section fakeSection;
112 return fakeSection;
113}
114
117{
118 return GetInstance().mUpdatePublisher.Subscribe(std::move(callback));
119}
120
122{
123 if (section < SectionID::Count)
124 {
125 GetInstance().mSections[size_t(section)].AddEvent(duration);
127 }
128}
129
131{
132 Publish(id);
133}
int min(int a, int b)
Profiling section data.
Duration GetMaxDuration() const noexcept
All time maximum duration of the events in this section.
size_t GetEventsCount() const noexcept
Total number of the events in this section.
Duration GetAverageDuration() const noexcept
Average duration of the last KERNEL_SIZE events in this section.
Duration GetLastDuration() const noexcept
Duration of the last event.
void AddEvent(Duration duration) noexcept
Duration GetMinDuration() const noexcept
All time minimum duration of the events in this section.
RAII wrapper used to measure a section time.
Stopwatch(SectionID section) noexcept
A class to profile TrackPanel painting.
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.
void AddEvent(SectionID section, Duration duration)
UpdatePublisher mUpdatePublisher
static const Section & GetSection(SectionID section) noexcept
Get the section data.
Section mSections[size_t(SectionID::Count)]
static Stopwatch CreateStopwatch(SectionID section) noexcept
Create a Stopwatch for the section specified.
Clock::duration Duration
static Observer::Subscription Subscribe(UpdatePublisher::Callback callback)
Subscribe to sections update.
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
std::function< CallbackReturn(const SectionID &) > Callback
Type of functions that can be connected to the Publisher.
Definition: Observer.h:130
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
FrameStatistics & GetInstance() noexcept