PersistentProfilerDataSegment.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::WorkingMemory
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{
32 CollectionInterfacePrx entityCollection,
34 bool useMongoIds) :
35 PersistentEntitySegment(entityCollection, ic, useMongoIds),
36 PersistentProfilerDataSegmentBase()
37 {
38 }
39
40 ProfilerEntityBaseList
41 PersistentProfilerDataSegment::getProfilerDataEntities(const Ice::Current&) const
42 {
43 ProfilerEntityBaseList entities;
44
45 for (const auto& entity : getAllEntities())
46 {
47 if (entity->ice_isA(ProfilerEntityBase::ice_staticId()))
48 {
49 entities.push_back(ProfilerEntityBasePtr::dynamicCast(entity));
50 }
51 }
52
53 return entities;
54 }
55
56 ProfilerEventBaseList
58 {
59 ProfilerEventBaseList entities;
60
61 for (const auto& entity : getAllEntities())
62 {
63 if (entity->ice_isA(ProfilerEventBase::ice_staticId()))
64 {
65 entities.push_back(ProfilerEventBasePtr::dynamicCast(entity));
66 }
67 }
68
69 return entities;
70 }
71
72 ProfilerTransitionBaseList
74 {
75 ProfilerTransitionBaseList entities;
76
77 for (const auto& entity : getAllEntities())
78 {
79 if (entity->ice_isA(ProfilerTransitionBase::ice_staticId()))
80 {
81 entities.push_back(ProfilerTransitionBasePtr::dynamicCast(entity));
82 }
83 }
84 return entities;
85 }
86
87 ProfilerMemorySnapshotBaseList
89 {
90 ProfilerMemorySnapshotBaseList entities;
91
92 for (const auto& entity : getAllEntities())
93 {
94 if (entity->ice_isA(ProfilerMemorySnapshotBase::ice_staticId()))
95 {
96 entities.push_back(ProfilerMemorySnapshotBasePtr::dynamicCast(entity));
97 }
98 }
99
100 return entities;
101 }
102
103 ProfilerProcessBaseList
105 {
106 ProfilerProcessBaseList entities;
107
108 for (const auto& entity : getAllEntities())
109 {
110 if (entity->ice_isA(ProfilerProcessBase::ice_staticId()))
111 {
112 entities.push_back(ProfilerProcessBasePtr::dynamicCast(entity));
113 }
114 }
115
116 return entities;
117 }
118
119 ProfilerMemoryUsageBaseList
121 {
122 ProfilerMemoryUsageBaseList entities;
123
124 for (const auto& entity : getAllEntities())
125 {
126 if (entity->ice_isA(ProfilerMemoryUsageBase::ice_staticId()))
127 {
128 entities.push_back(ProfilerMemoryUsageBasePtr::dynamicCast(entity));
129 }
130 }
131
132 return entities;
133 }
134
135 std::string
137 const ProfilerMemorySnapshotBasePtr& memorySnapshot,
138 const Ice::Current&)
139 {
140 EntityBaseList entities = getEntitiesByAttrValue(
141 ProfilerMemorySnapshot::ATTRIBUTE_STATENAME, memorySnapshot->getName());
142 // check if entity exists
144 memorySnapshot, entities);
145 // if no Id was found, the Entity must be created
146 if (entityId.empty())
147 {
148 entityId = addEntity(memorySnapshot);
149 }
150 return entityId;
151 }
152
153 std::string
155 const ProfilerTransitionBasePtr& transition,
156 const Ice::Current&)
157 {
158 ProfilerTransitionBaseList transitionEntities = getProfilerTransitionEntities();
159 // check if transition exists
160 std::string entityId =
162 transition, transitionEntities);
163 if (entityId.empty())
164 {
165 // create Entity if no Id was found
166 entityId = addEntity(transition);
167 }
168 else
169 {
170 // if (transition.exists) -> inc counter;
171 ProfilerTransitionBasePtr entity =
172 ProfilerTransitionBasePtr::dynamicCast(getEntityById(entityId));
173 entity->setCount(entity->getCount() + 1);
174 updateEntity(entityId, entity);
175 }
176 return entityId;
177 }
178
179 template <typename T>
180 std::string
182 const std::vector<T>& entities)
183 {
184 std::string entityId("");
185 if (entities.empty())
186 {
187 return entityId;
188 }
189
190 auto entityIterator = std::find_if(entities.begin(),
191 entities.end(),
192 [&entity](EntityBasePtr current)
193 { return entity->equalsAttributes(current); });
194 if (entityIterator != entities.end())
195 {
196 entityId = (*entityIterator)->getId();
197 }
198 return entityId;
199 }
200} // namespace memoryx
The PersistentEntitySegment class is the base class for all memory segments containing memoryx::Entit...
std::string addEntity(const EntityBasePtr &entity, const ::Ice::Current &c=Ice::emptyCurrent) override
addEntity add new entity and return the newly generated entity ID
EntityBasePtr getEntityById(const ::std::string &entityId, const ::Ice::Current &=Ice::emptyCurrent) const override
EntityBaseList getEntitiesByAttrValue(const ::std::string &attrName, const ::std::string &attrValue, const ::Ice::Current &=Ice::emptyCurrent) const override
EntityBaseList getAllEntities(const ::Ice::Current &=Ice::emptyCurrent) const override
getAllEntities returns a list of all entities managed by this memory segment
void updateEntity(const ::std::string &entityId, const EntityBasePtr &update, const ::Ice::Current &=Ice::emptyCurrent) override
static std::string GetEntityIdFromList(const EntityBasePtr &entity, const std::vector< T > &entities)
ProfilerProcessBaseList getProfilerProcessCpuUsageEntities(const Ice::Current &=Ice::emptyCurrent) const override
ProfilerEventBaseList getProfilerEventEntities(const Ice::Current &=Ice::emptyCurrent) const override
ProfilerMemoryUsageBaseList getProfilerMemoryUsageBaseEntities(const Ice::Current &=Ice::emptyCurrent) const override
std::string saveOrUpdateTransition(const ProfilerTransitionBasePtr &transition, const Ice::Current &=Ice::emptyCurrent) override
saveOrUpdateTransition if the ProfilerTransition already exists, the count() of it is increased,...
ProfilerMemorySnapshotBaseList getProfilerMemorySnapshotEntities(const Ice::Current &=Ice::emptyCurrent) const override
PersistentProfilerDataSegment(CollectionInterfacePrx entityCollection, Ice::CommunicatorPtr ic, bool useMongoIds=true)
ProfilerTransitionBaseList getProfilerTransitionEntities(const Ice::Current &=Ice::emptyCurrent) const override
std::string saveUniqueMemorySnapshot(const ProfilerMemorySnapshotBasePtr &memorySnapshot, const Ice::Current &=Ice::emptyCurrent) override
saveUniqueMemorySnapshot checks if memorySnaphsot already exists in the segment and creates it otherw...
static const std::string ATTRIBUTE_STATENAME
::IceInternal::Handle<::Ice::Communicator > CommunicatorPtr
Definition IceManager.h:49
VirtualRobot headers.