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
26
28
29namespace 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
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),
55 ProfilerEntity(source)
56 {
57 }
58
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
76 Ice::ObjectPtr
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 =
128 getAttribute(ATTRIBUTE_MEMORYPARAMETERS)->setValue(new armarx::Variant(memoryParameters));
129 }
130
131} // namespace memoryx
constexpr T c
The StringValueMap class is a subclass of VariantContainer and is comparable to a std::map<std::strin...
static StringValueMapPtr FromStdMap(const std::map< std::string, Type > &map)
FromStdMap creates a StringValueMap from a std::map<std::string, Type>.
The Variant class is described here: Variants.
Definition Variant.h:224
Entity is the superclass for all MemoryX memory chunks.
Definition Entity.h:246
EntityAttributeBasePtr getAttribute(const ::std::string &attrName, const ::Ice::Current &=Ice::emptyCurrent) const override
Retrieve attribute from entity.
Definition Entity.cpp:311
void setName(const ::std::string &name, const ::Ice::Current &=Ice::emptyCurrent) override
Set name of this entity.
Definition Entity.cpp:188
std::mutex attributesMutex
Definition Entity.h:524
std::recursive_mutex wrappersMutex
Definition Entity.h:526
void output(std::ostream &stream) const
Definition Entity.cpp:436
void putAttribute(const ::memoryx::EntityAttributeBasePtr &attr, const ::Ice::Current &=Ice::emptyCurrent) override
Store attribute in entity.
Definition Entity.cpp:347
std::shared_mutex entityMutex
Definition Entity.h:525
ProfilerMemorySnapshotPtr clone(const Ice::Current &c=Ice::emptyCurrent) const
void setStateName(const std::string &statename, const Ice::Current &context=Ice::emptyCurrent) override
void setMemoryParameterMap(const Ice::Context &parameters, const Ice::Current &context=Ice::emptyCurrent) override
static const std::string ATTRIBUTE_STATENAME
static const std::string ATTRIBUTE_MEMORYPARAMETERS
std::string getStateName(const Ice::Current &context=Ice::emptyCurrent) const override
Ice::ObjectPtr ice_clone() const override
Ice::Context getMemoryParameterMap(const Ice::Current &context=Ice::emptyCurrent) const override
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
IceInternal::Handle< StringValueMap > StringValueMapPtr
VirtualRobot headers.
IceInternal::Handle< ProfilerMemorySnapshot > ProfilerMemorySnapshotPtr