TraceWriter
class TraceWriter
Base interface for all trace format writers. Provides common operations for writing signals and trace data.
Functions
| Name | Description |
|---|---|
| set_format_version | Set the format version for the output file. |
| set_time_scale | Set the time scale for timestamp values. |
| set_time_base | Set the time base for calculations. |
| add_signal | Add a signal to the trace. |
| add_hierarchical_signal | Add a hierarchical signal (with scope path). |
| write_value | Write a signal value at a specific time index. |
| write_values | Write multiple signal values at the same time index. |
| begin_transaction | Begin a transaction for batch operations. |
| commit_transaction | Commit the current transaction. |
| rollback_transaction | Rollback the current transaction. |
| finalize | Finalize and close the trace file. |
| flush | Flush buffered data to disk without finalizing. |
| signal_count | Get the number of signals currently defined. |
| has_signal | Check if a signal has been defined. |
| signal_width | Get the width of a defined signal. |
| get_all_signals | Get all defined signal names. |
| get_statistics | Get write statistics. |
Function Details
add_hierarchical_signal
virtual void add_hierarchical_signal( const std::string& hierarchy, const std::string& name, size_t width, const std::string& type = "wire" ) = 0
Add a hierarchical signal (with scope path).
-
hierarchy - Dot-separated scope path (e.g., "top.cpu.alu")
-
name - Signal name within the hierarchy
-
width - Bit width of the signal
-
type - Signal type (default: "wire")
add_signal
virtual void add_signal( const std::string& name, size_t width, const std::string& type = "wire" ) = 0
Add a signal to the trace.
-
name - Signal name
-
width - Bit width of the signal
-
type - Signal type (default: "wire")
begin_transaction
virtual void begin_transaction() = 0
Begin a transaction for batch operations. Useful for grouping multiple writes for efficiency.
All writes after this are buffered until commit or rollback.
commit_transaction
virtual void commit_transaction() = 0
Commit the current transaction. Flushes all buffered writes to the file.
finalize
virtual void finalize() = 0
Finalize and close the trace file. Must be called before the writer is destroyed. Subsequent writes will fail.
flush
virtual void flush() = 0
Flush buffered data to disk without finalizing. Useful for periodic checkpoints in long-running operations.
get_all_signals
virtual std::vector<std::string> get_all_signals() const = 0
Get all defined signal names.
- Return
- Vector of signal names
get_statistics
virtual std::map<std::string, int64_t> get_statistics() const = 0
Get write statistics.
- Return
- Map with keys: - "signals_written": Number of signal values written - "transactions": Number of committed transactions - "bytes_written": Bytes written to file
has_signal
virtual bool has_signal(const std::string& signal_name) const = 0
Check if a signal has been defined.
-
signal_name - Name of the signal
- Return
- true if signal exists, false otherwise
rollback_transaction
virtual void rollback_transaction() = 0
Rollback the current transaction. Discards all buffered writes since begin_transaction().
set_format_version
virtual void set_format_version(int major, int minor) = 0
Set the format version for the output file.
-
major - Major version number
-
minor - Minor version number
set_time_base
virtual void set_time_base(uint64_t base) = 0
Set the time base for calculations.
-
base - Time base (typically 1)
set_time_scale
virtual void set_time_scale(const std::string& scale) = 0
Set the time scale for timestamp values.
-
scale - Time scale ("ps", "ns", "us", "ms", "s")
signal_count
virtual size_t signal_count() const = 0
Get the number of signals currently defined.
- Return
- Number of signals
signal_width
virtual size_t signal_width(const std::string& signal_name) const = 0
Get the width of a defined signal.
-
signal_name - Name of the signal
- Return
- Signal width in bits @throws std::runtime_error if signal not found
write_value
virtual void write_value( const std::string& signal_name, uint64_t time_index, const std::string& value ) = 0
Write a signal value at a specific time index.
-
signal_name - Name of the signal
-
time_index - Time index for this value
-
value - Signal value as string (binary, hex, or decimal) @throws std::runtime_error if signal not found
write_values
virtual void write_values( uint64_t time_index, const std::map<std::string, std::string>& values ) = 0
Write multiple signal values at the same time index.
-
time_index - Time index for all values
-
values - Map of signal_name → value @throws std::runtime_error if any signal not found