summaryrefslogtreecommitdiff
path: root/src/cpu/testers/traffic_gen/traffic_gen.cc
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2013-01-07 13:05:37 -0500
committerAndreas Hansson <andreas.hansson@arm.com>2013-01-07 13:05:37 -0500
commit1da209140cd7bf267315b10698bf14c21a76b1b8 (patch)
treefdfc048fe02cdd6862a21361484e75c97fca4366 /src/cpu/testers/traffic_gen/traffic_gen.cc
parent9c5ef235cc595d0f51b0810786c2b512bef7c69f (diff)
downloadgem5-1da209140cd7bf267315b10698bf14c21a76b1b8.tar.xz
cpu: Add support for protobuf input for the trace generator
This patch adds support for reading input traces encoded using protobuf according to what is done in the CommMonitor. A follow-up patch adds a Python script that can be used to convert the previously used ASCII traces to protobuf equivalents. The appropriate regression input is updated as part of this patch.
Diffstat (limited to 'src/cpu/testers/traffic_gen/traffic_gen.cc')
-rw-r--r--src/cpu/testers/traffic_gen/traffic_gen.cc65
1 files changed, 18 insertions, 47 deletions
diff --git a/src/cpu/testers/traffic_gen/traffic_gen.cc b/src/cpu/testers/traffic_gen/traffic_gen.cc
index 4617f5c81..05e5d0d3b 100644
--- a/src/cpu/testers/traffic_gen/traffic_gen.cc
+++ b/src/cpu/testers/traffic_gen/traffic_gen.cc
@@ -45,6 +45,7 @@
#include "cpu/testers/traffic_gen/traffic_gen.hh"
#include "debug/Checkpoint.hh"
#include "debug/TrafficGen.hh"
+#include "proto/packet.pb.h"
#include "sim/stats.hh"
#include "sim/system.hh"
@@ -497,65 +498,35 @@ TrafficGen::StateGraph::RandomGen::nextExecuteTick()
TrafficGen::StateGraph::TraceGen::InputStream::InputStream(const string&
filename)
+ : trace(filename)
{
- trace.rdbuf()->pubsetbuf(readBuffer, 4 * 1024 * 1024);
- trace.open(filename.c_str(), ifstream::in);
-
- if (!trace.is_open()) {
- fatal("Traffic generator trace file could not be"
- " opened: %s\n", filename);
+ // Create a protobuf message for the header and read it from the stream
+ Message::PacketHeader header_msg;
+ if (!trace.read(header_msg)) {
+ panic("Failed to read packet header from %s\n", filename);
+
+ if (header_msg.tick_freq() != SimClock::Frequency) {
+ panic("Trace %s was recorded with a different tick frequency %d\n",
+ header_msg.tick_freq());
+ }
}
}
void
TrafficGen::StateGraph::TraceGen::InputStream::reset()
{
- // seek to the start of the input trace file
- trace.seekg(0, ifstream::beg);
- trace.clear();
+ trace.reset();
}
bool
TrafficGen::StateGraph::TraceGen::InputStream::read(TraceElement& element)
{
- string buffer;
- bool format_error = false;
- assert(trace.good());
- getline(trace, buffer);
-
- // Check that we have something to process. This assumes no EOF at
- // the end of the line.
- if (buffer.size() > 0 && !trace.eof()) {
- std::istringstream iss(buffer);
-
- char rOrW, ch;
- iss >> rOrW;
- if (rOrW == 'r') {
- element.cmd = MemCmd::ReadReq;
- } else if (rOrW == 'w') {
- element.cmd = MemCmd::WriteReq;
- } else {
- format_error = true;
- }
-
- // eat a comma, then get the address
- iss >> ch;
- format_error |= ch != ',';
- iss >> element.addr;
-
- // eat a comma, then get the blocksize
- iss >> ch;
- format_error |= ch != ',';
- iss >> element.blocksize;
-
- // eat a comma, then get the tick
- iss >> ch;
- format_error |= ch != ',';
- iss >> element.tick;
-
- if (format_error)
- fatal("Trace format error in %s\n", buffer);
-
+ Message::Packet pkt_msg;
+ if (trace.read(pkt_msg)) {
+ element.cmd = pkt_msg.cmd();
+ element.addr = pkt_msg.addr();
+ element.blocksize = pkt_msg.size();
+ element.tick = pkt_msg.tick();
return true;
}