OpenShot Audio Library | OpenShotAudio 0.3.2
Loading...
Searching...
No Matches
juce_PerformanceCounter.cpp
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
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
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
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 / s.numRuns;
128
129 return s;
130}
131
132} // namespace juce
static void JUCE_CALLTYPE outputDebugString(const String &text)
PerformanceCounter(const String &counterName, int runsPerPrintout=100, const File &loggingFile=File())
static int64 getHighResolutionTicks() noexcept
static Time JUCE_CALLTYPE getCurrentTime() noexcept
static double highResolutionTicksToSeconds(int64 ticks) noexcept