Audacity 3.2.0
FrameStatistics.h
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.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11
12#pragma once
13
14#include <chrono>
15#include <cstddef>
16#include <functional>
17
18#include "Observer.h"
19
21
25class GRAPHICS_API FrameStatistics final
26{
27public:
28 using Clock = std::chrono::high_resolution_clock;
29 using Duration = Clock::duration;
30 using Timepoint = Clock::time_point;
31
33 enum class SectionID
34 {
42 WaveBitmapCachePreprocess,
46 Count
47 };
48
50 struct GRAPHICS_API UpdatePublisher : Observer::Publisher<SectionID>
51 {
52 void Invoke(SectionID id);
53 };
54
56 class GRAPHICS_API Stopwatch final
57 {
58 public:
59 ~Stopwatch() noexcept;
60 private:
61 explicit Stopwatch(SectionID section) noexcept;
62
65
66 friend class FrameStatistics;
67 };
68
70 class GRAPHICS_API Section final
71 {
72 public:
74 Duration GetLastDuration() const noexcept;
76 Duration GetMinDuration() const noexcept;
78 Duration GetMaxDuration() const noexcept;
80 Duration GetAverageDuration() const noexcept;
82 size_t GetEventsCount() const noexcept;
83 private:
84 void AddEvent(Duration duration) noexcept;
85
86 static constexpr size_t KERNEL_SIZE = 16;
87
88 Duration mLastDuration {};
89 Duration mMinDuration { std::numeric_limits<Duration::rep>::max() };
91 Duration mAvgAccum {};
92 Duration mAvgDuration {};
93
94 Duration mFilteringKernel[KERNEL_SIZE] {};
95 size_t mNextIndex { 0 };
96 size_t mKernelItems { 0 };
97
98 size_t mEventsCount { 0 };
99
100 friend class FrameStatistics;
101 };
102
104 static Stopwatch CreateStopwatch(SectionID section) noexcept;
106 static const Section& GetSection(SectionID section) noexcept;
109private:
110 void AddEvent(SectionID section, Duration duration);
111
113
115};
int min(int a, int b)
Profiling section data.
RAII wrapper used to measure a section time.
A class to profile TrackPanel painting.
SectionID
ID of the profiling section.
void AddEvent(SectionID section, Duration duration)
UpdatePublisher mUpdatePublisher
Clock::time_point Timepoint
std::chrono::high_resolution_clock Clock
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.
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
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
The TrackPanel class coordinates updates and operations on the main part of the screen which contains...
Definition: TrackPanel.h:63
Cache containing rasterized bitmaps representing the waveform.
Cache that contains the waveform data.
Definition: WaveDataCache.h:94
size_t Count(const Ptr< Type, BaseDeleter > &p)
Find out how many elements were allocated with a Ptr.
Definition: PackedArray.h:143
A helper that notifies the view that a specific section has changed.