diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-03-04 06:25:05 -0800 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2017-03-04 06:25:05 -0800 |
| commit | 19695fc832f289e2e5ae08335d49bca568af8e27 (patch) | |
| tree | b89ec80349d2d43ce716e1e1ef9efb0c6a920017 /toolsrc/src | |
| parent | 4806aaf460465b972ad1b6203ca744431b296ade (diff) | |
| download | vcpkg-19695fc832f289e2e5ae08335d49bca568af8e27.tar.gz vcpkg-19695fc832f289e2e5ae08335d49bca568af8e27.zip | |
[vcpkg] Deduplicate all timer classes.
Diffstat (limited to 'toolsrc/src')
| -rw-r--r-- | toolsrc/src/commands_build.cpp | 9 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg.cpp | 11 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_Chrono.cpp | 56 | ||||
| -rw-r--r-- | toolsrc/src/vcpkg_System.cpp | 19 |
4 files changed, 11 insertions, 84 deletions
diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp index e51d519f8..02b98e28d 100644 --- a/toolsrc/src/commands_build.cpp +++ b/toolsrc/src/commands_build.cpp @@ -6,6 +6,7 @@ #include "PostBuildLint.h" #include "vcpkg_Dependencies.h" #include "vcpkg_System.h" +#include "vcpkg_Chrono.h" #include "vcpkg_Environment.h" #include "metrics.h" #include "vcpkg_Enums.h" @@ -53,11 +54,11 @@ namespace vcpkg::Commands::Build port_dir.generic_wstring(), ports_cmake_script_path.generic_wstring()); - System::Stopwatch2 timer; - timer.start(); + ElapsedTime timer = ElapsedTime::createStarted(); + int return_code = System::cmd_execute(command); - timer.stop(); - TrackMetric("buildtimeus-" + spec.toString(), timer.microseconds()); + auto buildtimeus = timer.microseconds(); + TrackMetric("buildtimeus-" + spec.toString(), buildtimeus); if (return_code != 0) { diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp index a263be8bc..e94d2538b 100644 --- a/toolsrc/src/vcpkg.cpp +++ b/toolsrc/src/vcpkg.cpp @@ -13,6 +13,7 @@ #include "vcpkg_Input.h" #include "Paragraphs.h" #include "vcpkg_Strings.h" +#include "vcpkg_Chrono.h" using namespace vcpkg; @@ -153,8 +154,6 @@ static void loadConfig() } } -static System::Stopwatch2 g_timer; - static std::string trim_path_from_command_line(const std::string& full_command_line) { Checks::check_exit(full_command_line.size() > 0, "Internal failure - cannot have empty command line"); @@ -175,16 +174,18 @@ static std::string trim_path_from_command_line(const std::string& full_command_l return std::string(it, full_command_line.cend()); } +static ElapsedTime g_timer; + int wmain(const int argc, const wchar_t* const* const argv) { if (argc == 0) std::abort(); - g_timer.start(); + g_timer = ElapsedTime::createStarted(); atexit([]() { - g_timer.stop(); - TrackMetric("elapsed_us", g_timer.microseconds()); + auto elapsed_us = g_timer.microseconds(); + TrackMetric("elapsed_us", elapsed_us); Flush(); }); diff --git a/toolsrc/src/vcpkg_Chrono.cpp b/toolsrc/src/vcpkg_Chrono.cpp index 1bcb439be..e39842df9 100644 --- a/toolsrc/src/vcpkg_Chrono.cpp +++ b/toolsrc/src/vcpkg_Chrono.cpp @@ -60,60 +60,4 @@ namespace vcpkg { return format_time_userfriendly(elapsed<std::chrono::nanoseconds>()); } - - Stopwatch Stopwatch::createUnstarted() - { - return Stopwatch(); - } - - Stopwatch Stopwatch::createStarted() - { - return Stopwatch().start(); - } - - bool Stopwatch::isRunning() const - { - return this->m_isRunning; - } - - const Stopwatch& Stopwatch::start() - { - Checks::check_exit(!this->m_isRunning, "This stopwatch is already running."); - this->m_isRunning = true; - this->m_startTick = std::chrono::high_resolution_clock::now(); - return *this; - } - - const Stopwatch& Stopwatch::stop() - { - auto tick = std::chrono::high_resolution_clock::now(); - Checks::check_exit(this->m_isRunning, "This stopwatch is already stopped."); - this->m_isRunning = false; - this->m_elapsedNanos += tick - this->m_startTick; - return *this; - } - - Stopwatch& Stopwatch::reset() - { - this->m_elapsedNanos = std::chrono::nanoseconds(); - this->m_isRunning = false; - return *this; - } - - std::string Stopwatch::toString() const - { - return format_time_userfriendly(this->elapsedNanos()); - } - - Stopwatch::Stopwatch() : m_isRunning(false), m_elapsedNanos(0), m_startTick() { } - - std::chrono::nanoseconds Stopwatch::elapsedNanos() const - { - if (this->m_isRunning) - { - return std::chrono::high_resolution_clock::now() - this->m_startTick + this->m_elapsedNanos; - } - - return this->m_elapsedNanos; - } } diff --git a/toolsrc/src/vcpkg_System.cpp b/toolsrc/src/vcpkg_System.cpp index 9c849e8d8..679318768 100644 --- a/toolsrc/src/vcpkg_System.cpp +++ b/toolsrc/src/vcpkg_System.cpp @@ -96,23 +96,4 @@ namespace vcpkg::System { _wputenv_s(varname, varvalue); } - - void Stopwatch2::start() - { - static_assert(sizeof(start_time) == sizeof(LARGE_INTEGER), ""); - - QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&start_time)); - } - - void Stopwatch2::stop() - { - QueryPerformanceCounter(reinterpret_cast<LARGE_INTEGER*>(&end_time)); - QueryPerformanceFrequency(reinterpret_cast<LARGE_INTEGER*>(&freq)); - } - - double Stopwatch2::microseconds() const - { - return (reinterpret_cast<const LARGE_INTEGER*>(&end_time)->QuadPart - - reinterpret_cast<const LARGE_INTEGER*>(&start_time)->QuadPart) * 1000000.0 / reinterpret_cast<const LARGE_INTEGER*>(&freq)->QuadPart; - } } |
