OpenShot Audio Library | OpenShotAudio
1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
juce_PerformanceCounter.cpp
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
23
namespace
juce
24
{
25
26
static
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
37
PerformanceCounter::PerformanceCounter
(
const
String
& name,
int
runsPerPrintout,
const
File
& loggingFile)
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
44
PerformanceCounter::~PerformanceCounter
()
45
{
46
if
(stats.numRuns > 0)
47
printStatistics
();
48
}
49
50
PerformanceCounter::Statistics::Statistics() noexcept
51
: averageSeconds(), maximumSeconds(), minimumSeconds(), totalSeconds(), numRuns()
52
{
53
}
54
55
void
PerformanceCounter::Statistics::clear() noexcept
56
{
57
averageSeconds = maximumSeconds = minimumSeconds = totalSeconds = 0;
58
numRuns = 0;
59
}
60
61
void
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
78
static
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
84
String 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
97
void
PerformanceCounter::start
() noexcept
98
{
99
startTime =
Time::getHighResolutionTicks
();
100
}
101
102
bool
PerformanceCounter::stop
()
103
{
104
stats.addResult (
Time::highResolutionTicksToSeconds
(
Time::getHighResolutionTicks
() - startTime));
105
106
if
(stats.numRuns < runsPerPrint)
107
return
false
;
108
109
printStatistics
();
110
return
true
;
111
}
112
113
void
PerformanceCounter::printStatistics
()
114
{
115
const
String
desc (
getStatisticsAndReset
().toString());
116
117
Logger::writeToLog
(desc);
118
appendToFile (outputFile, desc);
119
}
120
121
PerformanceCounter::Statistics
PerformanceCounter::getStatisticsAndReset
()
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
juce::FileOutputStream
Definition
juce_FileOutputStream.h:35
juce::File
Definition
juce_File.h:45
juce::Logger::writeToLog
static void JUCE_CALLTYPE writeToLog(const String &message)
Definition
juce_Logger.cpp:40
juce::PerformanceCounter::stop
bool stop()
Definition
juce_PerformanceCounter.cpp:102
juce::PerformanceCounter::~PerformanceCounter
~PerformanceCounter()
Definition
juce_PerformanceCounter.cpp:44
juce::PerformanceCounter::getStatisticsAndReset
Statistics getStatisticsAndReset()
Definition
juce_PerformanceCounter.cpp:121
juce::PerformanceCounter::PerformanceCounter
PerformanceCounter(const String &counterName, int runsPerPrintout=100, const File &loggingFile=File())
Definition
juce_PerformanceCounter.cpp:37
juce::PerformanceCounter::start
void start() noexcept
Definition
juce_PerformanceCounter.cpp:97
juce::PerformanceCounter::printStatistics
void printStatistics()
Definition
juce_PerformanceCounter.cpp:113
juce::String
Definition
juce_String.h:53
juce::String::String
String() noexcept
Definition
juce_String.cpp:234
juce::Time::getHighResolutionTicks
static int64 getHighResolutionTicks() noexcept
juce::Time::getCurrentTime
static Time JUCE_CALLTYPE getCurrentTime() noexcept
Definition
juce_Time.cpp:233
juce::Time::highResolutionTicksToSeconds
static double highResolutionTicksToSeconds(int64 ticks) noexcept
Definition
juce_Time.cpp:293
juce::PerformanceCounter::Statistics
Definition
juce_PerformanceCounter.h:93
libopenshot-audio
JuceLibraryCode
modules
juce_core
time
juce_PerformanceCounter.cpp
Generated by
1.18.0