GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/dynamic-graph/tracer.h Lines: 2 4 50.0 %
Date: 2023-03-15 12:04:10 Branches: 0 0 - %

Line Branch Exec Source
1
// -*- mode: c++ -*-
2
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
3
// JRL, CNRS/AIST.
4
//
5
6
#ifndef DYNAMIC_GRAPH_TRACER_H
7
#define DYNAMIC_GRAPH_TRACER_H
8
#include <dynamic-graph/entity.h>
9
#include <dynamic-graph/exception-traces.h>
10
#include <dynamic-graph/signal-base.h>
11
#include <dynamic-graph/signal-time-dependent.h>
12
#include <dynamic-graph/time-dependency.h>
13
14
#include <boost/function.hpp>
15
#include <dynamic-graph/config-tracer.hh>
16
#include <list>
17
#include <mutex>
18
#include <string>
19
20
namespace dynamicgraph {
21
/// \ingroup plugin
22
///
23
/// \brief Tracer plug-in main class.
24
class DG_TRACER_DLLAPI Tracer : public Entity {
25
  DYNAMIC_GRAPH_ENTITY_DECL();
26
27
 protected:
28
  typedef std::list<const SignalBase<int> *> SignalList;
29
  SignalList toTraceSignals;
30
  std::mutex files_mtx;
31
32
 public:
33
  enum TraceStyle {
34
    WHEN_SAID
35
    /// Record, then trace to file only when said to.
36
    ,
37
    EACH_TIME
38
    /// Record and trace to file immediately.
39
    ,
40
    FREQUENTLY
41
    /// Record X time then trace (X is tuned by setFrenquence () ).
42
  };
43
  TraceStyle traceStyle;
44
  static const TraceStyle TRACE_STYLE_DEFAULT = EACH_TIME;
45
  double frequency;
46
47
  std::string basename;
48
  std::string suffix;
49
  std::string rootdir;
50
  bool namesSet;
51
  typedef std::list<std::ostream *> FileList;
52
  FileList files;
53
  typedef std::list<std::string> NameList;
54
  NameList names;
55
  bool play;
56
  int timeStart;
57
58
 public:
59
  Tracer(const std::string n);
60
  virtual ~Tracer() { closeFiles(); }
61
62
  void addSignalToTrace(const SignalBase<int> &sig,
63
                        const std::string &filename = "");
64
  void addSignalToTraceByName(const std::string &signame,
65
                              const std::string &filename = "");
66
  void clearSignalToTrace();
67
  // void parasite( SignalBase<int>& sig );
68
  void openFiles(const std::string &rootdir, const std::string &basename,
69
                 const std::string &suffix);
70
  virtual void closeFiles();
71
72
 protected:
73
  virtual void openFile(const SignalBase<int> &sig,
74
                        const std::string &filename);
75
76
 public:
77
  void setTraceStyle(const TraceStyle &style) { traceStyle = style; }
78
  TraceStyle getTraceStyle() { return traceStyle; }
79
80
  void setFrenquency(const double &frqu) { frequency = frqu; }
81
  double getFrequency() { return frequency; }
82
83
  void record();
84
  virtual void recordSignal(std::ostream &os, const SignalBase<int> &sig);
85
  int &recordTrigger(int &dummy, const int &time);
86
87
  virtual void trace();
88
2
  void start() { play = true; }
89
2
  void stop() { play = false; }
90
91
 public:
92
  // SignalTrigerer<int> triger;
93
  SignalTimeDependent<int, int> triger;
94
95
  /* --- DISPLAY --------------------------------------------------------- */
96
  DG_TRACER_DLLAPI friend std::ostream &operator<<(std::ostream &os,
97
                                                   const Tracer &t);
98
99
  /* --- PARAMS --- */
100
  void display(std::ostream &os) const;
101
};
102
103
}  // end of namespace dynamicgraph
104
105
#endif  //! DYNAMIC_GRAPH_TRACER_H