mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-15 07:16:13 -04:00
Just use the global locale (fixes gh #156)
After all the effort of setting the global locale in `safe_main`, we might just as well use it. Also makes the code a lot simpler.
This commit is contained in:
parent
ef02024dc5
commit
82977c7224
@ -24,7 +24,6 @@
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <locale>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -49,13 +48,10 @@ class console_writer : public logger {
|
|||||||
|
|
||||||
void update(const progress& p, bool last);
|
void update(const progress& p, bool last);
|
||||||
|
|
||||||
std::locale const& locale() const override { return locale_; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void rewind();
|
void rewind();
|
||||||
|
|
||||||
std::ostream& os_;
|
std::ostream& os_;
|
||||||
std::locale locale_;
|
|
||||||
std::mutex mx_;
|
std::mutex mx_;
|
||||||
std::atomic<level_type> threshold_;
|
std::atomic<level_type> threshold_;
|
||||||
std::string statebuf_;
|
std::string statebuf_;
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <locale>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@ -59,8 +58,6 @@ class logger {
|
|||||||
virtual void write(level_type level, const std::string& output,
|
virtual void write(level_type level, const std::string& output,
|
||||||
char const* file, int line) = 0;
|
char const* file, int line) = 0;
|
||||||
|
|
||||||
virtual std::locale const& locale() const = 0;
|
|
||||||
|
|
||||||
const std::string& policy_name() const { return policy_name_; }
|
const std::string& policy_name() const { return policy_name_; }
|
||||||
|
|
||||||
template <class Policy>
|
template <class Policy>
|
||||||
@ -88,14 +85,11 @@ class stream_logger : public logger {
|
|||||||
void write(level_type level, const std::string& output, char const* file,
|
void write(level_type level, const std::string& output, char const* file,
|
||||||
int line) override;
|
int line) override;
|
||||||
|
|
||||||
std::locale const& locale() const override { return locale_; }
|
|
||||||
|
|
||||||
void set_threshold(level_type threshold);
|
void set_threshold(level_type threshold);
|
||||||
void set_with_context(bool with_context) { with_context_ = with_context; }
|
void set_with_context(bool with_context) { with_context_ = with_context; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::ostream& os_;
|
std::ostream& os_;
|
||||||
std::locale locale_;
|
|
||||||
std::mutex mx_;
|
std::mutex mx_;
|
||||||
std::atomic<level_type> threshold_;
|
std::atomic<level_type> threshold_;
|
||||||
bool const color_;
|
bool const color_;
|
||||||
@ -109,9 +103,7 @@ class level_logger {
|
|||||||
: lgr_(lgr)
|
: lgr_(lgr)
|
||||||
, level_(level)
|
, level_(level)
|
||||||
, file_(file)
|
, file_(file)
|
||||||
, line_(line) {
|
, line_(line) {}
|
||||||
oss_.imbue(lgr_.locale());
|
|
||||||
}
|
|
||||||
|
|
||||||
level_logger(level_logger const&) = delete;
|
level_logger(level_logger const&) = delete;
|
||||||
|
|
||||||
@ -144,7 +136,6 @@ class timed_level_logger {
|
|||||||
, with_cpu_(with_cpu)
|
, with_cpu_(with_cpu)
|
||||||
, file_(file)
|
, file_(file)
|
||||||
, line_(line) {
|
, line_(line) {
|
||||||
oss_.imbue(lgr_.locale());
|
|
||||||
if (with_cpu) {
|
if (with_cpu) {
|
||||||
cpu_start_time_ = thread_clock::now();
|
cpu_start_time_ = thread_clock::now();
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <locale>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#include <folly/Conv.h>
|
#include <folly/Conv.h>
|
||||||
@ -82,7 +81,6 @@ console_writer::console_writer(std::ostream& os, progress_mode pg_mode,
|
|||||||
size_t width, level_type threshold,
|
size_t width, level_type threshold,
|
||||||
display_mode mode, bool with_context)
|
display_mode mode, bool with_context)
|
||||||
: os_(os)
|
: os_(os)
|
||||||
, locale_{""}
|
|
||||||
, threshold_(threshold)
|
, threshold_(threshold)
|
||||||
, frac_(0.0)
|
, frac_(0.0)
|
||||||
, pg_mode_(pg_mode)
|
, pg_mode_(pg_mode)
|
||||||
@ -183,8 +181,6 @@ void console_writer::update(const progress& p, bool last) {
|
|||||||
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
|
|
||||||
oss.imbue(locale_);
|
|
||||||
|
|
||||||
bool fancy = pg_mode_ == ASCII || pg_mode_ == UNICODE;
|
bool fancy = pg_mode_ == ASCII || pg_mode_ == UNICODE;
|
||||||
|
|
||||||
if (last || fancy) {
|
if (last || fancy) {
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <locale>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <folly/Conv.h>
|
#include <folly/Conv.h>
|
||||||
@ -64,7 +63,6 @@ logger::level_type logger::parse_level(std::string_view level) {
|
|||||||
stream_logger::stream_logger(std::ostream& os, level_type threshold,
|
stream_logger::stream_logger(std::ostream& os, level_type threshold,
|
||||||
bool with_context)
|
bool with_context)
|
||||||
: os_(os)
|
: os_(os)
|
||||||
, locale_{""}
|
|
||||||
, color_(stream_is_fancy_terminal(os))
|
, color_(stream_is_fancy_terminal(os))
|
||||||
, with_context_(with_context) {
|
, with_context_(with_context) {
|
||||||
set_threshold(threshold);
|
set_threshold(threshold);
|
||||||
|
@ -140,7 +140,6 @@ void analyze_frozen(std::ostream& os,
|
|||||||
MappedFrozen<thrift::metadata::metadata> const& meta,
|
MappedFrozen<thrift::metadata::metadata> const& meta,
|
||||||
size_t total_size, int detail) {
|
size_t total_size, int detail) {
|
||||||
using namespace ::apache::thrift::frozen;
|
using namespace ::apache::thrift::frozen;
|
||||||
std::locale loc("");
|
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
stream_logger lgr(oss);
|
stream_logger lgr(oss);
|
||||||
|
|
||||||
@ -157,8 +156,7 @@ void analyze_frozen(std::ostream& os,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
auto fmt_size = [&](auto const& name, size_t count, size_t size) {
|
auto fmt_size = [&](auto const& name, size_t count, size_t size) {
|
||||||
return fmt::format(loc,
|
return fmt::format("{0:>14" DWARFS_FMT_L "} {1:.<20}{2:.>16" DWARFS_FMT_L
|
||||||
"{0:>14" DWARFS_FMT_L "} {1:.<20}{2:.>16" DWARFS_FMT_L
|
|
||||||
"} bytes {3:5.1f}% {4:5.1f} bytes/item\n",
|
"} bytes {3:5.1f}% {4:5.1f} bytes/item\n",
|
||||||
count, name, size, 100.0 * size / total_size,
|
count, name, size, 100.0 * size / total_size,
|
||||||
count > 0 ? static_cast<double>(size) / count : 0.0);
|
count > 0 ? static_cast<double>(size) / count : 0.0);
|
||||||
@ -167,7 +165,6 @@ void analyze_frozen(std::ostream& os,
|
|||||||
auto fmt_detail = [&](auto const& name, size_t count, size_t size,
|
auto fmt_detail = [&](auto const& name, size_t count, size_t size,
|
||||||
std::string num) {
|
std::string num) {
|
||||||
return fmt::format(
|
return fmt::format(
|
||||||
loc,
|
|
||||||
" {0:<20}{1:>16" DWARFS_FMT_L "} bytes {2:>6} "
|
" {0:<20}{1:>16" DWARFS_FMT_L "} bytes {2:>6} "
|
||||||
"{3:5.1f} bytes/item\n",
|
"{3:5.1f} bytes/item\n",
|
||||||
name, size, num, count > 0 ? static_cast<double>(size) / count : 0.0);
|
name, size, num, count > 0 ? static_cast<double>(size) / count : 0.0);
|
||||||
@ -276,8 +273,7 @@ void analyze_frozen(std::ostream& os,
|
|||||||
});
|
});
|
||||||
|
|
||||||
os << "metadata memory usage:\n";
|
os << "metadata memory usage:\n";
|
||||||
os << fmt::format(loc,
|
os << fmt::format(" {0:.<20}{1:.>16" DWARFS_FMT_L
|
||||||
" {0:.<20}{1:.>16" DWARFS_FMT_L
|
|
||||||
"} bytes {2:6.1f} bytes/inode\n",
|
"} bytes {2:6.1f} bytes/inode\n",
|
||||||
"total metadata", total_size,
|
"total metadata", total_size,
|
||||||
static_cast<double>(total_size) / meta.inodes().size());
|
static_cast<double>(total_size) / meta.inodes().size());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user