forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils: Extract pretty printers into a header
Can be easily reused elsewhere. Signed-off-by: Raphael S. Carvalho <[email protected]>
- Loading branch information
Showing
8 changed files
with
79 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (C) 2023-present ScyllaDB | ||
*/ | ||
|
||
/* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
#include "pretty_printers.hh" | ||
|
||
namespace utils { | ||
|
||
std::ostream& operator<<(std::ostream& os, pretty_printed_data_size data) { | ||
static constexpr const char *suffixes[] = {" bytes", "kB", "MB", "GB", "TB", "PB"}; | ||
|
||
unsigned exp = 0; | ||
while ((data._size >= 1000) && (exp < sizeof(suffixes))) { | ||
exp++; | ||
data._size /= 1000; | ||
} | ||
|
||
os << data._size << suffixes[exp]; | ||
return os; | ||
} | ||
|
||
std::ostream& operator<<(std::ostream& os, pretty_printed_throughput tp) { | ||
uint64_t throughput = tp._duration.count() > 0 ? tp._size / tp._duration.count() : 0; | ||
os << pretty_printed_data_size(throughput) << "/s"; | ||
return os; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2023-present ScyllaDB | ||
*/ | ||
|
||
/* | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <chrono> | ||
#include <ostream> | ||
|
||
namespace utils { | ||
|
||
class pretty_printed_data_size { | ||
uint64_t _size; | ||
public: | ||
pretty_printed_data_size(uint64_t size) : _size(size) {} | ||
|
||
friend std::ostream& operator<<(std::ostream&, pretty_printed_data_size); | ||
}; | ||
|
||
class pretty_printed_throughput { | ||
uint64_t _size; | ||
std::chrono::duration<float> _duration; | ||
public: | ||
pretty_printed_throughput(uint64_t size, std::chrono::duration<float> dur) : _size(size), _duration(std::move(dur)) {} | ||
|
||
friend std::ostream& operator<<(std::ostream&, pretty_printed_throughput); | ||
}; | ||
|
||
} |