tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_CpuMeasurement.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
15{
16 ScopedCpuMeter (std::atomic<double>& valueToUpdate_, double filterAmount_) noexcept
17 : valueToUpdate (valueToUpdate_), filterAmount (filterAmount_)
18 {
19 }
20
21 ~ScopedCpuMeter() noexcept
22 {
23 const double msTaken = juce::Time::getMillisecondCounterHiRes() - callbackStartTime;
24 const auto lastValue = valueToUpdate.load (std::memory_order_acquire);
25 valueToUpdate.store (lastValue + filterAmount * (msTaken - lastValue),
27 }
28
29private:
30 std::atomic<double>& valueToUpdate;
31 const double filterAmount, callbackStartTime { juce::Time::getMillisecondCounterHiRes() };
33};
34
35//==============================================================================
37{
38 StopwatchTimer() noexcept : time (juce::Time::getCurrentTime()) {}
39
40 juce::RelativeTime getTime() const noexcept { return juce::Time::getCurrentTime() - time; }
41 juce::String getDescription() const { return getTime().getDescription(); }
42 double getSeconds() const noexcept { return getTime().inSeconds(); }
43
44private:
45 const juce::Time time;
47};
48
49//==============================================================================
50#if TRACKTION_CHECK_FOR_SLOW_RENDERING
51 struct RealtimeCheck
52 {
53 RealtimeCheck (const char* f, int l, double maxMillisecs) noexcept
55 end (start + maxMillisecs),
56 file (f), line (l)
57 {
58 }
59
60 ~RealtimeCheck() noexcept
61 {
62 const double now = juce::Time::getMillisecondCounterHiRes();
63
64 if (now > end)
65 juce::Logger::outputDebugString (juce::String (now - start) + " " + file + ":" + juce::String (line));
66 }
67
68 double start, end;
69 const char* file;
70 int line;
71 };
72
73 #define SCOPED_REALTIME_CHECK const RealtimeCheck JUCE_JOIN_MACRO(__realtimeCheck, __LINE__) (__FILE__, __LINE__, 1.5);
74 #define SCOPED_REALTIME_CHECK_LONGER const RealtimeCheck JUCE_JOIN_MACRO(__realtimeCheck, __LINE__) (__FILE__, __LINE__, 200 / 44.1);
75#else
76 #define SCOPED_REALTIME_CHECK
77 #define SCOPED_REALTIME_CHECK_LONGER
78#endif
79
80}} // namespace tracktion { inline namespace engine
static void JUCE_CALLTYPE outputDebugString(const String &text)
String getDescription(const String &returnValueForZeroTime="0") const
double inSeconds() const noexcept
static double getMillisecondCounterHiRes() noexcept
static Time JUCE_CALLTYPE getCurrentTime() noexcept
T is_pointer_v
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
T load(T... args)
T store(T... args)