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