From 66ec824b4449c884649964c4612f58376a012e1b Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 6 Dec 2020 09:07:27 +1000 Subject: [PATCH] analyse: start using fmtlib for printing --- CMakeLists.txt | 7 ++++++- conanfile.txt | 15 +++++++++++++++ tools/analyse.cpp | 13 +++++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 conanfile.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 705221f..7c1d43a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,11 @@ include_directories(.) add_subdirectory(cruft/util) add_subdirectory(cruft/crypto) +include (${CMAKE_BINARY_DIR}/conan_paths.cmake) + +find_package (fmt REQUIRED) + + ############################################################################### list(APPEND libemory_sources emory/chunk/fwd.cpp @@ -68,7 +73,7 @@ set_target_properties(libemory PROPERTIES OUTPUT_NAME emory) ############################################################################### foreach (t analyse compare stat) add_executable ("${t}" "tools/${t}.cpp") - target_link_libraries ("${t}" libemory cruft-crypto cruft) + target_link_libraries ("${t}" libemory cruft-crypto cruft fmt::fmt) set_target_properties ("${t}" PROPERTIES OUTPUT_NAME "emory-${t}" ) diff --git a/conanfile.txt b/conanfile.txt new file mode 100644 index 0000000..449e806 --- /dev/null +++ b/conanfile.txt @@ -0,0 +1,15 @@ +[requires] +fmt/[~=7] + +[generators] +cmake_find_package +cmake_paths + +[options] +*:shared=True + +[imports] +bin, *.dll* -> bin +bin, *.so* -> bin +lib, *.dll* -> bin +lib, *.so* -> bin diff --git a/tools/analyse.cpp b/tools/analyse.cpp index fc4f314..f4beb17 100644 --- a/tools/analyse.cpp +++ b/tools/analyse.cpp @@ -14,6 +14,9 @@ #include #include +#include +#include + #include #include #include @@ -161,8 +164,14 @@ int main (int argc, char const **argv) ); auto const duplicated_bytes = total_bytes - unique_bytes; - float const duplicated_fraction = 100.f * duplicated_bytes / total_bytes; + float const duplicated_fraction = float (duplicated_bytes) / total_bytes; + + fmt::print ( + "{} duplicated bytes of {} ({:.2f}%)\n", + duplicated_bytes, + total_bytes, + 100.f * duplicated_fraction + ); - std::cout << duplicated_bytes << " duplicated bytes of " << total_bytes << " (" << duplicated_fraction << "%)\n"; std::cout << (src.elements.size () - unique.size ()) << " duplicates\n"; }