replicode
Perf_modules.h
Go to the documentation of this file.
1 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
2 //_/_/
3 //_/_/ HUMANOBS - mBrane - Perf
4 //_/_/
5 //_/_/ Eric Nivel
6 //_/_/ Center for Analysis and Design of Intelligent Agents
7 //_/_/ Reykjavik University, Menntavegur 1, 101 Reykjavik, Iceland
8 //_/_/ http://cadia.ru.is
9 //_/_/ Copyright(c)2012
10 //_/_/
11 //_/_/ This software was developed by the above copyright holder as part of
12 //_/_/ the HUMANOBS EU research project, in collaboration with the
13 //_/_/ following parties:
14 //_/_/
15 //_/_/ Autonomous Systems Laboratory
16 //_/_/ Technical University of Madrid, Spain
17 //_/_/ http://www.aslab.org/
18 //_/_/
19 //_/_/ Communicative Machines
20 //_/_/ Edinburgh, United Kingdom
21 //_/_/ http://www.cmlabs.com/
22 //_/_/
23 //_/_/ Istituto Dalle Molle di Studi sull'Intelligenza Artificiale
24 //_/_/ University of Lugano and SUPSI, Switzerland
25 //_/_/ http://www.idsia.ch/
26 //_/_/
27 //_/_/ Institute of Cognitive Sciences and Technologies
28 //_/_/ Consiglio Nazionale delle Ricerche, Italy
29 //_/_/ http://www.istc.cnr.it/
30 //_/_/
31 //_/_/ Dipartimento di Ingegneria Informatica
32 //_/_/ University of Palermo, Italy
33 //_/_/ http://roboticslab.dinfo.unipa.it/index.php/Main/HomePage
34 //_/_/
35 //_/_/
36 //_/_/ --- HUMANOBS Open-Source BSD License, with CADIA Clause v 1.0 ---
37 //_/_/
38 //_/_/ Redistribution and use in source and binary forms, with or without
39 //_/_/ modification, is permitted provided that the following conditions
40 //_/_/ are met:
41 //_/_/
42 //_/_/ - Redistributions of source code must retain the above copyright
43 //_/_/ and collaboration notice, this list of conditions and the
44 //_/_/ following disclaimer.
45 //_/_/
46 //_/_/ - Redistributions in binary form must reproduce the above copyright
47 //_/_/ notice, this list of conditions and the following
48 //_/_/ disclaimer in the documentation and/or other materials provided
49 //_/_/ with the distribution.
50 //_/_/
51 //_/_/ - Neither the name of its copyright holders nor the names of its
52 //_/_/ contributors may be used to endorse or promote products
53 //_/_/ derived from this software without specific prior written permission.
54 //_/_/
55 //_/_/ - CADIA Clause: The license granted in and to the software under this
56 //_/_/ agreement is a limited-use license. The software may not be used in
57 //_/_/ furtherance of:
58 //_/_/ (i) intentionally causing bodily injury or severe emotional distress
59 //_/_/ to any person;
60 //_/_/ (ii) invading the personal privacy or violating the human rights of
61 //_/_/ any person; or
62 //_/_/ (iii) committing or preparing for any act of war.
63 //_/_/
64 //_/_/ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
65 //_/_/ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
66 //_/_/ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
67 //_/_/ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
68 //_/_/ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
69 //_/_/ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
70 //_/_/ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
71 //_/_/ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
72 //_/_/ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
73 //_/_/ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
74 //_/_/ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
75 //_/_/
76 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
77 
78 #ifndef Perf_modules_h
79 #define Perf_modules_h
80 
81 #include "Perf.h"
82 #include "../Core/module_node.h"
83 
84 #define N module::Node
85 #define NODE module::Node::Get()
86 #define OUTPUT NODE->trace(N::APPLICATION)
87 
88 #include "RR.h"
89 
90 int64_t startTime = 0;
91 int64_t endTime = 0;
92 int32_t runCount = 0;
93 
94 class pong;
96 void start()
97 {
98 }
99 void stop()
100 {
101 }
102 template<class T> Decision decide(T *p)
103 {
104  return WAIT;
105 }
106 template<class T> void react(T *p) // to messages
107 {
108  OUTPUT << "ping " << _id << " got another message..." << std::endl;
109 }
111 {
112  OUTPUT << "ping starting PingPong test, please wait..." << std::endl;
113  startTime = Time::Get();
114  NODE->send(this, new Ball(0), N::LOCAL);
115 }
117 {
118  int32_t counter = p->id;
119 
120  //OUTPUT<<"Test got to '"<<counter<<"' so far..."<<std::endl;
121  if (counter == 500) {
122  runCount++;
123 
124  if (runCount >= 200) {
125  endTime = Time::Get();
127  uint32_t c = (uint32_t)(counter * runCount);
128  OUTPUT << "PingPong test took " << t << "us for " << c << " msgs, " << ((double)t) / ((double)c) << "us per msg" << std::endl;
129  } else {
130  //OUTPUT<<"Test got to '"<<counter*runCount<<"' so far..."<<std::endl;
131  counter = 0;
132  NODE->send(this, new Ball(counter), N::LOCAL);
133  }
134  } else {
135  NODE->send(this, new Ball(counter + 1), N::LOCAL);
136  }
137 }
138 MODULE_CLASS_END(ping)
139 
140 MODULE_CLASS_BEGIN(pong, Module<pong>)
141 void start()
142 {
143 }
144 void stop()
145 {
146 }
147 template<class T> Decision decide(T *p)
148 {
149  return WAIT;
150 }
151 template<class T> void react(T *p) // to messages
152 {
153  OUTPUT << "pong " << _id << " got another message..." << std::endl;
154 }
155 void react(SystemReady *p)
156 {
157  // OUTPUT<<"pong got SystemReady"<<std::endl;
158 }
159 void react(Ball *p)
160 {
161  // OUTPUT<<"pong "<<_id<<" got the ball '"<<p->id<<"'"<<std::endl;
162  NODE->send(this, new ReturnBall(p->id), N::LOCAL);
163 }
164 MODULE_CLASS_END(pong)
165 
166 
167 #endif /* Perf_modules_h */
Definition: Perf_class.h:96
int32_t id
Definition: Perf_class.h:106
int32_t runCount
Definition: Perf_modules.h:92
#define MODULE_CLASS_END(C)
Definition: application.h:204
int32_t id
Definition: Perf_class.h:99
Definition: control_messages.h:89
#define OUTPUT
Definition: Perf_modules.h:86
Definition: application.h:98
void stop()
Definition: Perf_modules.h:99
void start()
Definition: Perf_modules.h:96
#define MODULE_CLASS_BEGIN(C, S)
Definition: application.h:190
int64_t endTime
Definition: Perf_modules.h:91
void react(T *p)
Definition: Perf_modules.h:106
#define NODE
Definition: Perf_modules.h:85
int64_t startTime
Definition: Perf_modules.h:90
Definition: Perf_class.h:103
Decision decide(T *p)
Definition: Perf_modules.h:102