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"),
41  m_sigdTwoTimeDepSOUT(
42  boost::bind(&MyEntity::update, this, _1, _2), m_sigdSIN,
43  "MyEntity(" + name + ")::input(double)::out2double")
44 
45  {
46  signalRegistration(m_sigdSIN << m_sigdTimeDepSOUT << m_sigdTwoTimeDepSOUT);
47  }
48 
49  double &update(double &res, const int &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<int> &out_double = entity.getSignal("out_double");
87  SignalBase<int> &out_double_2 = entity.getSignal("out2double");
88 
89  Signal<double, int> &in_double =
90  *(dynamic_cast<Signal<double, int> *>(&entity.getSignal("in_double")));
91 
92  in_double.setConstant(1.5);
93  atracer.start();
94 
95  std::string emptybuf_cmd_str("empty");
96  command::Command *acmd = atracer.getNewStyleCommand(emptybuf_cmd_str);
97  acmd->execute();
98  for (int i = 0; i < 1000; i++) {
99  in_double.setTime(i);
100  out_double.recompute(i);
101  out_double_2.recompute(i);
102  atracer.recordTrigger(i, i);
103  }
104  output_test_stream output;
105 
106  atracer.display(output);
107 
108  atracer.stop();
109  atracer.trace();
110  atracer.clearSignalToTrace();
111  atracer.closeFiles();
112  acmd->execute();
113  atracer.record();
114 
115  BOOST_CHECK(output.is_equal(
116  "TracerRealTime my-tracer [mode=play] : \n"
117  " - Dep list: \n"
118  " -> MyEntity(my-entity)::input(double)::out_double (in output)"
119  " [8Ko/16Ko] \n"));
120 }
dynamicgraph::SignalTimeDependent< double, int > m_sigdTimeDepSOUT
This class represents an entity, i.e. a generic computational unit that provides input and output sig...
virtual void recompute(const Time &)
Definition: signal-base.h:135
void signalRegistration(const SignalArray< int > &signals)
void openFiles(const std::string &rootdir, const std::string &basename, const std::string &suffix)
Definition: tracer.cpp:136
command::Command * getNewStyleCommand(const std::string &cmdName)
Provides the pointer towards the Command object cmdName.
void addSignalToTraceByName(const std::string &signame, const std::string &filename="")
Definition: tracer.cpp:111
virtual void setConstant(const T &t)
Definition: signal.t.cpp:98
MyEntity(const std::string &name)
Main class of the tracer real-time plug-in.
int & recordTrigger(int &dummy, const int &time)
Definition: tracer.cpp:250
void clearSignalToTrace()
Definition: tracer.cpp:124
BOOST_AUTO_TEST_CASE(test_tracer)
Value execute()
Execute the command after checking parameters.
Definition: command.cpp:52
dynamicgraph::SignalTimeDependent< double, int > m_sigdTwoTimeDepSOUT
void display(std::ostream &os) const
Display information on the entity inside the output stream os.
double & update(double &res, const int &inTime)
Entity * newEntity(const std::string &classname, const std::string &objname) const
Instantiate (and allocate) an entity.
static FactoryStorage * getInstance()
Get pointer to unique object of the class.
void setBufferSize(const int &SIZE)
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(CustomEntity, "CustomEntity")
SignalBase< int > & getSignal(const std::string &signalName)
Provides a reference to the signal named signalName.
Exceptions raised when an error related to traces happen.
static const std::string CLASS_NAME
virtual void setTime(const Time &t)
Definition: signal-base.h:38
dynamicgraph::Signal< double, int > m_sigdSIN


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Jun 25 2023 02:06:03