JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_PerformanceCounter.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
26static void appendToFile (const File& f, const String& s)
27{
28 if (f.getFullPathName().isNotEmpty())
29 {
30 FileOutputStream out (f);
31
32 if (! out.failedToOpen())
33 out << s << newLine;
34 }
35}
36
38 : runsPerPrint (runsPerPrintout), startTime (0), outputFile (loggingFile)
39{
40 stats.name = name;
41 appendToFile (outputFile, "**** Counter for \"" + name + "\" started at: " + Time::getCurrentTime().toString (true, true));
42}
43
45{
46 if (stats.numRuns > 0)
48}
49
50PerformanceCounter::Statistics::Statistics() noexcept
51 : averageSeconds(), maximumSeconds(), minimumSeconds(), totalSeconds(), numRuns()
52{
53}
54
55void PerformanceCounter::Statistics::clear() noexcept
56{
57 averageSeconds = maximumSeconds = minimumSeconds = totalSeconds = 0;
58 numRuns = 0;
59}
60
61void PerformanceCounter::Statistics::addResult (double elapsed) noexcept
62{
63 if (numRuns == 0)
64 {
65 maximumSeconds = elapsed;
66 minimumSeconds = elapsed;
67 }
68 else
69 {
70 maximumSeconds = jmax (maximumSeconds, elapsed);
71 minimumSeconds = jmin (minimumSeconds, elapsed);
72 }
73
74 ++numRuns;
75 totalSeconds += elapsed;
76}
77
78static String timeToString (double secs)
79{
80 return String ((int64) (secs * (secs < 0.01 ? 1000000.0 : 1000.0) + 0.5))
81 + (secs < 0.01 ? " microsecs" : " millisecs");
82}
83
84String PerformanceCounter::Statistics::toString() const
85{
86 MemoryOutputStream s;
87
88 s << "Performance count for \"" << name << "\" over " << numRuns << " run(s)" << newLine
89 << "Average = " << timeToString (averageSeconds)
90 << ", minimum = " << timeToString (minimumSeconds)
91 << ", maximum = " << timeToString (maximumSeconds)
92 << ", total = " << timeToString (totalSeconds);
93
94 return s.toString();
95}
96
98{
99 startTime = Time::getHighResolutionTicks();
100}
101
103{
105
106 if (stats.numRuns < runsPerPrint)
107 return false;
108
110 return true;
111}
112
114{
115 const String desc (getStatisticsAndReset().toString());
116
117 Logger::writeToLog (desc);
118 appendToFile (outputFile, desc);
119}
120
122{
123 Statistics s (stats);
124 stats.clear();
125
126 if (s.numRuns > 0)
127 s.averageSeconds = s.totalSeconds / (float) s.numRuns;
128
129 return s;
130}
131
132} // namespace juce
Represents a local file or directory.
Definition juce_File.h:45
static void JUCE_CALLTYPE writeToLog(const String &message)
Writes a string to the current logger.
bool stop()
Stops timing and prints out the results.
Statistics getStatisticsAndReset()
Returns a copy of the current stats, and resets the internal counter.
PerformanceCounter(const String &counterName, int runsPerPrintout=100, const File &loggingFile=File())
Creates a PerformanceCounter object.
void start() noexcept
Starts timing.
void printStatistics()
Dumps the current metrics to the debugger output and to a file.
The JUCE String class!
Definition juce_String.h:53
static Time JUCE_CALLTYPE getCurrentTime() noexcept
Returns a Time object that is set to the current system time.
static double highResolutionTicksToSeconds(int64 ticks) noexcept
Converts a number of high-resolution ticks into seconds.
static int64 getHighResolutionTicks() noexcept
Returns the current high-resolution counter's tick-count.
typedef float
JUCE Namespace.
NewLine newLine
A predefined object representing a new-line, which can be written to a string or stream.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
long long int64
A platform-independent 64-bit integer type.