ProfilerMemorySnapshot.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package MemoryX::Core
19  * @author Manfred Kroehnert (Manfred dot Kroehnert at kit dot edu)
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "ProfilerMemorySnapshot.h"
26 
28 
29 namespace memoryx
30 {
31 
32  const std::string ProfilerMemorySnapshot::ATTRIBUTE_STATENAME = "stateName";
33  const std::string ProfilerMemorySnapshot::ATTRIBUTE_MEMORYPARAMETERS = "memoryParameters";
34 
36  {
37  initializeAttributes();
38  }
39 
40  ProfilerMemorySnapshot::ProfilerMemorySnapshot(const std::string& stateName,
41  const Ice::Context& parameters)
42  {
43  initializeAttributes();
44  setStateName(stateName);
45  setMemoryParameterMap(parameters);
46  }
47 
49  IceUtil::Shared(source),
50  ::armarx::Serializable(source),
51  EntityBase(), // dont copy
52  ProfilerEntityBase(source),
53  ProfilerMemorySnapshotBase(source),
54  Entity(source),
56  {
57  }
58 
60  {
61  }
62 
63  void
64  ProfilerMemorySnapshot::output(std::ostream& stream) const
65  {
66  Entity::output(stream);
67  }
68 
69  void
70  ProfilerMemorySnapshot::initializeAttributes()
71  {
72  putAttribute(new EntityAttribute(ATTRIBUTE_STATENAME));
73  putAttribute(new EntityAttribute(ATTRIBUTE_MEMORYPARAMETERS));
74  }
75 
78  {
79  return this->clone();
80  }
81 
83  ProfilerMemorySnapshot::clone(const Ice::Current& c) const
84  {
85  std::shared_lock entityLock(entityMutex);
86  std::scoped_lock attributesLock(attributesMutex);
87  std::scoped_lock wrappersLock(wrappersMutex);
88  return new ProfilerMemorySnapshot(*this);
89  }
90 
91  std::string
92  ProfilerMemorySnapshot::getStateName(const Ice::Current& context) const
93  {
94  return getAttribute(ATTRIBUTE_STATENAME)->getValue()->getString();
95  }
96 
97  void
98  ProfilerMemorySnapshot::setStateName(const std::string& statename, const Ice::Current& context)
99  {
100  getAttribute(ATTRIBUTE_STATENAME)->setValue(new armarx::Variant(statename));
101  setName(statename);
102  }
103 
104  Ice::Context
105  ProfilerMemorySnapshot::getMemoryParameterMap(const Ice::Current& context) const
106  {
107  Ice::Context memoryParameters;
108  armarx::VariantPtr parameters =
109  armarx::VariantPtr::dynamicCast(getAttribute(ATTRIBUTE_MEMORYPARAMETERS)->getValue());
110  if (!parameters)
111  {
112  return memoryParameters;
113  }
114  armarx::StringValueMapPtr parameterMap = parameters->get<armarx::StringValueMap>();
115  if (!parameterMap)
116  {
117  return memoryParameters;
118  }
119  return parameterMap->toStdMap<std::string>();
120  }
121 
122  void
123  ProfilerMemorySnapshot::setMemoryParameterMap(const Ice::Context& parameters,
124  const Ice::Current& context)
125  {
126  armarx::StringValueMapPtr memoryParameters =
127  armarx::StringValueMap::FromStdMap<std::string>(parameters);
128  getAttribute(ATTRIBUTE_MEMORYPARAMETERS)->setValue(new armarx::Variant(memoryParameters));
129  }
130 
131 } // namespace memoryx
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:223
memoryx::Entity::putAttribute
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition: Entity.cpp:347
memoryx::Entity::getAttribute
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition: Entity.cpp:311
memoryx::ProfilerMemorySnapshot::ice_clone
Ice::ObjectPtr ice_clone() const override
Definition: ProfilerMemorySnapshot.cpp:77
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
memoryx::ProfilerEntity
Definition: ProfilerEntity.h:36
IceUtil
Definition: Instance.h:21
memoryx::ProfilerMemorySnapshot::~ProfilerMemorySnapshot
~ProfilerMemorySnapshot() override
Definition: ProfilerMemorySnapshot.cpp:59
memoryx::Entity::output
void output(std::ostream &stream) const
Definition: Entity.cpp:436
memoryx::ProfilerMemorySnapshot::ProfilerMemorySnapshot
ProfilerMemorySnapshot()
Definition: ProfilerMemorySnapshot.cpp:35
memoryx::ProfilerMemorySnapshot::setStateName
void setStateName(const std::string &statename, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerMemorySnapshot.cpp:98
IceInternal::Handle< ProfilerMemorySnapshot >
StringValueMap.h
memoryx::ProfilerMemorySnapshot::getStateName
std::string getStateName(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerMemorySnapshot.cpp:92
memoryx::ProfilerMemorySnapshot::getMemoryParameterMap
Ice::Context getMemoryParameterMap(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerMemorySnapshot.cpp:105
ProfilerMemorySnapshot.h
memoryx::ProfilerMemorySnapshot::clone
ProfilerMemorySnapshotPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: ProfilerMemorySnapshot.cpp:83
memoryx::Entity::attributesMutex
std::mutex attributesMutex
Definition: Entity.h:524
memoryx::ProfilerMemorySnapshot
Definition: ProfilerMemorySnapshot.h:40
memoryx::ProfilerMemorySnapshot::setMemoryParameterMap
void setMemoryParameterMap(const Ice::Context &parameters, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerMemorySnapshot.cpp:123
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:661
memoryx::Entity::entityMutex
std::shared_mutex entityMutex
Definition: Entity.h:525
memoryx::ProfilerMemorySnapshot::ATTRIBUTE_STATENAME
static const std::string ATTRIBUTE_STATENAME
Definition: ProfilerMemorySnapshot.h:65
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
memoryx::Entity
Definition: Entity.h:245
memoryx::ProfilerMemorySnapshot::ATTRIBUTE_MEMORYPARAMETERS
static const std::string ATTRIBUTE_MEMORYPARAMETERS
Definition: ProfilerMemorySnapshot.h:66
armarx::StringValueMap
The StringValueMap class is a subclass of VariantContainer and is comparable to a std::map<std::strin...
Definition: StringValueMap.h:47
memoryx::Entity::setName
void setName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
Set name of this entity.
Definition: Entity.cpp:188
memoryx::Entity::wrappersMutex
std::recursive_mutex wrappersMutex
Definition: Entity.h:526
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27