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 
30 namespace memoryx
31 {
32 
33  const std::string ProfilerMemorySnapshot::ATTRIBUTE_STATENAME = "stateName";
34  const std::string ProfilerMemorySnapshot::ATTRIBUTE_MEMORYPARAMETERS = "memoryParameters";
35 
36 
38  {
39  initializeAttributes();
40  }
41 
42  ProfilerMemorySnapshot::ProfilerMemorySnapshot(const std::string& stateName, const Ice::Context& parameters)
43  {
44  initializeAttributes();
45  setStateName(stateName);
46  setMemoryParameterMap(parameters);
47  }
48 
50  IceUtil::Shared(source),
51  ::armarx::Serializable(source),
52  EntityBase(),// dont copy
53  ProfilerEntityBase(source),
54  ProfilerMemorySnapshotBase(source),
55  Entity(source),
57  {
58  }
59 
61  {
62  }
63 
64 
65  void ProfilerMemorySnapshot::output(std::ostream& stream) const
66  {
67  Entity::output(stream);
68  }
69 
70  void ProfilerMemorySnapshot::initializeAttributes()
71  {
72  putAttribute(new EntityAttribute(ATTRIBUTE_STATENAME));
73  putAttribute(new EntityAttribute(ATTRIBUTE_MEMORYPARAMETERS));
74  }
75 
76 
78  {
79  return this->clone();
80  }
81 
83  {
84  std::shared_lock entityLock(entityMutex);
85  std::scoped_lock attributesLock(attributesMutex);
86  std::scoped_lock wrappersLock(wrappersMutex);
87  return new ProfilerMemorySnapshot(*this);
88  }
89 
90  std::string ProfilerMemorySnapshot::getStateName(const Ice::Current& context) const
91  {
92  return getAttribute(ATTRIBUTE_STATENAME)->getValue()->getString();
93  }
94 
95  void ProfilerMemorySnapshot::setStateName(const std::string& statename, const Ice::Current& context)
96  {
97  getAttribute(ATTRIBUTE_STATENAME)->setValue(new armarx::Variant(statename));
98  setName(statename);
99  }
100 
101  Ice::Context ProfilerMemorySnapshot::getMemoryParameterMap(const Ice::Current& context) const
102  {
103  Ice::Context memoryParameters;
104  armarx::VariantPtr parameters = armarx::VariantPtr::dynamicCast(getAttribute(ATTRIBUTE_MEMORYPARAMETERS)->getValue());
105  if (!parameters)
106  {
107  return memoryParameters;
108  }
109  armarx::StringValueMapPtr parameterMap = parameters->get<armarx::StringValueMap>();
110  if (!parameterMap)
111  {
112  return memoryParameters;
113  }
114  return parameterMap->toStdMap<std::string>();
115  }
116 
117  void ProfilerMemorySnapshot::setMemoryParameterMap(const Ice::Context& parameters, const Ice::Current& context)
118  {
119  armarx::StringValueMapPtr memoryParameters = armarx::StringValueMap::FromStdMap<std::string>(parameters);
120  getAttribute(ATTRIBUTE_MEMORYPARAMETERS)->setValue(new armarx::Variant(memoryParameters));
121  }
122 
123 }
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
memoryx::Entity::putAttribute
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition: Entity.cpp:327
memoryx::Entity::getAttribute
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition: Entity.cpp:293
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:43
memoryx::ProfilerEntity
Definition: ProfilerEntity.h:36
IceUtil
Definition: Instance.h:21
memoryx::ProfilerMemorySnapshot::~ProfilerMemorySnapshot
~ProfilerMemorySnapshot() override
Definition: ProfilerMemorySnapshot.cpp:60
memoryx::Entity::output
void output(std::ostream &stream) const
Definition: Entity.cpp:409
memoryx::ProfilerMemorySnapshot::ProfilerMemorySnapshot
ProfilerMemorySnapshot()
Definition: ProfilerMemorySnapshot.cpp:37
memoryx::ProfilerMemorySnapshot::setStateName
void setStateName(const std::string &statename, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerMemorySnapshot.cpp:95
IceInternal::Handle< ProfilerMemorySnapshot >
StringValueMap.h
memoryx::ProfilerMemorySnapshot::getStateName
std::string getStateName(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerMemorySnapshot.cpp:90
memoryx::ProfilerMemorySnapshot::getMemoryParameterMap
Ice::Context getMemoryParameterMap(const Ice::Current &context=Ice::emptyCurrent) const override
Definition: ProfilerMemorySnapshot.cpp:101
ProfilerMemorySnapshot.h
memoryx::ProfilerMemorySnapshot::clone
ProfilerMemorySnapshotPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
Definition: ProfilerMemorySnapshot.cpp:82
memoryx::Entity::attributesMutex
std::mutex attributesMutex
Definition: Entity.h:504
memoryx::ProfilerMemorySnapshot
Definition: ProfilerMemorySnapshot.h:41
memoryx::ProfilerMemorySnapshot::setMemoryParameterMap
void setMemoryParameterMap(const Ice::Context &parameters, const Ice::Current &context=Ice::emptyCurrent) override
Definition: ProfilerMemorySnapshot.cpp:117
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
memoryx::Entity::entityMutex
std::shared_mutex entityMutex
Definition: Entity.h:505
memoryx::ProfilerMemorySnapshot::ATTRIBUTE_STATENAME
static const std::string ATTRIBUTE_STATENAME
Definition: ProfilerMemorySnapshot.h:63
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
memoryx::Entity
Definition: Entity.h:246
memoryx::ProfilerMemorySnapshot::ATTRIBUTE_MEMORYPARAMETERS
static const std::string ATTRIBUTE_MEMORYPARAMETERS
Definition: ProfilerMemorySnapshot.h:64
armarx::StringValueMap
The StringValueMap class is a subclass of VariantContainer and is comparable to a std::map<std::strin...
Definition: StringValueMap.h:49
memoryx::Entity::setName
void setName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
Set name of this entity.
Definition: Entity.cpp:179
memoryx::Entity::wrappersMutex
std::recursive_mutex wrappersMutex
Definition: Entity.h:506
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28