summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-02-01 09:01:42 +1100
committerMaxime Coste <mawww@kakoune.org>2018-02-01 09:03:16 +1100
commit90c16d2b0d28c4e5607c94c46ebab383796a34f5 (patch)
treeefa1ac86fa3e8927e113fc2950d10052784b7c36 /src
parente41b4ee65da53b36cf26c494653a4e92bbee4091 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/commands.cc9
1 files changed, 9 insertions, 0 deletions
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<DebugFlags>();
+ 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<microseconds>(Clock::now() - start_time).count()));
}
};