From 6bf05083bd2ebb2a51e545c0081945d83d962e01 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 17 Oct 2016 21:52:39 -0400 Subject: [PATCH] Timer: Migrated to libshared --- src/CMakeLists.txt | 2 +- src/Config.cpp | 5 ++ src/Hooks.cpp | 1 + src/Timer.cpp | 113 --------------------------------------------- src/Timer.h | 55 ---------------------- 5 files changed, 7 insertions(+), 169 deletions(-) delete mode 100644 src/Timer.cpp delete mode 100644 src/Timer.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8170b9c17..6eaee7cf0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,7 +21,6 @@ add_library (task CLI2.cpp CLI2.h Nibbler.cpp Nibbler.h TDB2.cpp TDB2.h Task.cpp Task.h - Timer.cpp Timer.h TLSClient.cpp TLSClient.h Variant.cpp Variant.h ViewTask.cpp ViewTask.h @@ -41,6 +40,7 @@ add_library (libshared libshared/src/FS.cpp libshared/src/FS.h libshared/src/Pig.cpp libshared/src/Pig.h libshared/src/RX.cpp libshared/src/RX.h libshared/src/Table.cpp libshared/src/Table.h + libshared/src/Timer.cpp libshared/src/Timer.h libshared/src/unicode.cpp libshared/src/unicode.h libshared/src/utf8.cpp libshared/src/utf8.h libshared/src/wcwidth6.cpp) diff --git a/src/Config.cpp b/src/Config.cpp index 3cbe612af..46993dbc1 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -382,6 +383,8 @@ std::string Config::_defaults = "report.blocking.filter= status:pending +BLOCKING\n" "\n"; +extern Context context; + //////////////////////////////////////////////////////////////////////////////// // DO NOT CALL Config::setDefaults. // @@ -421,6 +424,8 @@ void Config::load (const std::string& file, int nest /* = 1 */) std::string contents; if (File::read (file, contents) && contents.length ()) parse (contents, nest); + + context.debug (timer.str ()); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Hooks.cpp b/src/Hooks.cpp index ff07f28a4..79815f787 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -559,6 +559,7 @@ int Hooks::callHookScript ( timer_per_hook.start(); status = execute (script, args, inputStr, outputStr); + context.debug(timer_per_hook.str ()); } else status = execute (script, args, inputStr, outputStr); diff --git a/src/Timer.cpp b/src/Timer.cpp deleted file mode 100644 index ed41c55c9..000000000 --- a/src/Timer.cpp +++ /dev/null @@ -1,113 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2016, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include -#include - -extern Context context; - -//////////////////////////////////////////////////////////////////////////////// -Timer::Timer () -{ -} - -//////////////////////////////////////////////////////////////////////////////// -// Timer starts when the object is constructed with a description. -Timer::Timer (const std::string& description) -: _description (description) -{ - start (); -} - -//////////////////////////////////////////////////////////////////////////////// -// Timer stops when the object is destructed. -Timer::~Timer () -{ - stop (); - - std::stringstream s; - s << "Timer " - << _description - << ' ' - << std::setprecision (6) - << std::fixed - << _total / 1000000.0 - << " sec"; - - context.debug (s.str ()); -} - -//////////////////////////////////////////////////////////////////////////////// -void Timer::start () -{ - if (!_running) - { - gettimeofday (&_start, nullptr); - _running = true; - } -} - -//////////////////////////////////////////////////////////////////////////////// -void Timer::stop () -{ - if (_running) - { - struct timeval end; - gettimeofday (&end, nullptr); - _running = false; - _total += (end.tv_sec - _start.tv_sec) * 1000000 - + (end.tv_usec - _start.tv_usec); - } -} - -//////////////////////////////////////////////////////////////////////////////// -unsigned long Timer::total () const -{ - return _total; -} - -//////////////////////////////////////////////////////////////////////////////// -void Timer::subtract (unsigned long value) -{ - if (value > _total) - _total = 0; - else - _total -= value; -} - -//////////////////////////////////////////////////////////////////////////////// -unsigned long Timer::now () -{ - struct timeval now; - gettimeofday (&now, nullptr); - return now.tv_sec * 1000000 + now.tv_usec; -} - -//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Timer.h b/src/Timer.h deleted file mode 100644 index 60e133799..000000000 --- a/src/Timer.h +++ /dev/null @@ -1,55 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2016, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#ifndef INCLUDED_TIMER -#define INCLUDED_TIMER - -#include -#include - -// Timer is a scope-activated timer that dumps to std::cout at end of scope. -class Timer -{ -public: - Timer (); - explicit Timer (const std::string&); - ~Timer (); - - void start (); - void stop (); - unsigned long total () const; - void subtract (unsigned long); - - static unsigned long now (); - -private: - std::string _description {"-"}; - bool _running {false}; - struct timeval _start {}; - unsigned long _total {0}; -}; - -#endif