Skip to content

Commit

Permalink
Update C++ instrumentation and metrics to use only New mapping (#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Jan 16, 2024
1 parent bd949ca commit e8f89de
Show file tree
Hide file tree
Showing 24 changed files with 169 additions and 1,278 deletions.
782 changes: 39 additions & 743 deletions cpp/include/Ice/Instrumentation.h

Large diffs are not rendered by default.

115 changes: 3 additions & 112 deletions cpp/include/Ice/InstrumentationF.h
Original file line number Diff line number Diff line change
@@ -1,128 +1,19 @@
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
//
// Ice version 3.7.10
//
// <auto-generated>
//
// Generated from file `InstrumentationF.ice'
//
// Warning: do not edit this file.
//
// </auto-generated>
//

#ifndef __Ice_InstrumentationF_h__
#define __Ice_InstrumentationF_h__

#include <IceUtil/PushDisableWarnings.h>
#include <Ice/ProxyF.h>
#include <Ice/ObjectF.h>
#include <Ice/ValueF.h>
#include <Ice/Exception.h>
#include <Ice/LocalObject.h>
#include <Ice/StreamHelpers.h>
#include <Ice/Comparable.h>
#include <IceUtil/ScopedArray.h>
#include <Ice/Optional.h>
#include <IceUtil/UndefSysMacros.h>
#ifndef ICE_INSTRUMENTATION_F_H
#define ICE_INSTRUMENTATION_F_H

#ifndef ICE_IGNORE_VERSION
# if ICE_INT_VERSION / 100 != 307
# error Ice version mismatch!
# endif
# if ICE_INT_VERSION % 100 >= 50
# error Beta header file detected
# endif
# if ICE_INT_VERSION % 100 < 10
# error Ice patch level mismatch!
# endif
#endif

#ifndef ICE_API
# if defined(ICE_STATIC_LIBS)
# define ICE_API /**/
# elif defined(ICE_API_EXPORTS)
# define ICE_API ICE_DECLSPEC_EXPORT
# else
# define ICE_API ICE_DECLSPEC_IMPORT
# endif
#endif

#ifdef ICE_CPP11_MAPPING // C++11 mapping

namespace Ice
{


namespace Instrumentation
namespace Ice::Instrumentation
{

class Observer;
class CommunicatorObserver;

}

}

/// \cond STREAM
namespace Ice
{

}
/// \endcond

/// \cond INTERNAL
namespace Ice
{

/// \cond INTERNAL
namespace Instrumentation
{

using ObserverPtr = ::std::shared_ptr<Observer>;

using CommunicatorObserverPtr = ::std::shared_ptr<CommunicatorObserver>;

}
/// \endcond

}
/// \endcond

#else // C++98 mapping

namespace Ice
{

namespace Instrumentation
{

class Observer;
/// \cond INTERNAL
ICE_API ::Ice::LocalObject* upCast(Observer*);
/// \endcond
typedef ::IceInternal::Handle< Observer> ObserverPtr;

class CommunicatorObserver;
/// \cond INTERNAL
ICE_API ::Ice::LocalObject* upCast(CommunicatorObserver*);
/// \endcond
typedef ::IceInternal::Handle< CommunicatorObserver> CommunicatorObserverPtr;

}

}

/// \cond STREAM
namespace Ice
{

}
/// \endcond

#endif

#include <IceUtil/PopDisableWarnings.h>
#endif
85 changes: 28 additions & 57 deletions cpp/include/Ice/MetricsAdminI.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ namespace IceInternal
{

class ICE_API MetricsMapI;
ICE_DEFINE_PTR(MetricsMapIPtr, MetricsMapI);
using MetricsMapIPtr = std::shared_ptr<MetricsMapI>;

class ICE_API MetricsMapI : public std::enable_shared_from_this<MetricsMapI>

class ICE_API MetricsMapI :
#ifdef ICE_CPP11_MAPPING
public std::enable_shared_from_this<MetricsMapI>
#else
public virtual IceUtil::Shared
#endif
{
public:

Expand Down Expand Up @@ -68,7 +64,7 @@ class ICE_API MetricsMapI :

std::regex _regex;
};
ICE_DEFINE_PTR(RegExpPtr, RegExp);
using RegExpPtr = std::shared_ptr<RegExp>;

virtual ~MetricsMapI();

Expand Down Expand Up @@ -96,9 +92,6 @@ class ICE_API MetricsMapI :
};

class ICE_API MetricsMapFactory
#ifndef ICE_CPP11_MAPPING
: public Ice::LocalObject
#endif
{
public:

Expand All @@ -114,28 +107,22 @@ class ICE_API MetricsMapFactory

IceMX::Updater* _updater;
};
ICE_DEFINE_PTR(MetricsMapFactoryPtr, MetricsMapFactory);
using MetricsMapFactoryPtr = std::shared_ptr<MetricsMapFactory>;

template<class MetricsType> class MetricsMapT : public MetricsMapI, private IceUtil::Mutex
{
public:

typedef MetricsType T;
typedef ICE_SHARED_PTR<MetricsType> TPtr;

ICE_DEFINE_PTR(MetricsMapTPtr, MetricsMapT);
using T = MetricsType;
using TPtr = ICE_SHARED_PTR<MetricsType>;
using MetricsMapTPtr = std::shared_ptr<MetricsMapT>;

typedef IceMX::MetricsMap MetricsType::* SubMapMember;

class EntryT;
ICE_DEFINE_PTR(EntryTPtr, EntryT);
using EntryTPtr = std::shared_ptr<EntryT>;

class EntryT :
#ifdef ICE_CPP11_MAPPING
public std::enable_shared_from_this<EntryT>
#else
public Ice::LocalObject
#endif
class EntryT : public std::enable_shared_from_this<EntryT>
{
public:

Expand Down Expand Up @@ -197,11 +184,7 @@ template<class MetricsType> class MetricsMapT : public MetricsMapI, private IceU
_object->totalLifetime += lifetime;
if(--_object->current == 0)
{
#ifdef ICE_CPP11_MAPPING
_map->detached(this->shared_from_this());
#else
_map->detached(this);
#endif
}
}

Expand Down Expand Up @@ -292,23 +275,17 @@ template<class MetricsType> class MetricsMapT : public MetricsMapI, private IceU
}
}

MetricsMapT(const MetricsMapT& other)
:
#ifndef ICE_CPP11_MAPPING
IceUtil::Shared(),
#endif
MetricsMapT(const MetricsMapT& other) :
MetricsMapI(other),
IceUtil::Mutex(),
_destroyed(false)
{
}

#ifdef ICE_CPP11_MAPPING
std::shared_ptr<MetricsMapT> shared_from_this()
{
return std::static_pointer_cast<MetricsMapT>(MetricsMapI::shared_from_this());
}
#endif

virtual void
destroy()
Expand Down Expand Up @@ -368,9 +345,9 @@ template<class MetricsType> class MetricsMapT : public MetricsMapI, private IceU
_subMaps.find(subMapName);
if(p != _subMaps.end())
{
return std::pair<MetricsMapIPtr, SubMapMember>(ICE_GET_SHARED_FROM_THIS(p->second.second->clone()), p->second.first);
return std::pair<MetricsMapIPtr, SubMapMember>(p->second.second->clone()->shared_from_this(), p->second.first);
}
return std::pair<MetricsMapIPtr, SubMapMember>(MetricsMapIPtr(ICE_NULLPTR), static_cast<SubMapMember>(0));
return std::pair<MetricsMapIPtr, SubMapMember>(MetricsMapIPtr(nullptr), static_cast<SubMapMember>(0));
}

EntryTPtr
Expand All @@ -383,15 +360,15 @@ template<class MetricsType> class MetricsMapT : public MetricsMapI, private IceU
{
if(!(*p)->match(helper, false))
{
return ICE_NULLPTR;
return nullptr;
}
}

for(std::vector<RegExpPtr>::const_iterator p = _reject.begin(); p != _reject.end(); ++p)
{
if((*p)->match(helper, true))
{
return ICE_NULLPTR;
return nullptr;
}
}

Expand Down Expand Up @@ -423,7 +400,7 @@ template<class MetricsType> class MetricsMapT : public MetricsMapI, private IceU
}
catch(const std::exception&)
{
return ICE_NULLPTR;
return nullptr;
}

//
Expand All @@ -432,7 +409,7 @@ template<class MetricsType> class MetricsMapT : public MetricsMapI, private IceU
Lock sync(*this);
if(_destroyed)
{
return ICE_NULLPTR;
return nullptr;
}

if(previous && previous->_object->id == key)
Expand All @@ -444,16 +421,11 @@ template<class MetricsType> class MetricsMapT : public MetricsMapI, private IceU
typename std::map<std::string, EntryTPtr>::const_iterator p = _objects.find(key);
if(p == _objects.end())
{
TPtr t = ICE_MAKE_SHARED(T);
TPtr t = std::make_shared<T>();
t->id = key;

#ifdef ICE_CPP11_MAPPING
p = _objects.insert(typename std::map<std::string, EntryTPtr>::value_type(
key, std::make_shared<EntryT>(shared_from_this(), t, _detachedQueue.end()))).first;
#else
p = _objects.insert(typename std::map<std::string, EntryTPtr>::value_type(
key, new EntryT(this, t, _detachedQueue.end()))).first;
#endif

}
p->second->attach(helper);
Expand All @@ -464,7 +436,7 @@ template<class MetricsType> class MetricsMapT : public MetricsMapI, private IceU

virtual MetricsMapIPtr clone() const
{
return ICE_MAKE_SHARED(MetricsMapT<MetricsType>, *this);
return std::make_shared<MetricsMapT<MetricsType>>(*this);
}

void detached(EntryTPtr entry)
Expand Down Expand Up @@ -540,14 +512,14 @@ template<class MetricsType> class MetricsMapFactoryT : public MetricsMapFactory
virtual MetricsMapIPtr
create(const std::string& mapPrefix, const Ice::PropertiesPtr& properties)
{
return ICE_MAKE_SHARED(MetricsMapT<MetricsType>, mapPrefix, properties, _subMaps);
return std::make_shared<MetricsMapT<MetricsType>>(mapPrefix, properties, _subMaps);
}

template<class SubMapMetricsType> void
registerSubMap(const std::string& subMap, IceMX::MetricsMap MetricsType::* member)
{
_subMaps[subMap] = std::pair<IceMX::MetricsMap MetricsType::*,
MetricsMapFactoryPtr>(member, ICE_MAKE_SHARED(MetricsMapFactoryT<SubMapMetricsType>, ICE_NULLPTR));
MetricsMapFactoryPtr>(member, std::make_shared<MetricsMapFactoryT<SubMapMetricsType>>(nullptr));
}

private:
Expand Down Expand Up @@ -580,7 +552,7 @@ class MetricsViewI : public IceUtil::Shared
const std::string _name;
std::map<std::string, MetricsMapIPtr> _maps;
};
ICE_DEFINE_PTR(MetricsViewIPtr, MetricsViewI);
using MetricsViewIPtr = std::shared_ptr<MetricsViewI>;

class ICE_API MetricsAdminI : public IceMX::MetricsAdmin,
private IceUtil::Mutex
Expand All @@ -601,7 +573,7 @@ class ICE_API MetricsAdminI : public IceMX::MetricsAdmin,
MetricsMapFactoryPtr factory;
{
Lock sync(*this);
factory = ICE_MAKE_SHARED(MetricsMapFactoryT<MetricsType>, updater);
factory = std::make_shared<MetricsMapFactoryT<MetricsType>>(updater);
_factories[map] = factory;
updated = addOrUpdateMap(map, factory);
}
Expand All @@ -615,19 +587,17 @@ class ICE_API MetricsAdminI : public IceMX::MetricsAdmin,
registerSubMap(const std::string& map, const std::string& subMap, IceMX::MetricsMap MetricsType::* member)
{
bool updated;
ICE_HANDLE<MetricsMapFactoryT<MetricsType> > factory;
std::shared_ptr<MetricsMapFactoryT<MetricsType>> factory;
{
Lock sync(*this);
std::map<std::string, MetricsMapFactoryPtr>::const_iterator p = _factories.find(map);
if(p == _factories.end())
{
return;
}
#ifdef ICE_CPP11_MAPPING
factory = ::std::dynamic_pointer_cast<MetricsMapFactoryT<MetricsType>>(p->second);
#else
factory = dynamic_cast<MetricsMapFactoryT<MetricsType>*>(p->second.get());
#endif

// use 'template' keyword to treat 'registerSubMap' as a dependent template name
factory->template registerSubMap<MemberMetricsType>(subMap, member);
removeMap(map);
updated = addOrUpdateMap(map, factory);
Expand Down Expand Up @@ -677,7 +647,8 @@ class ICE_API MetricsAdminI : public IceMX::MetricsAdmin,
const Ice::LoggerPtr _logger;
Ice::PropertiesPtr _properties;
};
ICE_DEFINE_SHARED_PTR(MetricsAdminIPtr, MetricsAdminI);

using MetricsAdminIPtr = std::shared_ptr<MetricsAdminI>;

};

Expand Down
Loading

0 comments on commit e8f89de

Please sign in to comment.