Add RealTimeMicroseconds to HTTP Header X-ClickHouse-Summary

This commit is contained in:
Alejandro 2024-08-28 15:34:34 +01:00
parent d6af09ea27
commit 644cfb27d6
3 changed files with 22 additions and 0 deletions

View File

@ -91,6 +91,8 @@ void ProgressValues::writeJSON(WriteBuffer & out) const
writeText(result_bytes, out);
writeCString("\",\"elapsed_ns\":\"", out);
writeText(elapsed_ns, out);
writeCString("\",\"real_time_microseconds\":\"", out);
writeText(real_time_microseconds, out);
writeCString("\"", out);
writeCString("}", out);
}
@ -110,6 +112,7 @@ bool Progress::incrementPiecewiseAtomically(const Progress & rhs)
result_bytes += rhs.result_bytes;
elapsed_ns += rhs.elapsed_ns;
real_time_microseconds += rhs.real_time_microseconds;
return rhs.read_rows || rhs.written_rows;
}
@ -129,6 +132,7 @@ void Progress::reset()
result_bytes = 0;
elapsed_ns = 0;
real_time_microseconds = 0;
}
ProgressValues Progress::getValues() const
@ -148,6 +152,7 @@ ProgressValues Progress::getValues() const
res.result_bytes = result_bytes.load(std::memory_order_relaxed);
res.elapsed_ns = elapsed_ns.load(std::memory_order_relaxed);
res.real_time_microseconds = real_time_microseconds.load(std::memory_order_relaxed);
return res;
}
@ -169,6 +174,7 @@ ProgressValues Progress::fetchValuesAndResetPiecewiseAtomically()
res.result_bytes = result_bytes.fetch_and(0);
res.elapsed_ns = elapsed_ns.fetch_and(0);
res.real_time_microseconds = real_time_microseconds.fetch_and(0);
return res;
}
@ -190,6 +196,7 @@ Progress Progress::fetchAndResetPiecewiseAtomically()
res.result_bytes = result_bytes.fetch_and(0);
res.elapsed_ns = elapsed_ns.fetch_and(0);
res.real_time_microseconds = real_time_microseconds.fetch_and(0);
return res;
}
@ -209,6 +216,7 @@ Progress & Progress::operator=(Progress && other) noexcept
result_bytes = other.result_bytes.load(std::memory_order_relaxed);
elapsed_ns = other.elapsed_ns.load(std::memory_order_relaxed);
real_time_microseconds = other.real_time_microseconds.load(std::memory_order_relaxed);
return *this;
}
@ -244,4 +252,9 @@ void Progress::incrementElapsedNs(UInt64 elapsed_ns_)
elapsed_ns.fetch_add(elapsed_ns_, std::memory_order_relaxed);
}
void Progress::incrementRealTimeMicroseconds(UInt64 microseconds)
{
real_time_microseconds.fetch_add(microseconds, std::memory_order_relaxed);
}
}

View File

@ -28,6 +28,7 @@ struct ProgressValues
UInt64 result_bytes = 0;
UInt64 elapsed_ns = 0;
UInt64 real_time_microseconds = 0;
void read(ReadBuffer & in, UInt64 server_revision);
void write(WriteBuffer & out, UInt64 client_revision) const;
@ -40,6 +41,7 @@ struct ReadProgress
UInt64 read_bytes = 0;
UInt64 total_rows_to_read = 0;
UInt64 total_bytes_to_read = 0;
UInt64 real_time_microseconds = 0;
ReadProgress(UInt64 read_rows_, UInt64 read_bytes_, UInt64 total_rows_to_read_ = 0, UInt64 total_bytes_to_read_ = 0)
: read_rows(read_rows_), read_bytes(read_bytes_), total_rows_to_read(total_rows_to_read_), total_bytes_to_read(total_bytes_to_read_) {}
@ -96,6 +98,8 @@ struct Progress
std::atomic<UInt64> elapsed_ns {0};
std::atomic<UInt64> real_time_microseconds {0};
Progress() = default;
Progress(UInt64 read_rows_, UInt64 read_bytes_, UInt64 total_rows_to_read_ = 0, UInt64 total_bytes_to_read_ = 0)
@ -125,6 +129,8 @@ struct Progress
void incrementElapsedNs(UInt64 elapsed_ns_);
void incrementRealTimeMicroseconds(UInt64 microseconds);
void reset();
ProgressValues getValues() const;

View File

@ -419,6 +419,9 @@ void logQueryFinish(
{
Progress p;
p.incrementPiecewiseAtomically(Progress{ResultProgress{elem.result_rows, elem.result_bytes}});
UInt64 cpu_real_time = (*info.profile_counters)[ProfileEvents::RealTimeMicroseconds];
p.incrementRealTimeMicroseconds(cpu_real_time);
progress_callback(p);
}