mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Add UptimeTimer class
This commit is contained in:
66
modules/ripple_basics/events/ripple_UptimeTimer.cpp
Normal file
66
modules/ripple_basics/events/ripple_UptimeTimer.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
UptimeTimer::UptimeTimer ()
|
||||||
|
: m_shadowPointer (0)
|
||||||
|
, m_startTime (::time (0))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
UptimeTimer::~UptimeTimer ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void UptimeTimer::initializeShadowPointerIfNecessary (int* shadowPointer)
|
||||||
|
{
|
||||||
|
if (m_shadowPointer == 0)
|
||||||
|
{
|
||||||
|
m_shadowPointer = static_cast <int volatile*> (shadowPointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void UptimeTimer::resetShadowPointerIfSet (int* shadowPointer)
|
||||||
|
{
|
||||||
|
if (m_shadowPointer == shadowPointer)
|
||||||
|
{
|
||||||
|
m_shadowPointer = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int UptimeTimer::getElapsedSeconds ()
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
if (m_shadowPointer != 0)
|
||||||
|
{
|
||||||
|
result = *m_shadowPointer;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = static_cast <int> (::time (0) - m_startTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
UptimeTimer& UptimeTimer::getInstance ()
|
||||||
|
{
|
||||||
|
static UptimeTimer instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
44
modules/ripple_basics/events/ripple_UptimeTimer.h
Normal file
44
modules/ripple_basics/events/ripple_UptimeTimer.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
//==============================================================================
|
||||||
|
|
||||||
|
#ifndef RIPPLE_UPTIMETIMER_H
|
||||||
|
#define RIPPLE_UPTIMETIMER_H
|
||||||
|
|
||||||
|
/** Singleton for tracking uptime.
|
||||||
|
*/
|
||||||
|
class UptimeTimer
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
UptimeTimer ();
|
||||||
|
~UptimeTimer ();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void initializeShadowPointerIfNecessary (int* shadowPointer);
|
||||||
|
|
||||||
|
void resetShadowPointerIfSet (int* shadowPointer);
|
||||||
|
|
||||||
|
int getElapsedSeconds ();
|
||||||
|
|
||||||
|
static UptimeTimer& getInstance ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
time_t m_startTime;
|
||||||
|
int volatile* m_shadowPointer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -27,10 +27,12 @@
|
|||||||
// VFALCO: TODO, fix these warnings!
|
// VFALCO: TODO, fix these warnings!
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
//#pragma warning (push) // Causes spurious C4503 "decorated name exceeds maximum length"
|
//#pragma warning (push) // Causes spurious C4503 "decorated name exceeds maximum length"
|
||||||
#pragma warning (disable: 4018) // signed/unsigned mismatch
|
//#pragma warning (disable: 4018) // signed/unsigned mismatch
|
||||||
#pragma warning (disable: 4244) // conversion, possible loss of data
|
//#pragma warning (disable: 4244) // conversion, possible loss of data
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "events/ripple_UptimeTimer.cpp"
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
//#pragma warning (pop)
|
//#pragma warning (pop)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -32,6 +32,10 @@
|
|||||||
#ifndef RIPPLE_BASICS_H
|
#ifndef RIPPLE_BASICS_H
|
||||||
#define RIPPLE_BASICS_H
|
#define RIPPLE_BASICS_H
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
#include "src/cpp/ripple/IntegerTypes.h"
|
#include "src/cpp/ripple/IntegerTypes.h"
|
||||||
|
|
||||||
|
#include "events/ripple_UptimeTimer.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -173,6 +173,12 @@
|
|||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="modules\ripple_basics\events\ripple_UptimeTimer.cpp">
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||||
|
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||||
|
</ClCompile>
|
||||||
<ClCompile Include="modules\ripple_basics\ripple_basics.cpp" />
|
<ClCompile Include="modules\ripple_basics\ripple_basics.cpp" />
|
||||||
<ClCompile Include="modules\ripple_client\ripple_client.cpp" />
|
<ClCompile Include="modules\ripple_client\ripple_client.cpp" />
|
||||||
<ClCompile Include="modules\ripple_db\ripple_db.cpp" />
|
<ClCompile Include="modules\ripple_db\ripple_db.cpp" />
|
||||||
@@ -1163,6 +1169,7 @@
|
|||||||
<ClInclude Include="build\proto\ripple.pb.h" />
|
<ClInclude Include="build\proto\ripple.pb.h" />
|
||||||
<ClInclude Include="database\sqlite3.h" />
|
<ClInclude Include="database\sqlite3.h" />
|
||||||
<ClInclude Include="database\sqlite3ext.h" />
|
<ClInclude Include="database\sqlite3ext.h" />
|
||||||
|
<ClInclude Include="modules\ripple_basics\events\ripple_UptimeTimer.h" />
|
||||||
<ClInclude Include="modules\ripple_basics\ripple_basics.h" />
|
<ClInclude Include="modules\ripple_basics\ripple_basics.h" />
|
||||||
<ClInclude Include="modules\ripple_client\ripple_client.h" />
|
<ClInclude Include="modules\ripple_client\ripple_client.h" />
|
||||||
<ClInclude Include="modules\ripple_db\ripple_db.h" />
|
<ClInclude Include="modules\ripple_db\ripple_db.h" />
|
||||||
|
|||||||
@@ -124,6 +124,9 @@
|
|||||||
<Filter Include="1. Modules\ripple_basics\containers">
|
<Filter Include="1. Modules\ripple_basics\containers">
|
||||||
<UniqueIdentifier>{96cbc9ff-0118-4844-bb4c-05aef58a60b5}</UniqueIdentifier>
|
<UniqueIdentifier>{96cbc9ff-0118-4844-bb4c-05aef58a60b5}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter Include="1. Modules\ripple_basics\events">
|
||||||
|
<UniqueIdentifier>{f585ac4d-1867-4f3d-b0a2-eceae4d7e7e7}</UniqueIdentifier>
|
||||||
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="src\cpp\database\sqlite3.c">
|
<ClCompile Include="src\cpp\database\sqlite3.c">
|
||||||
@@ -738,6 +741,9 @@
|
|||||||
<ClCompile Include="modules\ripple_mess\ripple_mess.cpp">
|
<ClCompile Include="modules\ripple_mess\ripple_mess.cpp">
|
||||||
<Filter>1. Modules\ripple_mess</Filter>
|
<Filter>1. Modules\ripple_mess</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="modules\ripple_basics\events\ripple_UptimeTimer.cpp">
|
||||||
|
<Filter>1. Modules\ripple_basics\events</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="database\sqlite3ext.h">
|
<ClInclude Include="database\sqlite3ext.h">
|
||||||
@@ -1379,6 +1385,9 @@
|
|||||||
<ClInclude Include="src\cpp\ripple\KeyCache.h">
|
<ClInclude Include="src\cpp\ripple\KeyCache.h">
|
||||||
<Filter>1. Modules\ripple_basics\containers</Filter>
|
<Filter>1. Modules\ripple_basics\containers</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="modules\ripple_basics\events\ripple_UptimeTimer.h">
|
||||||
|
<Filter>1. Modules\ripple_basics\events</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="SConstruct" />
|
<None Include="SConstruct" />
|
||||||
|
|||||||
Reference in New Issue
Block a user