#13126 RiaLogging: Take std::string_view for logElapsedTime message

Switch the message parameter from const QString& to std::string_view so
callers with std::string in hand no longer need a QString::fromStdString
wrapper. The internal duration formatting still uses QString::arg, fed
from a single QString::fromUtf8 conversion.

Callers passing QString locals are updated with .toStdString() at the
call site.
This commit is contained in:
Kristian Bendiksen committed 2026-05-08 10:11:09 +02:00
1 parent bb0afbf962
commit 4957bf5a8b
7 files changed
+21 -20

No files matched your search

@@ -609,7 +609,7 @@ bool RiaApplication::loadProject( const QString& projectFileName, ProjectLoadAct
addToRecentFiles( fullPathProjectFileName );
}
if ( logTiming ) RiaLogging::logElapsedTime( taskName, startTime );
if ( logTiming ) RiaLogging::logElapsedTime( taskName.toStdString(), startTime );
}
{
@@ -673,7 +673,7 @@ bool RiaApplication::loadProject( const QString& projectFileName, ProjectLoadAct
oilField->polygonCollection()->loadData();
}
if ( logTiming ) RiaLogging::logElapsedTime( taskName, startTime );
if ( logTiming ) RiaLogging::logElapsedTime( taskName.toStdString(), startTime );
}
{
@@ -732,7 +732,7 @@ bool RiaApplication::loadProject( const QString& projectFileName, ProjectLoadAct
oilField->surfaceCollection()->loadData();
}
if ( logTiming ) RiaLogging::logElapsedTime( taskName, startTime );
if ( logTiming ) RiaLogging::logElapsedTime( taskName.toStdString(), startTime );
}
{
@@ -755,7 +755,7 @@ bool RiaApplication::loadProject( const QString& projectFileName, ProjectLoadAct
}
}
if ( logTiming ) RiaLogging::logElapsedTime( taskName, startTime );
if ( logTiming ) RiaLogging::logElapsedTime( taskName.toStdString(), startTime );
}
{
@@ -885,7 +885,7 @@ bool RiaApplication::loadProject( const QString& projectFileName, ProjectLoadAct
}
}
if ( logTiming ) RiaLogging::logElapsedTime( taskName, startTime );
if ( logTiming ) RiaLogging::logElapsedTime( taskName.toStdString(), startTime );
}
{
@@ -951,13 +951,13 @@ bool RiaApplication::loadProject( const QString& projectFileName, ProjectLoadAct
RiaPlotWindowRedrawScheduler::instance()->performScheduledUpdates();
if ( logTiming ) RiaLogging::logElapsedTime( taskName, startTime );
if ( logTiming ) RiaLogging::logElapsedTime( taskName.toStdString(), startTime );
}
auto logText = QString( "Project file '%1' loaded successfully." ).arg( projectFileName );
if ( logTiming )
{
RiaLogging::logElapsedTime( logText, startTime );
RiaLogging::logElapsedTime( logText.toStdString(), startTime );
}
else
{
@@ -20,6 +20,7 @@
#include "RiaApplication.h"
#include "RiaPreferencesSystem.h"
#include <format>
#include <iostream>
#include <sstream>
@@ -355,28 +356,27 @@ std::chrono::time_point<std::chrono::high_resolution_clock> RiaLogging::currentT
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaLogging::logElapsedTime( const QString& message, const std::chrono::time_point<std::chrono::high_resolution_clock>& startTime )
void RiaLogging::logElapsedTime( std::string_view message, const std::chrono::time_point<std::chrono::high_resolution_clock>& startTime )
{
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( end - startTime );
auto totalMs = duration.count();
QString text;
auto totalMs = duration.count();
std::string text;
if ( totalMs < 1000 )
{
text = message + QString( " (duration: %1 milliseconds)" ).arg( totalMs );
text = std::format( "{} (duration: {} milliseconds)", message, totalMs );
}
else if ( totalMs < 60000 )
{
double seconds = totalMs / 1000.0;
text = message + QString( " (duration: %1 seconds)" ).arg( seconds, 0, 'f', 1 );
text = std::format( "{} (duration: {:.1f} seconds)", message, seconds );
}
else
{
auto minutes = totalMs / 60000;
auto remainingSeconds = ( totalMs % 60000 ) / 1000.0;
text = message + QString( " (duration: %1 minutes %2 seconds)" ).arg( minutes ).arg( remainingSeconds, 0, 'f', 1 );
text = std::format( "{} (duration: {} minutes {:.1f} seconds)", message, minutes, remainingSeconds );
}
RiaLogging::debug( text );
@@ -21,6 +21,7 @@
#include <chrono>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include <QString>
@@ -73,7 +74,7 @@ public:
static void debug( const QString& message, const QString logKeyword = "" );
static std::chrono::time_point<std::chrono::high_resolution_clock> currentTime();
static void logElapsedTime( const QString& message, const std::chrono::time_point<std::chrono::high_resolution_clock>& startTime );
static void logElapsedTime( std::string_view message, const std::chrono::time_point<std::chrono::high_resolution_clock>& startTime );
private:
static void setLastMessage( const QString& message );
@@ -839,8 +839,7 @@ void RifReaderOpmCommon::setupInitAndRestartAccess()
m_restartFile = std::make_unique<EclIO::ERst>( m_restartFileName );
const bool isLoggingEnabled = RiaPreferencesSystem::current()->isLoggingActivatedForKeyword( "RifReaderOpmCommon" );
if ( isLoggingEnabled )
RiaLogging::logElapsedTime( "Import of meta data from " + QString::fromStdString( m_restartFileName ), startTime );
if ( isLoggingEnabled ) RiaLogging::logElapsedTime( "Import of meta data from " + m_restartFileName, startTime );
}
catch ( ... )
{
@@ -133,7 +133,7 @@ void RivGridPartMgr::generatePartGeometry( cvf::StructGridGeometryGenerator& geo
if ( showDebugTiming )
{
auto text = caf::AppEnum<RivCellSetEnum>::text( m_cellSetType );
RiaLogging::logElapsedTime( text, startTime );
RiaLogging::logElapsedTime( text.toStdString(), startTime );
}
if ( geo.notNull() )
@@ -301,7 +301,7 @@ void RimEnsembleStatisticsCase::calculate( const std::vector<RimSummaryCase*>& s
bool showDebugTiming = false;
if ( showDebugTiming )
{
QString timingText = "RimEnsembleStatisticsCase::calculate" + QString::fromStdString( inputAddress.toEclipseTextAddress() );
std::string timingText = "RimEnsembleStatisticsCase::calculate" + inputAddress.toEclipseTextAddress();
RiaLogging::logElapsedTime( timingText, startTime );
}
}
@@ -201,7 +201,8 @@ std::unique_ptr<RifSummaryReaderInterface> RimFileSummaryCase::findRelatedFilesA
}
bool isLoggingEnabled = RiaPreferencesSystem::current()->isLoggingActivatedForKeyword( "OpmSummaryImport" );
if ( isLoggingEnabled ) RiaLogging::logElapsedTime( "Searched for restart files for " + headerFileName, startTime );
if ( isLoggingEnabled )
RiaLogging::logElapsedTime( ( "Searched for restart files for " + headerFileName ).toStdString(), startTime );
if ( !restartFileNames.empty() )
{