MCPcopy Create free account
hub / github.com/apache/kvrocks / BytesToHuman

Function BytesToHuman

src/common/string_util.cc:416–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

414constexpr unsigned long long ExpTo1024(unsigned n) { return 1ULL << (n * 10); }
415
416std::string BytesToHuman(uint64_t n) {
417 if (n < ExpTo1024(1)) {
418 return fmt::format("{}B", n);
419 } else if (n < ExpTo1024(2)) {
420 return fmt::format("{:.2f}K", static_cast<double>(n) / ExpTo1024(1));
421 } else if (n < ExpTo1024(3)) {
422 return fmt::format("{:.2f}M", static_cast<double>(n) / ExpTo1024(2));
423 } else if (n < ExpTo1024(4)) {
424 return fmt::format("{:.2f}G", static_cast<double>(n) / ExpTo1024(3));
425 } else if (n < ExpTo1024(5)) {
426 return fmt::format("{:.2f}T", static_cast<double>(n) / ExpTo1024(4));
427 } else if (n < ExpTo1024(6)) {
428 return fmt::format("{:.2f}P", static_cast<double>(n) / ExpTo1024(5));
429 } else {
430 return fmt::format("{}B", n);
431 }
432}
433
434std::vector<std::string> TokenizeRedisProtocol(const std::string &value) {
435 std::vector<std::string> tokens;

Callers 1

GetMemoryInfoMethod · 0.85

Calls 1

ExpTo1024Function · 0.85

Tested by

no test coverage detected