debug-real-time-tracer.cpp
Go to the documentation of this file.
1 /* Copyright 2019, LAAS-CNRS
2  *
3  * Olivier Stasse
4  *
5  */
6 
8 #include <dynamic-graph/entity.h>
10 #include <dynamic-graph/factory.h>
11 #include <dynamic-graph/pool.h>
15 
16 #include <iostream>
17 #define BOOST_TEST_MODULE debug - tracer
18 
19 #if BOOST_VERSION >= 105900
20 #include <boost/test/tools/output_test_stream.hpp>
21 #else
22 #include <boost/test/output_test_stream.hpp>
23 #endif
24 #include <boost/test/unit_test.hpp>
25 using boost::test_tools::output_test_stream;
26 
27 namespace dynamicgraph {
28 struct MyEntity : public dynamicgraph::Entity {
29  static const std::string CLASS_NAME;
30 
34 
35  explicit MyEntity(const std::string &name)
36  : Entity(name),
37  m_sigdSIN("MyEntity(" + name + ")::input(double)::in_double"),
38  m_sigdTimeDepSOUT(boost::bind(&MyEntity::update, this, _1, _2),
39  m_sigdSIN,
40  "MyEntity(" + name + ")::input(double)::out_double"),
42  boost::bind(&MyEntity::update, this, _1, _2), m_sigdSIN,
43  "MyEntity(" + name + ")::input(double)::out2double")
44 
45  {
47  }
48 
49  double &update(double &res, const sigtime_t &inTime) {
50  const double &aDouble = m_sigdSIN(inTime);
51  res = aDouble;
52  return res;
53  }
54 };
56 } // namespace dynamicgraph
57 
58 BOOST_AUTO_TEST_CASE(test_tracer) {
59  using namespace dynamicgraph;
60 
61  // Creates a tracer.
62  TracerRealTime &atracer = *dynamic_cast<TracerRealTime *>(
63  FactoryStorage::getInstance()->newEntity("TracerRealTime", "my-tracer"));
64 
65  MyEntity &entity = *dynamic_cast<MyEntity *>(
66  FactoryStorage::getInstance()->newEntity("MyEntity", "my-entity"));
67 
68  std::string rootdir("/tmp");
69  std::string basename("my-tracer");
70  std::string suffix(".dat");
71 
72  atracer.setBufferSize(1 << 14);
73 
74  // Check that an exception is thrown if the filename is invalid.
75  atracer.openFiles(rootdir, "invalid/filename", suffix);
76  BOOST_CHECK_THROW(
77  atracer.addSignalToTraceByName("my-entity.out_double", "output"),
79 
80  // Test openfiles
81  atracer.openFiles(rootdir, basename, suffix);
82  // Add trace by name
83  atracer.addSignalToTraceByName("my-entity.out_double", "output");
84 
86  SignalBase<sigtime_t> &out_double = entity.getSignal("out_double");
87  SignalBase<sigtime_t> &out_double_2 = entity.getSignal("out2double");
88 
89  Signal<double, sigtime_t> &in_double =
90  *(dynamic_cast<Signal<double, sigtime_t> *>(
91  &entity.getSignal("in_double")));
92 
93  in_double.setConstant(1.5);
94  atracer.start();
95 
96  std::string emptybuf_cmd_str("empty");
97  command::Command *acmd = atracer.getNewStyleCommand(emptybuf_cmd_str);
98  acmd->execute();
99  for (sigtime_t i = 0; i < 1000; i++) {
100  in_double.setTime(i);
101  out_double.recompute(i);
102  out_double_2.recompute(i);
103  atracer.recordTrigger(i, i);
104  }
105  output_test_stream output;
106 
107  atracer.display(output);
108 
109  atracer.stop();
110  atracer.trace();
111  atracer.clearSignalToTrace();
112  atracer.closeFiles();
113  acmd->execute();
114  atracer.record();
115 
116  BOOST_CHECK(output.is_equal(
117  "TracerRealTime my-tracer [mode=play] : \n"
118  " - Dep list: \n"
119  " -> MyEntity(my-entity)::input(double)::out_double (in output)"
120  " [8Ko/16Ko] \n"));
121 }
entity.h
dynamicgraph::Signal< double, sigtime_t >
signal-time-dependent.h
dynamicgraph::SignalBase::recompute
virtual void recompute(const Time &)
Definition: signal-base.h:135
dynamicgraph::Tracer::recordTrigger
sigtime_t & recordTrigger(sigtime_t &dummy, const sigtime_t &time)
Definition: tracer.cpp:251
dynamicgraph::Tracer::addSignalToTraceByName
void addSignalToTraceByName(const std::string &signame, const std::string &filename="")
Definition: tracer.cpp:111
dynamicgraph
dynamicgraph::MyEntity::update
double & update(double &res, const sigtime_t &inTime)
Definition: debug-real-time-tracer.cpp:49
dynamicgraph::Entity
This class represents an entity, i.e. a generic computational unit that provides input and output sig...
Definition: include/dynamic-graph/entity.h:52
dynamicgraph::Tracer::record
void record()
Definition: tracer.cpp:198
dynamicgraph::MyEntity
Definition: debug-real-time-tracer.cpp:28
dynamicgraph::Tracer::stop
void stop()
Definition: tracer.h:89
dynamicgraph::DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity")
dynamicgraph::Entity::name
std::string name
Definition: include/dynamic-graph/entity.h:174
dynamicgraph::MyEntity::m_sigdTwoTimeDepSOUT
dynamicgraph::SignalTimeDependent< double, sigtime_t > m_sigdTwoTimeDepSOUT
Definition: debug-real-time-tracer.cpp:33
dynamicgraph::Tracer::clearSignalToTrace
void clearSignalToTrace()
Definition: tracer.cpp:124
dynamicgraph::TracerRealTime::setBufferSize
void setBufferSize(const int &SIZE)
Definition: tracer-real-time.h:55
signal-ptr.h
command.h
dynamicgraph::MyEntity::CLASS_NAME
static const std::string CLASS_NAME
Definition: debug-real-time-tracer.cpp:29
tracer-real-time.h
dynamicgraph::MyEntity::m_sigdTimeDepSOUT
dynamicgraph::SignalTimeDependent< double, sigtime_t > m_sigdTimeDepSOUT
Definition: debug-real-time-tracer.cpp:32
dynamicgraph::sigtime_t
int64_t sigtime_t
Definition: fwd.hh:12
dynamicgraph::MyEntity::MyEntity
MyEntity(const std::string &name)
Definition: debug-real-time-tracer.cpp:35
dynamicgraph::TracerRealTime::closeFiles
virtual void closeFiles()
Definition: tracer-real-time.cpp:147
dynamicgraph::command::Command
Definition: command.h:35
dynamicgraph::Entity::getNewStyleCommand
command::Command * getNewStyleCommand(const std::string &cmdName)
Provides the pointer towards the Command object cmdName.
Definition: src/dgraph/entity.cpp:206
dynamicgraph::MyEntity::m_sigdSIN
dynamicgraph::Signal< double, sigtime_t > m_sigdSIN
Definition: debug-real-time-tracer.cpp:31
dynamicgraph::Signal::setConstant
virtual void setConstant(const T &t)
Definition: signal.t.cpp:98
exception-factory.h
factory.h
dynamicgraph::SignalTimeDependent< double, sigtime_t >
dynamicgraph::Entity::getSignal
SignalBase< sigtime_t > & getSignal(const std::string &signalName)
Provides a reference to the signal named signalName.
dynamicgraph::command::Command::execute
Value execute()
Execute the command after checking parameters.
Definition: command.cpp:52
dynamicgraph::TracerRealTime::display
void display(std::ostream &os) const
Display information on the entity inside the output stream os.
Definition: tracer-real-time.cpp:261
MyEntity
Definition: tests/pool.cpp:26
dynamicgraph::SignalBase< sigtime_t >
dynamicgraph::Tracer::start
void start()
Definition: tracer.h:88
dynamicgraph::TracerRealTime::trace
virtual void trace()
Definition: tracer-real-time.cpp:176
dynamicgraph::Entity::signalRegistration
void signalRegistration(const SignalArray< sigtime_t > &signals)
Definition: src/dgraph/entity.cpp:59
dynamicgraph::ExceptionTraces
Exceptions raised when an error related to traces happen.
Definition: exception-traces.h:18
dynamicgraph::TracerRealTime
Main class of the tracer real-time plug-in.
Definition: tracer-real-time.h:39
dynamicgraph::Tracer::openFiles
void openFiles(const std::string &rootdir, const std::string &basename, const std::string &suffix)
Definition: tracer.cpp:136
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_tracer)
Definition: debug-real-time-tracer.cpp:58
dynamicgraph::FactoryStorage::newEntity
Entity * newEntity(const std::string &classname, const std::string &objname) const
Instantiate (and allocate) an entity.
Definition: src/dgraph/factory.cpp:79
pool.h
dynamicgraph::FactoryStorage::getInstance
static FactoryStorage * getInstance()
Get pointer to unique object of the class.
Definition: src/dgraph/factory.cpp:15


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Fri Aug 2 2024 08:36:38