MCPcopy Create free account
hub / github.com/facebook/CacheLib / toString

Function toString

cachelib/common/Utils.cpp:349–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

347}
348
349std::string toString(std::chrono::nanoseconds d) {
350 // bunch of constants to help us round up and convert with appropriate
351 // suffix. For example say 90ns or 5.6us or 5.5ms or 55s etc
352 constexpr uint64_t micros =
353 std::chrono::nanoseconds(std::chrono::microseconds(1)).count();
354 constexpr uint64_t millis =
355 std::chrono::nanoseconds(std::chrono::milliseconds(1)).count();
356 constexpr uint64_t secs =
357 std::chrono::nanoseconds(std::chrono::seconds(1)).count();
358
359 uint64_t count = d.count();
360 if (count < micros) {
361 return fmt::format("{}ns", count);
362 } else if (count < millis) {
363 return fmt::format("{:.2f}us", static_cast<double>(count) / micros);
364 } else if (count < secs) {
365 return fmt::format("{:.2f}ms", static_cast<double>(count) / millis);
366 } else {
367 return fmt::format("{:.2f}s", static_cast<double>(count) / secs);
368 }
369}
370
371namespace {
372// char to int conversion

Callers 7

serializeMethod · 0.50
IncResult incRefMethod · 0.50
changeKeyMethod · 0.50
appendChainMethod · 0.50
testReaperOutOfBoundMethod · 0.50
isConsistentMethod · 0.50
TESTFunction · 0.50

Calls 1

countMethod · 0.80

Tested by 2

testReaperOutOfBoundMethod · 0.40
TESTFunction · 0.40