+ // If we are using a trace file, then open the file,
+ if (params->trace_file != "") {
+ // If the trace file is not specified as an absolute path,
+ // append the current simulation output directory
+ std::string filename = simout.resolve(params->trace_file);
+ traceStream = new ProtoOutputStream(filename);
+
+ // Create a protobuf message for the header and write it to
+ // the stream
+ Message::PacketHeader header_msg;
+ header_msg.set_obj_id(name());
+ header_msg.set_tick_freq(SimClock::Frequency);
+ traceStream->write(header_msg);
+
+ // Register a callback to compensate for the destructor not
+ // being called. The callback forces the stream to flush and
+ // closes the output file.
+ Callback* cb = new MakeCallback<CommMonitor,
+ &CommMonitor::closeStreams>(this);
+ registerExitCallback(cb);
+ }
+