Timer: Migrated to libshared

This commit is contained in:
Paul Beckingham 2016-10-17 21:52:39 -04:00
parent a9061dc299
commit 6bf05083bd
5 changed files with 7 additions and 169 deletions

View file

@ -21,7 +21,6 @@ add_library (task CLI2.cpp CLI2.h
Nibbler.cpp Nibbler.h Nibbler.cpp Nibbler.h
TDB2.cpp TDB2.h TDB2.cpp TDB2.h
Task.cpp Task.h Task.cpp Task.h
Timer.cpp Timer.h
TLSClient.cpp TLSClient.h TLSClient.cpp TLSClient.h
Variant.cpp Variant.h Variant.cpp Variant.h
ViewTask.cpp ViewTask.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/Pig.cpp libshared/src/Pig.h
libshared/src/RX.cpp libshared/src/RX.h libshared/src/RX.cpp libshared/src/RX.h
libshared/src/Table.cpp libshared/src/Table.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/unicode.cpp libshared/src/unicode.h
libshared/src/utf8.cpp libshared/src/utf8.h libshared/src/utf8.cpp libshared/src/utf8.h
libshared/src/wcwidth6.cpp) libshared/src/wcwidth6.cpp)

View file

@ -26,6 +26,7 @@
#include <cmake.h> #include <cmake.h>
#include <Config.h> #include <Config.h>
#include <Context.h>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
@ -382,6 +383,8 @@ std::string Config::_defaults =
"report.blocking.filter= status:pending +BLOCKING\n" "report.blocking.filter= status:pending +BLOCKING\n"
"\n"; "\n";
extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DO NOT CALL Config::setDefaults. // DO NOT CALL Config::setDefaults.
// //
@ -421,6 +424,8 @@ void Config::load (const std::string& file, int nest /* = 1 */)
std::string contents; std::string contents;
if (File::read (file, contents) && contents.length ()) if (File::read (file, contents) && contents.length ())
parse (contents, nest); parse (contents, nest);
context.debug (timer.str ());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -559,6 +559,7 @@ int Hooks::callHookScript (
timer_per_hook.start(); timer_per_hook.start();
status = execute (script, args, inputStr, outputStr); status = execute (script, args, inputStr, outputStr);
context.debug(timer_per_hook.str ());
} }
else else
status = execute (script, args, inputStr, outputStr); status = execute (script, args, inputStr, outputStr);

View file

@ -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 <cmake.h>
#include <Timer.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <Context.h>
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;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -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 <string>
#include <sys/time.h>
// 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