Process: Read QTC_MEASURE_PROCESS just once

And store it in static variable.

Change-Id: Ia630f63125088bff32a4d6df9de4c8279c8d8b34
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-01-22 10:05:04 +01:00
parent 77e395f926
commit 60eaa2c826

View File

@@ -58,17 +58,22 @@ static bool isGuiEnabled()
return isGuiApp && isMainThread();
}
static bool isMeasuring()
{
static const bool measuring = qtcEnvironmentVariableIsSet("QTC_MEASURE_PROCESS");
return measuring;
}
class MeasureAndRun
{
public:
MeasureAndRun(const char *functionName)
: m_functionName(functionName)
, m_measureProcess(qtcEnvironmentVariableIsSet("QTC_MEASURE_PROCESS"))
{}
template <typename Function, typename... Args>
std::invoke_result_t<Function, Args...> measureAndRun(Function &&function, Args&&... args)
{
if (!m_measureProcess)
if (!isMeasuring())
return std::invoke(std::forward<Function>(function), std::forward<Args>(args)...);
QElapsedTimer timer;
timer.start();
@@ -151,7 +156,6 @@ private:
}
const char * const m_functionName;
const bool m_measureProcess;
std::atomic_int m_hitThisAll = 0;
std::atomic_int m_hitThisMain = 0;
std::atomic_int64_t m_totalThisAll = 0;