From d0626212a870bb0a2aaddd9e7641f7c38d2d062e Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sat, 27 Apr 2024 15:24:30 +0200 Subject: [PATCH] feat: add --perfmon-trace-file and -o perfmon_trace_file --- doc/dwarfs.md | 8 ++++++-- doc/dwarfsextract.md | 8 ++++++-- src/dwarfs_main.cpp | 13 +++++++++++-- src/dwarfsextract_main.cpp | 13 ++++++++++--- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/doc/dwarfs.md b/doc/dwarfs.md index e469a7ff..9884c02a 100644 --- a/doc/dwarfs.md +++ b/doc/dwarfs.md @@ -156,8 +156,12 @@ options: - `-o perfmon=`*name*: Enable performance monitoring for the list of comma-separated components. This option is only available if the project was built with performance - monitoring enabled. Available components include `fuse`, `filesystem_v2` - and `inode_reader_v2`. + monitoring enabled. Available components include `fuse`, `filesystem_v2`, + `inode_reader_v2` and `block_cache`. + +- `-o perfmon_trace=`*file*: + Write JSON trace data for all components enabled by `--perfmon` to this + file when the process exits. - `--man`: If the project was built with support for built-in manual pages, this diff --git a/doc/dwarfsextract.md b/doc/dwarfsextract.md index b829c559..7603d385 100644 --- a/doc/dwarfsextract.md +++ b/doc/dwarfsextract.md @@ -93,8 +93,12 @@ to disk: - `--perfmon=`*name*: Enable performance monitoring for the list of comma-separated components. This option is only available if the project was built with performance - monitoring enabled. Available components include `fuse`, `filesystem_v2` - and `inode_reader_v2`. + monitoring enabled. Available components include `fuse`, `filesystem_v2`, + `inode_reader_v2` and `block_cache`. + +- `--perfmon-trace=`*file*: + Write JSON trace data for all components enabled by `--perfmon` to this + file when the process exits. - `-h`, `--help`: Show program help, including option defaults. diff --git a/src/dwarfs_main.cpp b/src/dwarfs_main.cpp index 40d53a54..0a0b0c2c 100644 --- a/src/dwarfs_main.cpp +++ b/src/dwarfs_main.cpp @@ -159,7 +159,8 @@ struct options { char const* cache_tidy_interval_str{nullptr}; // TODO: const?? -> use string? char const* cache_tidy_max_age_str{nullptr}; // TODO: const?? -> use string? #if DWARFS_PERFMON_ENABLED - char const* perfmon_enabled_str{nullptr}; // TODO: const?? -> use string? + char const* perfmon_enabled_str{nullptr}; // TODO: const?? -> use string? + char const* perfmon_trace_file_str{nullptr}; // TODO: const?? -> use string? #endif int enable_nlink{0}; int readonly{0}; @@ -237,6 +238,7 @@ constexpr struct ::fuse_opt dwarfs_opts[] = { DWARFS_OPT("no_cache_files", cache_files, 0), #if DWARFS_PERFMON_ENABLED DWARFS_OPT("perfmon=%s", perfmon_enabled_str, 0), + DWARFS_OPT("perfmon_trace=%s", perfmon_trace_file_str, 0), #endif FUSE_OPT_END}; @@ -1041,6 +1043,7 @@ void usage(std::ostream& os, std::filesystem::path const& progname) { << " -o tidy_max_age=TIME tidy blocks after this time (10m)\n" #if DWARFS_PERFMON_ENABLED << " -o perfmon=name[,...] enable performance monitor\n" + << " -o perfmon_trace=FILE write performance monitor trace file\n" #endif #ifdef DWARFS_BUILTIN_MANPAGE << " --man show manual page and exit\n" @@ -1274,15 +1277,21 @@ void load_filesystem(dwarfs_userdata& userdata) { } std::unordered_set perfmon_enabled; + std::optional perfmon_trace_file; #if DWARFS_PERFMON_ENABLED if (opts.perfmon_enabled_str) { folly::splitTo( ',', opts.perfmon_enabled_str, std::inserter(perfmon_enabled, perfmon_enabled.begin())); } + if (opts.perfmon_trace_file_str) { + perfmon_trace_file = userdata.iol.os->canonical(std::filesystem::path( + reinterpret_cast(opts.perfmon_trace_file_str))); + } #endif - userdata.perfmon = performance_monitor::create(perfmon_enabled); + userdata.perfmon = performance_monitor::create( + perfmon_enabled, userdata.iol.file, perfmon_trace_file); PERFMON_EXT_PROXY_SETUP(userdata, userdata.perfmon, "fuse") PERFMON_EXT_TIMER_SETUP(userdata, op_init) diff --git a/src/dwarfsextract_main.cpp b/src/dwarfsextract_main.cpp index cdda7c8e..6fc8cc26 100644 --- a/src/dwarfsextract_main.cpp +++ b/src/dwarfsextract_main.cpp @@ -59,7 +59,7 @@ constexpr std::string_view kDash{"-"}; } // namespace int dwarfsextract_main(int argc, sys_char** argv, iolayer const& iol) { - sys_string filesystem, output; + sys_string filesystem, output, trace_file; std::string format, cache_size_str, image_offset; logger_options logopts; #if DWARFS_PERFMON_ENABLED @@ -103,6 +103,9 @@ int dwarfsextract_main(int argc, sys_char** argv, iolayer const& iol) { ("perfmon", po::value(&perfmon_str), "enable performance monitor") + ("perfmon-trace", + po_sys_value(&trace_file), + "write performance monitor trace file") #endif ; // clang-format on @@ -152,15 +155,19 @@ int dwarfsextract_main(int argc, sys_char** argv, iolayer const& iol) { fsopts.metadata.enable_nlink = true; std::unordered_set perfmon_enabled; + std::optional perfmon_trace_file; #if DWARFS_PERFMON_ENABLED if (!perfmon_str.empty()) { folly::splitTo( ',', perfmon_str, std::inserter(perfmon_enabled, perfmon_enabled.begin())); } + if (!trace_file.empty()) { + perfmon_trace_file = iol.os->canonical(trace_file); + } #endif - std::shared_ptr perfmon = - performance_monitor::create(perfmon_enabled); + std::shared_ptr perfmon = performance_monitor::create( + perfmon_enabled, iol.file, perfmon_trace_file); auto fs_path = iol.os->canonical(filesystem);