mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 19:15:54 +00:00
Use duration in insight::Event, add chrono_util
This commit is contained in:
@@ -90,6 +90,7 @@
|
|||||||
<ClInclude Include="..\..\beast\boost\ErrorCode.h" />
|
<ClInclude Include="..\..\beast\boost\ErrorCode.h" />
|
||||||
<ClInclude Include="..\..\beast\ByteOrder.h" />
|
<ClInclude Include="..\..\beast\ByteOrder.h" />
|
||||||
<ClInclude Include="..\..\beast\chrono\chrono_io.h" />
|
<ClInclude Include="..\..\beast\chrono\chrono_io.h" />
|
||||||
|
<ClInclude Include="..\..\beast\chrono\chrono_util.h" />
|
||||||
<ClInclude Include="..\..\beast\chrono\CPUMeter.h" />
|
<ClInclude Include="..\..\beast\chrono\CPUMeter.h" />
|
||||||
<ClInclude Include="..\..\beast\chrono\abstract_clock.h" />
|
<ClInclude Include="..\..\beast\chrono\abstract_clock.h" />
|
||||||
<ClInclude Include="..\..\beast\chrono\manual_clock.h" />
|
<ClInclude Include="..\..\beast\chrono\manual_clock.h" />
|
||||||
|
|||||||
@@ -1239,6 +1239,9 @@
|
|||||||
<ClInclude Include="..\..\beast\make_unique.h">
|
<ClInclude Include="..\..\beast\make_unique.h">
|
||||||
<Filter>beast</Filter>
|
<Filter>beast</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\beast\chrono\chrono_util.h">
|
||||||
|
<Filter>beast\chrono</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="..\..\modules\beast_core\containers\DynamicObject.cpp">
|
<ClCompile Include="..\..\modules\beast_core\containers\DynamicObject.cpp">
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "chrono/abstract_clock.h"
|
#include "chrono/abstract_clock.h"
|
||||||
#include "chrono/chrono_io.h"
|
#include "chrono/chrono_io.h"
|
||||||
|
#include "chrono/chrono_util.h"
|
||||||
#include "chrono/manual_clock.h"
|
#include "chrono/manual_clock.h"
|
||||||
#include "chrono/ratio_io.h"
|
#include "chrono/ratio_io.h"
|
||||||
|
|
||||||
|
|||||||
66
beast/chrono/chrono_util.h
Normal file
66
beast/chrono/chrono_util.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/*
|
||||||
|
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||||
|
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||||
|
|
||||||
|
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 BEAST_CHRONO_UTIL_H_INCLUDED
|
||||||
|
#define BEAST_CHRONO_UTIL_H_INCLUDED
|
||||||
|
|
||||||
|
// From Howard Hinnant
|
||||||
|
// http://home.roadrunner.com/~hinnant/duration_io/chrono_util.html
|
||||||
|
|
||||||
|
// round down
|
||||||
|
template <class To, class Rep, class Period>
|
||||||
|
To floor(std::chrono::duration <Rep, Period> const& d)
|
||||||
|
{
|
||||||
|
To t = std::chrono::duration_cast<To>(d);
|
||||||
|
if (t > d)
|
||||||
|
--t;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
// round to nearest, to even on tie
|
||||||
|
template <class To, class Rep, class Period>
|
||||||
|
To round (std::chrono::duration <Rep, Period> const& d)
|
||||||
|
{
|
||||||
|
To t0 = std::chrono::duration_cast<To>(d);
|
||||||
|
To t1 = t0;
|
||||||
|
++t1;
|
||||||
|
auto diff0 = d - t0;
|
||||||
|
auto diff1 = t1 - d;
|
||||||
|
if (diff0 == diff1)
|
||||||
|
{
|
||||||
|
if (t0.count() & 1)
|
||||||
|
return t1;
|
||||||
|
return t0;
|
||||||
|
}
|
||||||
|
else if (diff0 < diff1)
|
||||||
|
return t0;
|
||||||
|
return t1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// round up
|
||||||
|
template <class To, class Rep, class Period>
|
||||||
|
To ceil (std::chrono::duration <Rep, Period> const& d)
|
||||||
|
{
|
||||||
|
To t = std::chrono::duration_cast<To>(d);
|
||||||
|
if (t < d)
|
||||||
|
++t;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -44,6 +44,8 @@ namespace insight {
|
|||||||
class Collector
|
class Collector
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef std::shared_ptr <Collector> ptr;
|
||||||
|
|
||||||
virtual ~Collector() = 0;
|
virtual ~Collector() = 0;
|
||||||
|
|
||||||
/** Create a hook.
|
/** Create a hook.
|
||||||
|
|||||||
@@ -20,10 +20,13 @@
|
|||||||
#ifndef BEAST_INSIGHT_EVENT_H_INCLUDED
|
#ifndef BEAST_INSIGHT_EVENT_H_INCLUDED
|
||||||
#define BEAST_INSIGHT_EVENT_H_INCLUDED
|
#define BEAST_INSIGHT_EVENT_H_INCLUDED
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "EventImpl.h"
|
#include "EventImpl.h"
|
||||||
|
|
||||||
|
#include "../chrono/chrono_util.h"
|
||||||
|
|
||||||
namespace beast {
|
namespace beast {
|
||||||
namespace insight {
|
namespace insight {
|
||||||
|
|
||||||
@@ -45,8 +48,7 @@ public:
|
|||||||
A null metric reports no information.
|
A null metric reports no information.
|
||||||
*/
|
*/
|
||||||
Event ()
|
Event ()
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
/** Create the metric reference the specified implementation.
|
/** Create the metric reference the specified implementation.
|
||||||
Normally this won't be called directly. Instead, call the appropriate
|
Normally this won't be called directly. Instead, call the appropriate
|
||||||
@@ -55,17 +57,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
explicit Event (std::shared_ptr <EventImpl> const& impl)
|
explicit Event (std::shared_ptr <EventImpl> const& impl)
|
||||||
: m_impl (impl)
|
: m_impl (impl)
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
/** Push an event notification.
|
/** Push an event notification. */
|
||||||
The value specifies the elapsed time in milliseconds, or any other
|
template <class Rep, class Period>
|
||||||
domain specific value.
|
void notify (std::chrono::duration <Rep, Period> const& value) const
|
||||||
*/
|
|
||||||
void notify (value_type value) const
|
|
||||||
{
|
{
|
||||||
if (m_impl)
|
if (m_impl)
|
||||||
m_impl->notify (value);
|
m_impl->notify (ceil <value_type> (value));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -30,10 +30,10 @@ class Event;
|
|||||||
class EventImpl : public std::enable_shared_from_this <EventImpl>
|
class EventImpl : public std::enable_shared_from_this <EventImpl>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef uint64 value_type;
|
typedef std::chrono::milliseconds value_type;
|
||||||
|
|
||||||
virtual ~EventImpl () = 0;
|
virtual ~EventImpl () = 0;
|
||||||
virtual void notify (value_type value) = 0;
|
virtual void notify (value_type const& value) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ public:
|
|||||||
A null metric reports no information.
|
A null metric reports no information.
|
||||||
*/
|
*/
|
||||||
Meter ()
|
Meter ()
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
/** Create the metric reference the specified implementation.
|
/** Create the metric reference the specified implementation.
|
||||||
Normally this won't be called directly. Instead, call the appropriate
|
Normally this won't be called directly. Instead, call the appropriate
|
||||||
@@ -53,8 +52,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
explicit Meter (std::shared_ptr <MeterImpl> const& impl)
|
explicit Meter (std::shared_ptr <MeterImpl> const& impl)
|
||||||
: m_impl (impl)
|
: m_impl (impl)
|
||||||
{
|
{ }
|
||||||
}
|
|
||||||
|
|
||||||
/** Set a handler for polling.
|
/** Set a handler for polling.
|
||||||
If a handler is set, it will be called once per collection interval.
|
If a handler is set, it will be called once per collection interval.
|
||||||
@@ -79,13 +77,22 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Meter const& operator+= (value_type amount) const
|
Meter const& operator+= (value_type amount) const
|
||||||
{ increment (amount); return *this; }
|
{
|
||||||
|
increment (amount);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Meter const& operator++ () const
|
Meter const& operator++ () const
|
||||||
{ increment (1); return *this; }
|
{
|
||||||
|
increment (1);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Meter const& operator++ (int) const
|
Meter const& operator++ (int) const
|
||||||
{ increment (1); return *this; }
|
{
|
||||||
|
increment (1);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ private:
|
|||||||
class NullEventImpl : public EventImpl
|
class NullEventImpl : public EventImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void notify (value_type)
|
void notify (value_type const&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,9 +112,9 @@ public:
|
|||||||
|
|
||||||
~StatsDEventImpl ();
|
~StatsDEventImpl ();
|
||||||
|
|
||||||
void notify (EventImpl::value_type value);
|
void notify (EventImpl::value_type const& alue);
|
||||||
|
|
||||||
void do_notify (EventImpl::value_type value);
|
void do_notify (EventImpl::value_type const& value);
|
||||||
void do_process ();
|
void do_process ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -527,7 +527,7 @@ StatsDEventImpl::~StatsDEventImpl ()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatsDEventImpl::notify (EventImpl::value_type value)
|
void StatsDEventImpl::notify (EventImpl::value_type const& value)
|
||||||
{
|
{
|
||||||
m_impl->get_io_service().dispatch (std::bind (
|
m_impl->get_io_service().dispatch (std::bind (
|
||||||
&StatsDEventImpl::do_notify,
|
&StatsDEventImpl::do_notify,
|
||||||
@@ -535,13 +535,13 @@ void StatsDEventImpl::notify (EventImpl::value_type value)
|
|||||||
shared_from_this ()), value));
|
shared_from_this ()), value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatsDEventImpl::do_notify (EventImpl::value_type value)
|
void StatsDEventImpl::do_notify (EventImpl::value_type const& value)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss <<
|
ss <<
|
||||||
m_impl->prefix() << "." <<
|
m_impl->prefix() << "." <<
|
||||||
m_name << ":" <<
|
m_name << ":" <<
|
||||||
value << "|ms" <<
|
value.count() << "|ms" <<
|
||||||
"\n";
|
"\n";
|
||||||
m_impl->post_buffer (ss.str ());
|
m_impl->post_buffer (ss.str ());
|
||||||
}
|
}
|
||||||
@@ -617,17 +617,18 @@ void StatsDGaugeImpl::do_increment (GaugeImpl::difference_type amount)
|
|||||||
|
|
||||||
if (amount > 0)
|
if (amount > 0)
|
||||||
{
|
{
|
||||||
|
GaugeImpl::value_type const d (
|
||||||
|
static_cast <GaugeImpl::value_type> (amount));
|
||||||
value +=
|
value +=
|
||||||
(amount >= std::numeric_limits <GaugeImpl::value_type>::max() - m_value)
|
(d >= std::numeric_limits <GaugeImpl::value_type>::max() - m_value)
|
||||||
? std::numeric_limits <GaugeImpl::value_type>::max() - m_value
|
? std::numeric_limits <GaugeImpl::value_type>::max() - m_value
|
||||||
: GaugeImpl::value_type (amount);
|
: d;
|
||||||
}
|
}
|
||||||
else if (amount < 0)
|
else if (amount < 0)
|
||||||
{
|
{
|
||||||
value -=
|
GaugeImpl::value_type const d (
|
||||||
(std::abs (amount) >= m_value)
|
static_cast <GaugeImpl::value_type> (-amount));
|
||||||
? m_value
|
value = (d >= value) ? 0 : value - d;
|
||||||
: std::abs (amount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
do_set (value);
|
do_set (value);
|
||||||
|
|||||||
Reference in New Issue
Block a user