From 71ae1373939c9f61af5ca21d5a4fb2221a52ab7e Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Fri, 12 Jan 2018 10:01:35 -0800 Subject: [PATCH] Add ScopedPerfTimer --- src/clang_complete.cc | 1 + src/messages/text_document_completion.cc | 3 +++ src/timer.cc | 7 +++++++ src/timer.h | 8 ++++++++ 4 files changed, 19 insertions(+) diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 84c5dc1a..332e81a0 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -479,6 +479,7 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) { // TODO: before emitting diagnostics check if we have another completion // request and think about servicing that first, because it may be much // faster than reparsing the document. + // TODO: have a separate thread for diagnostics? timer.Reset(); session->tu = diff --git a/src/messages/text_document_completion.cc b/src/messages/text_document_completion.cc index c4c9cfdc..b945ed35 100644 --- a/src/messages/text_document_completion.cc +++ b/src/messages/text_document_completion.cc @@ -3,6 +3,7 @@ #include "include_complete.h" #include "message_handler.h" #include "queue_manager.h" +#include "timer.h" #include "working_files.h" #include "lex_utils.h" @@ -101,6 +102,8 @@ char* tofixedbase64(T input, char* out) { void SortAndFilterCompletionResponse( Out_TextDocumentComplete* complete_response, const std::string& complete_text) { + ScopedPerfTimer timer("SortAndFilterCompletionResponse"); + // Used to inject more completions. #if false const size_t kNumIterations = 250; diff --git a/src/timer.cc b/src/timer.cc index 38fcc3d2..d0dfd9d0 100644 --- a/src/timer.cc +++ b/src/timer.cc @@ -55,3 +55,10 @@ void Timer::Resume() { assert(!start_.has_value()); start_ = Clock::now(); } + +ScopedPerfTimer::ScopedPerfTimer(const std::string& message) : message_(message) {} + +ScopedPerfTimer::~ScopedPerfTimer() { + timer_.ResetAndPrint(message_); +} + diff --git a/src/timer.h b/src/timer.h index dcc857a4..bbe2a955 100644 --- a/src/timer.h +++ b/src/timer.h @@ -29,3 +29,11 @@ struct Timer { // Elapsed time. long long elapsed_ = 0; }; + +struct ScopedPerfTimer { + ScopedPerfTimer(const std::string& message); + ~ScopedPerfTimer(); + + Timer timer_; + std::string message_; +};