1
0
mirror of https://github.com/apple/foundationdb.git synced 2025-05-31 10:14:52 +08:00

Add bytes_per_second unit in histograms

This commit is contained in:
Xiaoge Su 2020-11-12 15:38:51 -08:00
parent 8343c78bf0
commit 4a0fa57989
3 changed files with 31 additions and 9 deletions

@ -311,7 +311,7 @@ public:
bytes(Histogram::getHistogram(STORAGESERVER_HISTOGRAM_GROUP, FETCH_KEYS_BYTES_HISTOGRAM,
Histogram::Unit::bytes)),
bandwidth(Histogram::getHistogram(STORAGESERVER_HISTOGRAM_GROUP, FETCH_KEYS_BYTES_PER_SECOND_HISTOGRAM,
Histogram::Unit::bytes)) {}
Histogram::Unit::bytes_per_second)) {}
} fetchKeysHistograms;
class CurrentRunningFetchKeys {

@ -41,6 +41,8 @@ thread_local ISimulator::ProcessInfo* ISimulator::currentProcess = nullptr;
// we have a simulated contex here; we'd just use the current context regardless.
static HistogramRegistry* globalHistograms = nullptr;
#pragma region HistogramRegistry
HistogramRegistry& GetHistogramRegistry() {
ISimulator::ProcessInfo* info = g_simulator.getCurrentProcess();
@ -89,6 +91,16 @@ void HistogramRegistry::logReport() {
}
}
#pragma endregion // HistogramRegistry
#pragma region Histogram
const std::unordered_map<Histogram::Unit, std::string> Histogram::UnitToStringMapper = {
{ Histogram::Unit::microseconds, "microseconds" },
{ Histogram::Unit::bytes, "bytes" },
{ Histogram::Unit::bytes_per_second, "bytes_per_second" }
};
void Histogram::writeToLog() {
bool active = false;
for (uint32_t i = 0; i < 32; i++) {
@ -102,17 +114,19 @@ void Histogram::writeToLog() {
}
TraceEvent e(SevInfo, "Histogram");
e.detail("Group", group).detail("Op", op);
e.detail("Group", group).detail("Op", op).detail("Unit", UnitToStringMapper.at(unit));
for (uint32_t i = 0; i < 32; i++) {
uint32_t value = ((uint32_t)1) << (i + 1);
if (buckets[i]) {
switch (unit) {
case Unit::microseconds: {
uint32_t usec = ((uint32_t)1) << (i + 1);
e.detail(format("LessThan%u.%03u", usec / 1000, usec % 1000), buckets[i]);
case Unit::microseconds:
e.detail(format("LessThan%u.%03u", value / 1000, value % 1000), buckets[i]);
break;
}
case Unit::bytes:
e.detail(format("LessThan%u", ((uint32_t)1) << (i + 1)), buckets[i]);
case Unit::bytes_per_second:
e.detail(format("LessThan%u", value), buckets[i]);
break;
default:
ASSERT(false);
@ -121,6 +135,8 @@ void Histogram::writeToLog() {
}
}
#pragma endregion // Histogram
TEST_CASE("/flow/histogram/smoke_test") {
{
@ -168,4 +184,4 @@ TEST_CASE("/flow/histogram/smoke_test") {
GetHistogramRegistry().logReport();
return Void();
}
}

@ -26,6 +26,7 @@
#include <string>
#include <map>
#include <unordered_map>
#ifdef _WIN32
#include <intrin.h>
@ -57,11 +58,16 @@ HistogramRegistry& GetHistogramRegistry();
*/
class Histogram sealed : public ReferenceCounted<Histogram> {
public:
enum class Unit { microseconds, bytes };
enum class Unit { microseconds, bytes, bytes_per_second };
private:
static const std::unordered_map<Unit, std::string> UnitToStringMapper;
Histogram(std::string group, std::string op, Unit unit, HistogramRegistry& registry)
: group(group), op(op), unit(unit), registry(registry), ReferenceCounted<Histogram>() {
ASSERT(UnitToStringMapper.find(unit) != UnitToStringMapper.end());
clear();
}