mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 11:05:54 +00:00
Add basic_seconds_clock, insight::Groups
This commit is contained in:
144
beast/insight/impl/Groups.cpp
Normal file
144
beast/insight/impl/Groups.cpp
Normal file
@@ -0,0 +1,144 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "../../make_unique.h"
|
||||
|
||||
namespace beast {
|
||||
namespace insight {
|
||||
|
||||
namespace detail {
|
||||
|
||||
class GroupImp
|
||||
: public std::enable_shared_from_this <GroupImp>
|
||||
, public Group
|
||||
{
|
||||
public:
|
||||
typedef std::vector <std::shared_ptr <BaseImpl>> Items;
|
||||
|
||||
std::string const m_name;
|
||||
Collector::ptr m_collector;
|
||||
Items m_items;
|
||||
|
||||
GroupImp (std::string const& name_,
|
||||
Collector::ptr const& collector)
|
||||
: m_name (name_)
|
||||
, m_collector (collector)
|
||||
{
|
||||
}
|
||||
|
||||
~GroupImp ()
|
||||
{
|
||||
}
|
||||
|
||||
std::string const& name () const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
std::string make_name (std::string const& name)
|
||||
{
|
||||
return m_name + "." + name;
|
||||
}
|
||||
|
||||
Hook make_hook (HookImpl::HandlerType const& handler)
|
||||
{
|
||||
Hook hook (m_collector->make_hook (handler));
|
||||
m_items.emplace_back (hook.impl ());
|
||||
return hook;
|
||||
}
|
||||
|
||||
Counter make_counter (std::string const& name)
|
||||
{
|
||||
Counter counter (m_collector->make_counter (make_name (name)));
|
||||
m_items.emplace_back (counter.impl ());
|
||||
return counter;
|
||||
}
|
||||
|
||||
Event make_event (std::string const& name)
|
||||
{
|
||||
Event event (m_collector->make_event (make_name (name)));
|
||||
m_items.emplace_back (event.impl ());
|
||||
return event;
|
||||
}
|
||||
|
||||
Gauge make_gauge (std::string const& name)
|
||||
{
|
||||
Gauge gauge (m_collector->make_gauge (make_name (name)));
|
||||
m_items.emplace_back (gauge.impl ());
|
||||
return gauge;
|
||||
}
|
||||
|
||||
Meter make_meter (std::string const& name)
|
||||
{
|
||||
Meter meter (m_collector->make_meter (make_name (name)));
|
||||
m_items.emplace_back (meter.impl ());
|
||||
return meter;
|
||||
}
|
||||
|
||||
private:
|
||||
GroupImp& operator= (GroupImp const&);
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class GroupsImp : public Groups
|
||||
{
|
||||
public:
|
||||
typedef std::unordered_map <std::string, std::shared_ptr <Group>> Items;
|
||||
|
||||
Collector::ptr m_collector;
|
||||
Items m_items;
|
||||
|
||||
GroupsImp (Collector::ptr const& collector)
|
||||
: m_collector (collector)
|
||||
{
|
||||
}
|
||||
|
||||
~GroupsImp ()
|
||||
{
|
||||
}
|
||||
|
||||
Group::ptr const& get (std::string const& name)
|
||||
{
|
||||
std::pair <Items::iterator, bool> result (
|
||||
m_items.emplace (name, Group::ptr ()));
|
||||
Group::ptr& group (result.first->second);
|
||||
if (result.second)
|
||||
group = std::make_shared <GroupImp> (name, m_collector);
|
||||
return group;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Groups::~Groups ()
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr <Groups> make_Groups (Collector::ptr const& collector)
|
||||
{
|
||||
return std::make_unique <detail::GroupsImp> (collector);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user