From 90c16d2b0d28c4e5607c94c46ebab383796a34f5 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 1 Feb 2018 09:01:42 +1100 Subject: [PATCH] Profile the time it takes to source a file `:source` command will now generate timings if profile is enabled in the debug option, to help find which script can be slow to load. This should help for #1823 --- src/commands.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/commands.cc b/src/commands.cc index 8101a6f1..de7d0c98 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1208,6 +1208,10 @@ const CommandDesc source_cmd = { filename_completer, [](const ParametersParser& parser, Context& context, const ShellContext&) { + const DebugFlags debug_flags = context.options()["debug"].get(); + const bool profile = debug_flags & DebugFlags::Profile; + auto start_time = profile ? Clock::now() : Clock::time_point{}; + String path = real_path(parse_filename(parser[0])); String file_content = read_file(path, true); try @@ -1220,6 +1224,11 @@ const CommandDesc source_cmd = { write_to_debug_buffer(format("{}:{}", parser[0], err.what())); throw; } + + using namespace std::chrono; + if (profile) + write_to_debug_buffer(format("sourcing '{}' took {} us", parser[0], + (size_t)duration_cast(Clock::now() - start_time).count())); } };