Loading...
Searching...
No Matches
juce_PerformanceCounter.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API PerformanceCounter
{
public:
//==============================================================================
PerformanceCounter (const String& counterName,
int runsPerPrintout = 100,
const File& loggingFile = File());
~PerformanceCounter();
//==============================================================================
void start() noexcept;
bool stop();
void printStatistics();
struct Statistics
{
Statistics() noexcept;
void clear() noexcept;
String toString() const;
void addResult (double elapsed) noexcept;
String name;
double averageSeconds;
double maximumSeconds;
double minimumSeconds;
double totalSeconds;
int64 numRuns;
};
Statistics getStatisticsAndReset();
private:
//==============================================================================
Statistics stats;
int64 runsPerPrint, startTime;
File outputFile;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PerformanceCounter)
};
//==============================================================================
class JUCE_API ScopedTimeMeasurement
{
public:
ScopedTimeMeasurement (double& resultInSeconds) noexcept
: result (resultInSeconds)
{
result = 0.0;
}
~ScopedTimeMeasurement()
{
static auto scaler = 1.0 / static_cast<double> (Time::getHighResolutionTicksPerSecond());
result = static_cast<double> (Time::getHighResolutionTicks() - startTimeTicks) * scaler;
}
private:
int64 startTimeTicks = Time::getHighResolutionTicks();
double& result;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ScopedTimeMeasurement)
};
} // namespace juce
juce::File
Definition juce_File.h:45
juce::PerformanceCounter::stop
bool stop()
Definition juce_PerformanceCounter.cpp:102
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::Time::getHighResolutionTicks
static int64 getHighResolutionTicks() noexcept
juce::Time::getHighResolutionTicksPerSecond
static int64 getHighResolutionTicksPerSecond() noexcept
juce::PerformanceCounter::Statistics
Definition juce_PerformanceCounter.h:93