SystemC  2.3.2
Accellera SystemC proof-of-concept library
sc_trace_file_base.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements. See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License. You may obtain a copy of the License at
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied. See the License for the specific language governing
16  permissions and limitations under the License.
17 
18  *****************************************************************************/
19 
20 /*****************************************************************************
21 
22  sc_trace_file_base.h - Shared internal tracing implementation
23 
24  Original Author: Philipp A. Hartmann, OFFIS, 2013-11-15
25 
26  CHANGE LOG AT END OF FILE
27  *****************************************************************************/
28 
29 /*****************************************************************************
30 
31  Acknowledgement: The tracing mechanism is based on the tracing
32  mechanism developed at Infineon (formerly Siemens HL). Though this
33  code is somewhat different, and significantly enhanced, the basics
34  are identical to what was originally contributed by Infineon. The
35  contribution of Infineon in the development of this tracing
36  technology is hereby acknowledged.
37 
38  *****************************************************************************/
39 
40 #ifndef SC_TRACE_FILE_BASE_H_INCLUDED_
41 #define SC_TRACE_FILE_BASE_H_INCLUDED_
42 
43 #include <cstdio>
44 
45 // use callback-based tracing implementation
46 #if defined( SC_ENABLE_SIMULATION_PHASE_CALLBACKS_TRACING )
47 # define SC_TRACING_PHASE_CALLBACKS_ 1
48 # include "sysc/kernel/sc_object.h"
49 #else
50 # define SC_TRACING_PHASE_CALLBACKS_ 0
51 #endif
52 
53 #include "sysc/tracing/sc_trace.h"
55 
56 #if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
57 #pragma warning(push)
58 #pragma warning(disable: 4251) // DLL import for std::string
59 #endif
60 
61 namespace sc_core {
62 
63 // shared implementation of trace files
65  : public sc_trace_file
66 #if SC_TRACING_PHASE_CALLBACKS_
67  , private sc_object // to be used as callback target
68 #endif
69 {
70 public:
72 
73  const char* filename() const
74  { return filename_.c_str(); }
75 
76  bool delta_cycles() const
77  { return trace_delta_cycles_; }
78 
79  // Also trace transitions between delta cycles if flag is true.
80  virtual void delta_cycles(bool flag);
81 
82  // set a user-define timescale unit for the trace file
83  virtual void set_time_unit( double v, sc_time_unit tu);
84 
85 protected:
86  sc_trace_file_base( const char* name, const char* extension );
87 
88  // returns true, iff initialization has been performed
89  bool initialize();
90  // ensure that file has been opened (needed for early write_comment())
91  void open_fp();
92  // perform format specific initialization
93  virtual void do_initialize() = 0;
94 
95  // returns true, if new trace objects can still be added
96  // (i.e. trace file is not yet initialized)
97  bool add_trace_check( const std::string& name ) const;
98 
99  // tracefile time unit < kernel unit, extra units will be placed in low part
100  bool has_low_units() const;
101 
102  // number of decimal digits in low units
103  int low_units_len() const;
104 
105  // get current kernel time in trace time units
106  void timestamp_in_trace_units(unit_type &high, unit_type &low) const;
107 
108  // Flush results and close file.
109  virtual ~sc_trace_file_base();
110 
111  static sc_time::value_type unit_to_fs(sc_time_unit tu);
112 
113  static std::string fs_unit_to_str(sc_trace_file_base::unit_type tu);
114 
115 #if SC_TRACING_PHASE_CALLBACKS_
116 private:
117  virtual void simulation_phase_callback();
118 #endif // SC_TRACING_PHASE_CALLBACKS_
119 
120 protected:
121  FILE* fp; // pointer to the trace file
122 
123  unit_type trace_unit_fs; // tracefile timescale unit in femtoseconds
124  unit_type kernel_unit_fs; // kernel timescale unit in femtoseconds
125  bool timescale_set_by_user; // = true means set by user
126 
127 private:
128  std::string filename_; // name of the file (for reporting)
129  bool initialized_; // tracing started?
130  bool trace_delta_cycles_; // also trace delta transitions?
131 
132  static bool tracing_initialized_; // shared setup of tracing implementation
133 
134 private: // disabled
135  sc_trace_file_base( const sc_trace_file_base& ) /* = delete */;
136  sc_trace_file_base& operator=( const sc_trace_file_base& ) /* = delete */;
137 
138 }; // class sc_trace_file_base
139 
140 // -----------------------------------------------------------------------
141 
142 
143 // obtain formatted time string
144 SC_API std::string localtime_string();
145 
146 } // namespace sc_core
147 
148 #if defined(_MSC_VER) && !defined(SC_WIN_DLL_WARN)
149 #pragma warning(pop)
150 #endif
151 
152 /*****************************************************************************
153 
154  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
155  changes you are making here.
156 
157  Name, Affiliation, Date:
158  Description of Modification:
159 
160  *****************************************************************************/
161 
162 #endif // SC_TRACE_FILE_BASE_H_INCLUDED_
163 // Taf!
sc_time::value_type unit_type
SC_API std::string localtime_string()
Abstract base class of all SystemC `simulation&#39; objects.
Definition: sc_object.h:61
Report ids for the tracing code.
sc_dt::uint64 value_type
Definition: sc_time.h:86
const char * filename() const
Abstract base class of all SystemC `simulation&#39; objects.
class SC_API sc_trace_file_base
Definition: sc_object.h:53
#define SC_API
Definition: sc_cmnhdr.h:168
sc_time_unit
Enumeration of time units.
Definition: sc_time.h:64