10 #include <rtt-config.h> 18 #include <boost/lexical_cast.hpp> 21 #include <boost/array.hpp> 23 #include <boost/test/unit_test.hpp> 25 #define SAMPLE_SIZE 10000 26 #define SAMPLE_TYPE boost::array<double,SAMPLE_SIZE> 28 #define NUMBER_OF_CYCLES 10000 31 template <
typename T, PortTypes>
struct Adaptor;
34 #if (RTT_VERSION_MAJOR == 1) 36 #define RTT_VERSION_GTE(major,minor,patch) \ 37 ((RTT_VERSION_MAJOR > major) || (RTT_VERSION_MAJOR == major && \ 38 (RTT_VERSION_MINOR > minor) || (RTT_VERSION_MINOR == minor && \ 39 (RTT_VERSION_PATCH >= patch)))) 42 #include "DataPort.hpp" 43 #include "BufferPort.hpp" 52 typedef enum { UnspecifiedReadPolicy, ReadUnordered, ReadShared } ReadPolicy;
53 typedef enum { UnspecifiedWritePolicy, WritePrivate, WriteShared } WritePolicy;
58 static const int DATA = 0;
59 static const int BUFFER = 1;
62 static const int UNSYNC = 0;
63 static const int LOCKED = 1;
66 static const bool PUSH =
false;
67 static const bool PULL =
true;
69 ConnPolicy() :
type(),
size(),
lock_policy(),
init(),
pull(), read_policy(), write_policy(),
max_threads(),
mandatory(),
transport(),
data_size(),
name_id() {}
76 ReadPolicy read_policy;
77 WritePolicy write_policy;
86 #include <boost/thread/mutex.hpp> 87 #include <boost/thread/condition_variable.hpp> 91 void lock() { m.
lock(); }
92 void unlock() { m.unlock(); }
107 void broadcast() { c.notify_all(); }
111 boost::condition_variable_any c;
115 using RTT::OS::ThreadInterface;
133 if ( cpu_affinity.none() )
134 cpu_affinity = ~cpu_affinity;
136 if( task && task->
thread != 0 ) {
139 for(std::size_t i = 0; i < cpu_affinity.size(); i++)
141 if(cpu_affinity[i]) { CPU_SET(i, &cs); }
143 return 0 == pthread_setaffinity_np(task->
thread,
sizeof(cs), &cs);
150 if( task && task->
thread != 0) {
151 std::bitset<16> cpu_affinity;
153 pthread_getaffinity_np(task->
thread,
sizeof(cs), &cs);
154 for(std::size_t i = 0; i < cpu_affinity.size(); i++)
156 if(CPU_ISSET(i, &cs)) { cpu_affinity[i] =
true; }
160 return ~
std::bitset<16>();
164 RTT::ConnectionTypes::ConnectionType con_type;
168 default:
return RTT::ConnectionInterface::shared_ptr();
170 RTT::ConnectionInterface::shared_ptr connection = output_port.connection();
171 if (!connection) connection = input_port.connection();
174 connection->connect();
180 template <
typename T, PortTypes>
183 template <
typename T>
186 typedef RTT::DataPortBase<T>
Port;
194 static void addEventPort(
TaskContext *tc, InputPort &port) {
198 static void setDataSample(OutputPort &port,
const T &sample) {
201 static WriteStatus write(OutputPort &port,
const T &sample) {
207 static FlowStatus read(InputPort &port, T &sample,
bool copy_old_data) {
213 static bool connect(OutputPort &output_port, InputPort &input_port,
const ConnPolicy &cp) {
215 RTT::ConnectionInterface::shared_ptr connection = adaptor::getOrCreateConnection(output_port, input_port, cp);
216 if (!connection)
return false;
223 template <
typename T>
226 typedef RTT::BufferPortBase<T> Port;
227 typedef RTT::ReadBufferPort<T> InputPort;
230 class OutputPort :
public RTT::WriteBufferPort<T>
233 OutputPort(
const std::string &name,
const T &initial_value = T()) :
RTT::WriteBufferPort<T>(name, 0, initial_value) {}
240 static void addEventPort(
TaskContext *tc, InputPort &port) {
244 static void setDataSample(OutputPort &port,
const T &sample) {
247 static WriteStatus write(OutputPort &port,
const T &sample) {
252 static FlowStatus read(InputPort &port, T &sample,
bool copy_old_data) {
257 static bool connect(OutputPort &output_port, InputPort &input_port,
const ConnPolicy &cp) {
259 output_port.setBufferSize(cp.
size);
260 RTT::ConnectionInterface::shared_ptr connection = adaptor::getOrCreateConnection(output_port, input_port, cp);
261 if (!connection)
return false;
273 :
RTT::
Activity(scheduler, priority, period, r, name)
295 #if !RTT_VERSION_GTE(2,8,99) 301 static const bool PUSH =
false;
348 if (!t)
return false;
354 if (!t)
return ~
std::bitset<16>();
359 template <
typename T, PortTypes>
378 #if RTT_VERSION_GTE(2,8,99) 379 static WriteStatus write(OutputPort &port,
const T &sample) {
380 return port.
write(sample);
383 static WriteStatus
write(OutputPort &port,
const T &sample) {
390 return port.
read(sample, copy_old_data);
394 return output_port.
connectTo(&input_port, cp);
399 #if !RTT_VERSION_GTE(2,8,99) 408 default: type =
"(unknown type)";
break;
411 type +=
"[" + boost::lexical_cast<std::string>(cp.
size) +
"]";
419 default: lock_policy =
"(unknown lock policy)";
break;
423 switch(
int(cp.
pull)) {
429 os << lock_policy <<
" ";
438 #define _stringify(x) _stringify2(x) 440 #define _stringify2(x...) #x 458 template <
typename Derived>
478 : Derived(other), sleep_usecs_during_assignment(0), _counter_details(other._counter_details)
489 this_type &
operator=(
const value_type &) {
throw std::runtime_error(
"Cannot assign CopyAndAssignmentCounted type from its value_type directly!"); }
491 if (
this == &other)
return *
this;
495 throw std::runtime_error(
"Conflicting assignment detected: instance is concurrently being assigned by another thread!");
498 throw std::runtime_error(
"Conflicting assignment detected: instance being assigned is concurrently read by another thread!");
501 static_cast<value_type &
>(*this) = other;
504 if (sleep_usecs_during_assignment > 0)
usleep(sleep_usecs_during_assignment);
521 this_type
detachedCopy()
const {
return this_type(static_cast<const value_type &>(*
this)); }
532 template <
typename T>
538 template <
typename T, std::
size_t N>
544 template <
typename T>
548 std::srand(std::time(0));
549 for(
typename T::iterator it = sample.begin(); it != sample.end(); ++it)
555 template <
typename T>
559 std::size_t counter = 0;
560 for(
typename T::iterator it = sample.begin(); it != sample.end(); ++it)
566 timespec
operator-(
const timespec &a,
const timespec &b)
569 result.tv_sec = a.tv_sec - b.tv_sec;
570 if (a.tv_nsec >= b.tv_nsec) {
571 result.tv_nsec = a.tv_nsec - b.tv_nsec;
574 result.tv_nsec = 1000000000 - b.tv_nsec + a.tv_nsec;
579 timespec
operator+(
const timespec &a,
const timespec &b)
582 result.tv_sec = a.tv_sec + b.tv_sec;
583 result.tv_nsec = a.tv_nsec + b.tv_nsec;
584 if (result.tv_nsec >= 1000000000)
587 result.tv_nsec -= 1000000000;
592 timespec
operator/(
const timespec &a,
unsigned long divider)
602 result.tv_sec = a.tv_sec / divider;
603 long long remainder_sec = a.tv_sec % divider;
604 result.tv_nsec = a.tv_nsec / divider + ((remainder_sec * 1000000000ll) / divider);
605 if (result.tv_nsec >= 1000000000)
608 result.tv_nsec -= 1000000000;
616 return (a.tv_sec < b.tv_sec) || (a.tv_sec == b.tv_sec && a.tv_nsec < b.tv_nsec);
619 std::ostream &
operator<<(std::ostream &stream,
const timespec &tp)
621 std::ostringstream seconds;
624 seconds << tp.tv_sec <<
"." << std::setw(9) << std::setfill(
'0') << tp.tv_nsec;
626 return stream << seconds.str();
634 void reset() { monotonic.tv_sec = 0; monotonic.tv_nsec = 0; cputime.tv_sec = 0; cputime.tv_nsec = 0; }
635 operator const void *()
const {
return (monotonic.tv_sec == 0 && monotonic.tv_nsec == 0 && cputime.tv_sec == 0 && cputime.tv_nsec == 0) ? 0 :
this; }
655 std::size_t
count()
const {
return count_; }
666 if (!(min_.monotonic.tv_sec || min_.monotonic.tv_nsec) || (other.
min_.
monotonic < min_.monotonic)) min_.monotonic = other.
min_.
monotonic;
667 if (!(min_.cputime.tv_sec || min_.cputime.tv_nsec) || (other.
min_.
cputime < min_.cputime)) min_.cputime = other.
min_.
cputime;
668 if (!(max_.monotonic.tv_sec || max_.monotonic.tv_nsec) || (max_.monotonic < other.
max_.
monotonic)) max_.monotonic = other.
max_.
monotonic;
669 if (!(max_.cputime.tv_sec || max_.cputime.tv_nsec) || (max_.cputime < other.
max_.
cputime)) max_.cputime = other.
max_.
cputime;
698 #if defined(CLOCK_MONOTONIC) 700 #elif defined(CLOCK_MONOTONIC_RAW) 705 #if defined(CLOCK_THREAD_CPUTIME_ID) 712 if (!tic_)
throw std::runtime_error(
"You called toc() without tic()!");
715 #if defined(CLOCK_MONOTONIC) 717 #elif defined(CLOCK_MONOTONIC_RAW) 722 #if defined(CLOCK_THREAD_CPUTIME_ID) 723 if (0 !=
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &toc.
cputime))
throw std::runtime_error(strerror(errno));
727 last_delta_.monotonic = toc.
monotonic - tic_.monotonic;
728 last_delta_.cputime = toc.
cputime - tic_.cputime;
729 total_.monotonic = total_.monotonic + last_delta_.monotonic;
730 total_.cputime = total_.cputime + last_delta_.cputime;
731 if (!(min_.monotonic.tv_sec || min_.monotonic.tv_nsec) || (last_delta_.monotonic < min_.monotonic)) min_.monotonic = last_delta_.monotonic;
732 if (!(min_.cputime.tv_sec || min_.cputime.tv_nsec) || (last_delta_.cputime < min_.cputime)) min_.cputime = last_delta_.cputime;
733 if (!(max_.monotonic.tv_sec || max_.monotonic.tv_nsec) || (max_.monotonic < last_delta_.monotonic)) max_.monotonic = last_delta_.monotonic;
734 if (!(max_.cputime.tv_sec || max_.cputime.tv_nsec) || (max_.cputime < last_delta_.cputime)) max_.cputime = last_delta_.cputime;
762 , number_of_cycles_(0)
763 , desired_number_of_cycles_(0)
768 number_of_cycles_ = 0;
769 desired_number_of_cycles_ = n;
774 BOOST_REQUIRE_MESSAGE(!this->inException(), exception_reason_);
779 bool finished =
false;
783 if ((desired_number_of_cycles_ > 0) && (number_of_cycles_ >= desired_number_of_cycles_)) finished =
true;
784 finished_.broadcast();
786 if (trigger && !finished) {
790 if (finished) this->stop();
795 return (desired_number_of_cycles_ > 0) && (number_of_cycles_ >= desired_number_of_cycles_);
800 if (inException())
return;
802 while(number_of_cycles_ < desired_number_of_cycles_) {
803 finished_.wait(mutex_);
810 return number_of_cycles_;
816 return desired_number_of_cycles_;
829 template <
typename T, PortTypes PortType>
840 Writer(
const std::string &name, std::size_t index, std::size_t sample_size = 1,
bool keep_last_written_value =
false)
843 , timer(getName() +
"::write()")
845 #if RTT_VERSION_MAJOR >= 2 848 AdaptorType::addPort(
this, output_port);
850 AdaptorType::setDataSample(output_port, sample.
detachedCopy());
869 fs = AdaptorType::write(output_port, sample);
871 timer_by_status[fs].updateFrom(timer);
872 this->afterUpdateHook(
true);
873 }
catch(std::exception &e) {
874 exception_reason_ = e.what();
885 template <
typename T, PortTypes PortType>
896 Reader(
const std::string &name, std::size_t index,
bool read_loop,
bool copy_old_data)
899 , timer(getName() +
"::read()")
900 , read_loop_(read_loop)
901 , copy_old_data_(copy_old_data)
903 AdaptorType::addEventPort(
this, input_port);
925 timer_by_status[fs].updateFrom(timer);
926 if (!read_loop_)
break;
929 this->afterUpdateHook(
false);
930 }
catch(std::exception &e) {
931 exception_reason_ = e.what();
974 WriteMode(WriteAsynchronous),
975 ReadMode(ReadAsynchronous),
976 KeepLastWrittenValue(false),
979 SleepUsecsDuringWriteAssignment(1),
980 SleepUsecsDuringReadAssignment(10),
983 CpuAffinity(getDefaultCpuAffinity() &
std::bitset<16>(0x000f))
990 static std::bitset<16> default_cpu_affinity(0);
991 if (default_cpu_affinity.none()) {
995 return default_cpu_affinity;
1000 static std::map<int, const char *> map;
1005 return map.at(scheduler);
1011 os <<
"***************************************************************************************************************************" <<
std::endl;
1032 os <<
" * Write mode: NONE (no writes)" <<
std::endl;
break;
1034 os <<
" * Write mode: Synchronous" <<
std::endl;
break;
1036 os <<
" * Write mode: Asynchronous" <<
std::endl;
break;
1038 os <<
" * Keep last written value: " << (options.
KeepLastWrittenValue ?
"yes" :
"no") << std::endl;
1042 os <<
" * Read mode: NONE (no reads)" <<
std::endl;
break;
1044 os <<
" * Read mode: Synchronous" <<
std::endl;
break;
1046 os <<
" * Read mode: Asynchronous" <<
std::endl;
break;
1048 os <<
" * Read in loop: " << (options.
ReadLoop ?
"yes" :
"no") << std::endl;
1049 os <<
" * Copy old data: " << (options.
CopyOldData ?
"yes" :
"no") << std::endl;
1050 os <<
"***************************************************************************************************************************" <<
std::endl;
1056 template <
typename T, PortTypes PortType>
1065 typedef boost::shared_ptr<ReaderWriterTaskContextBase>
TaskPtr;
1078 for(std::size_t index = 0; index < options_.NumberOfWriters; ++index) {
1079 WriterPtr writer(
new Writer<T,PortType>(
"Writer", index, options_.SampleSize, options_.KeepLastWrittenValue));
1080 writers.push_back(writer);
1081 tasks.push_back(writer);
1082 switch(options_.WriteMode) {
1085 writer->setDesiredNumberOfCycles(options_.NumberOfCycles);
1088 writer->setActivity(
new Activity(options_.SchedulerType, options_.ThreadPriority, 0.0, options_.CpuAffinity.to_ulong(), 0, writer->getName()));
1090 BOOST_WARN_EQUAL(writer->getActivity()->thread()->getScheduler(), options_.SchedulerType);
1091 BOOST_WARN_EQUAL(writer->getActivity()->thread()->getPriority(), options_.ThreadPriority);
1093 writer->setDesiredNumberOfCycles(options_.NumberOfCycles);
1101 for(std::size_t index = 0; index < options_.NumberOfReaders; ++index) {
1102 ReaderPtr reader(
new Reader<T,PortType>(
"Reader", index, options_.ReadLoop, options_.CopyOldData));
1103 readers.push_back(reader);
1104 tasks.push_back(reader);
1105 switch(options_.ReadMode) {
1108 reader->setDesiredNumberOfCycles(options_.NumberOfCycles);
1111 reader->setActivity(
new Activity(options_.SchedulerType, options_.ThreadPriority, 0.0, options_.CpuAffinity.to_ulong(), 0, reader->getName()));
1113 BOOST_WARN_EQUAL(reader->getActivity()->thread()->getScheduler(), options_.SchedulerType);
1114 BOOST_WARN_EQUAL(reader->getActivity()->thread()->getPriority(), options_.ThreadPriority);
1126 for(
typename Writers::const_iterator writer = writers.begin(); writer != writers.end(); ++writer) {
1127 for(
typename Readers::const_iterator reader = readers.begin(); reader != readers.end(); ++reader) {
1135 for(
typename Writers::const_iterator task = writers.begin(); task != writers.end(); ++task) {
1136 (*task)->output_port.disconnect();
1138 for(
typename Readers::const_iterator task = readers.begin(); task != readers.end(); ++task) {
1139 (*task)->input_port.disconnect();
1146 for(
typename Writers::const_iterator task = writers.begin(); task != writers.end(); ++task) {
1147 if (!(*task)->isRunning()) {
1148 result = (*task)->start() && result;
1157 for(
typename Readers::const_iterator task = readers.begin(); task != readers.end(); ++task) {
1158 if (!(*task)->isRunning()) {
1159 result = (*task)->start() && result;
1166 return startWriters() && startReaders();
1170 for(
typename Tasks::const_iterator task = tasks.begin(); task != tasks.end(); ++task) {
1176 for(
typename Tasks::const_iterator task = tasks.begin(); task != tasks.end(); ++task) {
1177 (*task)->waitUntilFinished();
1182 if (!startAll())
return false;
1184 std::size_t cycle = 0;
1185 bool all_finished =
false;
1187 while(!all_finished && (options_.NumberOfCycles == 0 || cycle < options_.NumberOfCycles)) {
1189 all_finished =
true;
1191 for(
typename Tasks::const_iterator task = tasks.begin(); task != tasks.end(); ++task) {
1192 if (!(*task)->isRunning())
continue;
1194 if (!(*task)->finished()) all_finished =
false;
1204 Timer total_write_timer;
1205 std::map<WriteStatus, Timer> total_write_timer_by_status;
1208 std::cout <<
" Task #Cycles #Writes Total Average Max Total Average Max #Copies #Assign #WSuccess #WFailure " <<
std::endl;
1209 std::cout <<
"----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" <<
std::endl;
1210 for(
typename Writers::const_iterator task = writers.begin(); task != writers.end(); ++task) {
1212 <<
" " << std::setw(30) << (*task)->getName()
1213 <<
" " << std::setw(16) << (boost::lexical_cast<std::string>((*task)->getNumberOfCycles()) +
1214 ((*task)->getDesiredNumberOfCycles() ? (
"/" + boost::lexical_cast<std::string>((*task)->getDesiredNumberOfCycles())) :
""))
1215 <<
" " << std::setw(9) << (*task)->timer.count()
1216 <<
" " << std::setw(12) << (*task)->timer.total().monotonic
1217 <<
" " << std::setw(12) << ((*task)->timer.total().monotonic / (*task)->timer.count())
1218 <<
" " << std::setw(12) << (*task)->timer.max().monotonic
1219 <<
" " << std::setw(12) << (*task)->timer.total().cputime
1220 <<
" " << std::setw(12) << ((*task)->timer.total().cputime / (*task)->timer.count())
1221 <<
" " << std::setw(12) << (*task)->timer.max().cputime
1222 <<
" " << std::setw(9) << (*task)->sample.getCopyCount()
1223 <<
" " << std::setw(9) << (*task)->sample.getAssignmentCount()
1224 <<
" " << std::setw(9) << (*task)->timer_by_status[
WriteSuccess].count()
1225 <<
" " << std::setw(9) << (*task)->timer_by_status[
WriteFailure].count()
1229 <<
" " << std::setw(30) <<
" (WriteSuccess)" 1230 <<
" " << std::setw(16) <<
"" 1231 <<
" " << std::setw(9) << (*task)->timer_by_status[
WriteSuccess].count()
1232 <<
" " << std::setw(12) << (*task)->timer_by_status[
WriteSuccess].total().monotonic
1233 <<
" " << std::setw(12) << ((*task)->timer_by_status[
WriteSuccess].total().monotonic / (*task)->timer_by_status[
WriteSuccess].count())
1234 <<
" " << std::setw(12) << (*task)->timer_by_status[
WriteSuccess].max().monotonic
1235 <<
" " << std::setw(12) << (*task)->timer_by_status[
WriteSuccess].total().cputime
1236 <<
" " << std::setw(12) << ((*task)->timer_by_status[
WriteSuccess].total().cputime / (*task)->timer_by_status[
WriteSuccess].count())
1237 <<
" " << std::setw(12) << (*task)->timer_by_status[
WriteSuccess].max().cputime
1242 <<
" " << std::setw(30) <<
" (WriteFailure)" 1243 <<
" " << std::setw(16) <<
"" 1244 <<
" " << std::setw(9) << (*task)->timer_by_status[
WriteFailure].count()
1245 <<
" " << std::setw(12) << (*task)->timer_by_status[
WriteFailure].total().monotonic
1246 <<
" " << std::setw(12) << ((*task)->timer_by_status[
WriteFailure].total().monotonic / (*task)->timer_by_status[
WriteFailure].count())
1247 <<
" " << std::setw(12) << (*task)->timer_by_status[
WriteFailure].max().monotonic
1248 <<
" " << std::setw(12) << (*task)->timer_by_status[
WriteFailure].total().cputime
1249 <<
" " << std::setw(12) << ((*task)->timer_by_status[
WriteFailure].total().cputime / (*task)->timer_by_status[
WriteFailure].count())
1250 <<
" " << std::setw(12) << (*task)->timer_by_status[
WriteFailure].max().cputime
1254 total_write_timer += (*task)->timer;
1259 std::cout <<
"----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------" <<
std::endl;
1261 <<
" " << std::setw(30) <<
"Total" 1262 <<
" " << std::setw(16) <<
"" 1263 <<
" " << std::setw(9) << total_write_timer.
count()
1265 <<
" " << std::setw(12) << (total_write_timer.
total().
monotonic / total_write_timer.
count())
1266 <<
" " << std::setw(12) << total_write_timer.
max().
monotonic 1267 <<
" " << std::setw(12) << total_write_timer.
total().
cputime 1268 <<
" " << std::setw(12) << (total_write_timer.
total().
cputime / total_write_timer.
count())
1269 <<
" " << std::setw(12) << total_write_timer.
max().
cputime 1270 <<
" " << std::setw(9) <<
"" 1271 <<
" " << std::setw(9) <<
"" 1272 <<
" " << std::setw(9) << total_write_timer_by_status[
WriteSuccess].count()
1273 <<
" " << std::setw(9) << total_write_timer_by_status[
WriteFailure].count()
1276 <<
" " << std::setw(30) <<
"Average" 1277 <<
" " << std::setw(16) <<
"" 1278 <<
" " << std::setw(9) << total_write_timer.
count() / writers.size()
1279 <<
" " << std::setw(12) << total_write_timer.
total().
monotonic / writers.size()
1280 <<
" " << std::setw(12) << (total_write_timer.
total().
monotonic / total_write_timer.
count()) / writers.size()
1281 <<
" " << std::setw(12) << total_write_timer.
max().
monotonic / writers.size()
1282 <<
" " << std::setw(12) << total_write_timer.
total().
cputime / writers.size()
1283 <<
" " << std::setw(12) << (total_write_timer.
total().
cputime / total_write_timer.
count()) / writers.size()
1284 <<
" " << std::setw(12) << total_write_timer.
max().
cputime / writers.size()
1285 <<
" " << std::setw(9) <<
"" 1286 <<
" " << std::setw(9) <<
"" 1287 <<
" " << std::setw(9) << total_write_timer_by_status[
WriteSuccess].count() / writers.size()
1288 <<
" " << std::setw(9) << total_write_timer_by_status[
WriteFailure].count() / writers.size()
1292 Timer total_read_timer;
1293 std::map<FlowStatus, Timer> total_read_timer_by_status;
1296 std::cout <<
" Task #Cycles #Reads Total Average Max Total Average Max #NewData #OldData #NoData " <<
std::endl;
1297 std::cout <<
"---------------------------------------------------------------------------------------------------------------------------------------------------------------------" <<
std::endl;
1298 for(
typename Readers::const_iterator task = readers.begin(); task != readers.end(); ++task) {
1300 <<
" " << std::setw(30) << (*task)->getName()
1301 <<
" " << std::setw(16) << (boost::lexical_cast<std::string>((*task)->getNumberOfCycles()) +
1302 ((*task)->getDesiredNumberOfCycles() ? (
"/" + boost::lexical_cast<std::string>((*task)->getDesiredNumberOfCycles())) :
""))
1303 <<
" " << std::setw(9) << (*task)->timer.count()
1304 <<
" " << std::setw(12) << (*task)->timer.total().monotonic
1305 <<
" " << std::setw(12) << ((*task)->timer.total().monotonic / (*task)->timer.count())
1306 <<
" " << std::setw(12) << (*task)->timer.max().monotonic
1307 <<
" " << std::setw(12) << (*task)->timer.total().cputime
1308 <<
" " << std::setw(12) << ((*task)->timer.total().cputime / (*task)->timer.count())
1309 <<
" " << std::setw(12) << (*task)->timer.max().cputime
1310 <<
" " << std::setw(9) << (*task)->timer_by_status[
NewData].count()
1311 <<
" " << std::setw(9) << (*task)->timer_by_status[
OldData].count()
1312 <<
" " << std::setw(9) << (*task)->timer_by_status[
NoData].count()
1314 if ((*task)->timer_by_status[
NewData].count()) {
1316 <<
" " << std::setw(30) <<
" (NewData)" 1317 <<
" " << std::setw(16) <<
"" 1318 <<
" " << std::setw(9) << (*task)->timer_by_status[
NewData].count()
1319 <<
" " << std::setw(12) << (*task)->timer_by_status[
NewData].total().monotonic
1320 <<
" " << std::setw(12) << ((*task)->timer_by_status[
NewData].total().monotonic / (*task)->timer_by_status[
NewData].count())
1321 <<
" " << std::setw(12) << (*task)->timer_by_status[
NewData].max().monotonic
1322 <<
" " << std::setw(12) << (*task)->timer_by_status[
NewData].total().cputime
1323 <<
" " << std::setw(12) << ((*task)->timer_by_status[
NewData].total().cputime / (*task)->timer_by_status[
NewData].count())
1324 <<
" " << std::setw(12) << (*task)->timer_by_status[
NewData].max().cputime
1327 if ((*task)->timer_by_status[
OldData].count()) {
1329 <<
" " << std::setw(30) <<
" (OldData)" 1330 <<
" " << std::setw(16) <<
"" 1331 <<
" " << std::setw(9) << (*task)->timer_by_status[
OldData].count()
1332 <<
" " << std::setw(12) << (*task)->timer_by_status[
OldData].total().monotonic
1333 <<
" " << std::setw(12) << ((*task)->timer_by_status[
OldData].total().monotonic / (*task)->timer_by_status[
OldData].count())
1334 <<
" " << std::setw(12) << (*task)->timer_by_status[
OldData].max().monotonic
1335 <<
" " << std::setw(12) << (*task)->timer_by_status[
OldData].total().cputime
1336 <<
" " << std::setw(12) << ((*task)->timer_by_status[
OldData].total().cputime / (*task)->timer_by_status[
OldData].count())
1337 <<
" " << std::setw(12) << (*task)->timer_by_status[
OldData].max().cputime
1340 if ((*task)->timer_by_status[
NoData].count()) {
1342 <<
" " << std::setw(30) <<
" (NoData)" 1343 <<
" " << std::setw(16) <<
"" 1344 <<
" " << std::setw(9) << (*task)->timer_by_status[
NoData].count()
1345 <<
" " << std::setw(12) << (*task)->timer_by_status[
NoData].total().monotonic
1346 <<
" " << std::setw(12) << ((*task)->timer_by_status[
NoData].total().monotonic / (*task)->timer_by_status[
NoData].count())
1347 <<
" " << std::setw(12) << (*task)->timer_by_status[
NoData].max().monotonic
1348 <<
" " << std::setw(12) << (*task)->timer_by_status[
NoData].total().cputime
1349 <<
" " << std::setw(12) << ((*task)->timer_by_status[
NoData].total().cputime / (*task)->timer_by_status[
NoData].count())
1350 <<
" " << std::setw(12) << (*task)->timer_by_status[
NoData].max().cputime
1354 total_read_timer += (*task)->timer;
1355 total_read_timer_by_status[
NewData] += (*task)->timer_by_status[
NewData];
1356 total_read_timer_by_status[
OldData] += (*task)->timer_by_status[
OldData];
1357 total_read_timer_by_status[
NoData] += (*task)->timer_by_status[
NoData];
1359 std::cout <<
"---------------------------------------------------------------------------------------------------------------------------------------------------------------------" <<
std::endl;
1361 <<
" " << std::setw(30) <<
"Total" 1362 <<
" " << std::setw(16) <<
"" 1363 <<
" " << std::setw(9) << total_read_timer.
count()
1365 <<
" " << std::setw(12) << (total_read_timer.
total().
monotonic / total_read_timer.
count())
1366 <<
" " << std::setw(12) << total_read_timer.
max().
monotonic 1367 <<
" " << std::setw(12) << total_read_timer.
total().
cputime 1368 <<
" " << std::setw(12) << (total_read_timer.
total().
cputime / total_read_timer.
count())
1369 <<
" " << std::setw(12) << total_read_timer.
max().
cputime 1370 <<
" " << std::setw(9) << total_read_timer_by_status[
NewData].count()
1371 <<
" " << std::setw(9) << total_read_timer_by_status[
OldData].count()
1372 <<
" " << std::setw(9) << total_read_timer_by_status[
NoData].count()
1383 template <PortTypes PortType,
typename Enabled =
void>
1392 BOOST_CHECK( runner->connectAll() );
1393 BOOST_CHECK( runner->run() );
1395 runner->printStats();
1411 options.policy.size = 100;
1430 #if (RTT_VERSION_MAJOR >= 2) 1434 options.NumberOfWriters = 7;
1435 options.NumberOfReaders = 1;
1437 runner.reset(
new RunnerType(options));
1442 #if (RTT_VERSION_MAJOR == 1) || RTT_VERSION_GTE(2,8,99) 1446 options.NumberOfWriters = 7;
1447 options.NumberOfReaders = 1;
1449 runner.reset(
new RunnerType(options));
1454 #if (RTT_VERSION_MAJOR >= 2) 1458 options.NumberOfWriters = 1;
1459 options.NumberOfReaders = 7;
1461 runner.reset(
new RunnerType(options));
1466 #if (RTT_VERSION_MAJOR == 1) || RTT_VERSION_GTE(2,8,99) 1470 options.NumberOfWriters = 1;
1471 options.NumberOfReaders = 7;
1473 runner.reset(
new RunnerType(options));
1478 #if (RTT_VERSION_MAJOR >= 2) 1482 options.NumberOfWriters = 4;
1483 options.NumberOfReaders = 4;
1485 runner.reset(
new RunnerType(options));
1489 #if RTT_VERSION_GTE(2,8,99) 1493 options.NumberOfWriters = 4;
1494 options.NumberOfReaders = 4;
1496 runner.reset(
new RunnerType(options));
1503 options.NumberOfWriters = 4;
1504 options.NumberOfReaders = 4;
1506 runner.reset(
new RunnerType(options));
1512 #if (RTT_VERSION_MAJOR == 1) || RTT_VERSION_GTE(2,8,99) 1516 options.NumberOfWriters = 4;
1517 options.NumberOfReaders = 4;
1518 options.policy.buffer_policy =
Shared;
1519 runner.reset(
new RunnerType(options));
1530 #if (RTT_VERSION_MAJOR >= 2) 1534 options.NumberOfWriters = 7;
1535 options.NumberOfReaders = 1;
1537 runner.reset(
new RunnerType(options));
1540 BOOST_CHECK( runner->connectAll() );
1541 BOOST_CHECK( runner->run() );
1543 runner->printStats();
1548 #if (RTT_VERSION_MAJOR == 1) || RTT_VERSION_GTE(2,8,99) 1552 options.NumberOfWriters = 7;
1553 options.NumberOfReaders = 1;
1555 runner.reset(
new RunnerType(options));
1560 #if (RTT_VERSION_MAJOR >= 2) 1564 options.NumberOfWriters = 1;
1565 options.NumberOfReaders = 7;
1567 runner.reset(
new RunnerType(options));
1572 #if (RTT_VERSION_MAJOR == 1) || RTT_VERSION_GTE(2,8,99) 1576 options.NumberOfWriters = 1;
1577 options.NumberOfReaders = 7;
1579 runner.reset(
new RunnerType(options));
1584 #if (RTT_VERSION_MAJOR >= 2) 1588 options.NumberOfWriters = 4;
1589 options.NumberOfReaders = 4;
1591 runner.reset(
new RunnerType(options));
1595 #if RTT_VERSION_GTE(2,8,99) 1599 options.NumberOfWriters = 4;
1600 options.NumberOfReaders = 4;
1602 runner.reset(
new RunnerType(options));
1609 options.NumberOfWriters = 4;
1610 options.NumberOfReaders = 4;
1612 runner.reset(
new RunnerType(options));
1618 #if (RTT_VERSION_MAJOR == 1) || RTT_VERSION_GTE(2,8,99) 1622 options.NumberOfWriters = 4;
1623 options.NumberOfReaders = 4;
1624 options.policy.buffer_policy =
Shared;
1625 runner.reset(
new RunnerType(options));
1636 #if (RTT_VERSION_MAJOR >= 2) 1640 options.NumberOfWriters = 7;
1641 options.NumberOfReaders = 1;
1643 runner.reset(
new RunnerType(options));
1648 #if (RTT_VERSION_MAJOR == 1) || RTT_VERSION_GTE(2,8,99) 1652 options.NumberOfWriters = 7;
1653 options.NumberOfReaders = 1;
1654 options.policy.buffer_policy =
Shared;
1655 runner.reset(
new RunnerType(options));
void setDataSample(const T &sample)
std::size_t NumberOfCycles
boost::shared_ptr< Reader< T, PortType > > ReaderPtr
base::PortInterface & addPort(const std::string &name, base::PortInterface &port)
RTT::OutputPort< T > OutputPort
CopyAndAssignmentCounted< T > SampleType
static void setDataSample(OutputPort &port, const T &sample)
static WriteStatus write(OutputPort &port, const T &sample)
#define BOOST_FIXTURE_TEST_SUITE(suite_name, F)
std::size_t NumberOfReaders
std::size_t getNumberOfCycles()
void afterUpdateHook(bool trigger)
static FlowStatus read(InputPort &port, T &sample, bool copy_old_data=true)
std::size_t getDesiredNumberOfCycles()
AdaptorType::InputPort input_port
std::vector< ReaderPtr > Readers
#define BOOST_AUTO_TEST_CASE(test_name)
this_type & operator=(const value_type &)
int SleepUsecsDuringReadAssignment
boost::intrusive_ptr< CopyAndAssignmentCountedDetails > _counter_details
static const int CIRCULAR_BUFFER
base::InputPortInterface & addEventPort(const std::string &name, base::InputPortInterface &port, SlotFunction callback=SlotFunction())
static void addPort(TaskContext *tc, Port &port)
virtual os::ThreadInterface * thread()
CopyAndAssignmentCounted(const this_type &other)
AdaptorType::OutputPort output_port
#define BOOST_AUTO_TEST_SUITE_END()
const Data & total() const
void keepLastWrittenValue(bool keep)
CopyAndAssignmentCounted(const value_type &value)
A class for running a certain piece of code in a thread.
ConnPolicy & operator==(const RTT::ConnPolicy &other)
this_type & operator=(const this_type &other)
int usleep(unsigned int us)
virtual RTOS_TASK * getTask()=0
Timer & operator+=(const Timer &other)
boost::shared_ptr< ReaderWriterTaskContextBase > TaskPtr
virtual bool setCpuAffinity(unsigned cpu_affinity)
~ReaderWriterTaskContextBase()
An object oriented wrapper around a condition variable.
CopyAndAssignmentCounted()
virtual bool createConnection(internal::SharedConnectionBase::shared_ptr shared_connection, ConnPolicy const &policy=ConnPolicy())=0
base::InputPortInterface & addEventPort(const std::string &name, base::InputPortInterface &port, SlotFunction callback=SlotFunction())
RTT::base::PortInterface Port
std::vector< TaskPtr > Tasks
CopyAndAssignmentCounted< T > SampleType
TestRunner< T, PortType > TestRunnerType
int oro_atomic_read(oro_atomic_t *a)
int SleepUsecsDuringWriteAssignment
const std::string & getName() const
Data & operator+=(const Data &other)
Timer & updateFrom(const Timer &other)
const int HighestPriority
std::map< FlowStatus, Timer > timer_by_status
CopyAndAssignmentCounted< T > SampleType
std::string exception_reason_
DataFlowInterface * ports()
std::map< WriteStatus, Timer > timer_by_status
oro_atomic_t _write_guard
std::size_t count() const
void oro_atomic_inc(oro_atomic_t *a)
std::size_t NumberOfWriters
static RTT_UNUSED bool setCpuAffinity(ThreadInterface *thread, const std::bitset< 16 > &cpu_affinity)
std::vector< WriterPtr > Writers
base::PortInterface & addPort(const std::string &name, base::PortInterface &port)
~CopyAndAssignmentCounted()
void ORO_ATOMIC_SETUP(oro_atomic_t *a, int n)
std::size_t number_of_cycles_
TestRunner(const TestOptions &options)
virtual bool connectTo(PortInterface *other, ConnPolicy const &policy)
const Data & last() const
void ORO_ATOMIC_CLEANUP(oro_atomic_t *a)
WriteStatus write(const T &sample)
Adaptor< SampleType, PortType > AdaptorType
virtual unsigned getCpuAffinity() const
std::bitset< 16 > CpuAffinity
const TestOptions & getOptions() const
basic_ostreams & endl(basic_ostreams &s)
static const int LOCK_FREE
virtual bool connected() const
An Activity executes a RunnableInterface object in a (periodic) thread.
enum TestOptions::@8 WriteMode
enum TestOptions::@9 ReadMode
int oro_atomic_dec_and_test(oro_atomic_t *a)
ConnPolicy(int type, int lock_policy)
static std::bitset< 16 > getDefaultCpuAffinity()
static void yield(TaskContext *tc)
Timer & operator+=(const Data &other)
static int clock_gettime(int clk_id, struct timespec *tp)
virtual os::ThreadInterface * thread()=0
void oro_atomic_set(oro_atomic_t *a, int n)
static void addEventPort(TaskContext *tc, InputPort &port)
Writer(const std::string &name, std::size_t index, std::size_t sample_size=1, bool keep_last_written_value=false)
CopyAndAssignmentCountedDetails()
static std::bitset< 16 > getCpuAffinity(ThreadInterface *thread)
Timer(const std::string &name="")
An object oriented wrapper around a non recursive mutex.
boost::shared_ptr< Writer< T, PortType > > WriterPtr
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
ReaderWriterTaskContextBase(const std::string &name, std::size_t index=0)
Reader(const std::string &name, std::size_t index, bool read_loop, bool copy_old_data)
bool KeepLastWrittenValue
Adaptor< SampleType, PortType > AdaptorType
ReaderWriterTaskContextBase & setDesiredNumberOfCycles(std::size_t n)
CopyAndAssignmentCounted< Derived > this_type
std::size_t desired_number_of_cycles_
this_type detachedCopy() const
int sleep_usecs_during_assignment
void oro_atomic_dec(oro_atomic_t *a)
static bool connect(OutputPort &output_port, InputPort &input_port, const ConnPolicy &cp)
base::ActivityInterface * getActivity()
static const int UNBUFFERED
static bool update(TaskContext *tc)
boost::shared_ptr< TestRunnerType > shared_ptr
RTT::InputPort< T > InputPort
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...
static bool trigger(TaskContext *tc)