Repository: duckdb/duckdb
File: src/include/duckdb/main/query_profiler.hpp (C++)

Code before:
		attach_load_storage_latency.Reset();
		attach_replay_wal_latency.Reset();
		checkpoint_latency.Reset();
		commit_write_wal_latency.Reset();
		wal_replay_entry_count = 0;
		total_bytes_read = 0;
		total_bytes_written = 0;
	}

	ProfilingInfo query_global_info;

	//! The SQL string of the query.
	string query;
	//! The timer of the execution of the entire query.
	Profiler latency;
	//! The timer of the delay when waiting to ATTACH a file.
	Profiler waiting_to_attach_latency;
	//! The timer for loading from storage.
	Profiler attach_load_storage_latency;
	//! The timer for replaying the WAL file.
	Profiler attach_replay_wal_latency;
	//! The timer for running checkpoints.
	Profiler checkpoint_latency;
	//! The timer for the WAL writes
	Profiler commit_write_wal_latency;
	//! The total times WAL is replayed
	atomic<idx_t> wal_replay_entry_count;
	//! The total bytes read by the file system.
	atomic<idx_t> total_bytes_read;
	//! The total bytes written by the file system.
	atomic<idx_t> total_bytes_written;
};

//! QueryProfiler collects the profiling metrics of a query.
class QueryProfiler {
public:
	using TreeMap = reference_map_t<const PhysicalOperator, reference<ProfilingNode>>;

public:
	DUCKDB_API explicit QueryProfiler(ClientContext &context);

public:
	DUCKDB_API bool IsEnabled() const;
	DUCKDB_API bool IsDetailedEnabled() const;
	DUCKDB_API ProfilerPrintFormat GetPrintFormat(ExplainFormat format = ExplainFormat::DEFAULT) const;
	DUCKDB_API bool PrintOptimizerOutput() const;
	DUCKDB_API string GetSaveLocation() const;

	DUCKDB_API static QueryProfiler &Get(ClientContext &context);

	DUCKDB_API void Start(const string &query);

Review comment (suggestion):
`The total number of entries to replay in the WAL.` (just for clarification, it's a bit confusing in the loop, but basically every time we're reading an entry and replaying it, we then increment the offset in the file, so that on the next iteration its the next entry)

Code after:
		attach_load_storage_latency.Reset();
		attach_replay_wal_latency.Reset();
		checkpoint_latency.Reset();
		commit_write_wal_latency.Reset();
		wal_replay_entry_count = 0;
		total_bytes_read = 0;
		total_bytes_written = 0;
	}

	ProfilingInfo query_global_info;

	//! The SQL string of the query.
	string query;
	//! The timer of the execution of the entire query.
	Profiler latency;
	//! The timer of the delay when waiting to ATTACH a file.
	Profiler waiting_to_attach_latency;
	//! The timer for loading from storage.
	Profiler attach_load_storage_latency;
	//! The timer for replaying the WAL file.
	Profiler attach_replay_wal_latency;
	//! The timer for running checkpoints.
	Profiler checkpoint_latency;
	//! The timer for the WAL writes during COMMIT.
	Profiler commit_write_wal_latency;
	//! The total number of entries to replay in the WAL.
	atomic<idx_t> wal_replay_entry_count;
	//! The total bytes read by the file system.
	atomic<idx_t> total_bytes_read;
	//! The total bytes written by the file system.
	atomic<idx_t> total_bytes_written;
};

//! QueryProfiler collects the profiling metrics of a query.
class QueryProfiler {
public:
	using TreeMap = reference_map_t<const PhysicalOperator, reference<ProfilingNode>>;

public:
	DUCKDB_API explicit QueryProfiler(ClientContext &context);

public:
	DUCKDB_API bool IsEnabled() const;
	DUCKDB_API bool IsDetailedEnabled() const;
	DUCKDB_API ProfilerPrintFormat GetPrintFormat(ExplainFormat format = ExplainFormat::DEFAULT) const;
	DUCKDB_API bool PrintOptimizerOutput() const;
	DUCKDB_API string GetSaveLocation() const;

	DUCKDB_API static QueryProfiler &Get(ClientContext &context);

	DUCKDB_API void Start(const string &query);