diff options
author | Andreas Hansson <andreas.hansson@arm.com> | 2013-01-07 13:05:37 -0500 |
---|---|---|
committer | Andreas Hansson <andreas.hansson@arm.com> | 2013-01-07 13:05:37 -0500 |
commit | 35bdee72cbbced98bb93f9e5310c4dbd014dd911 (patch) | |
tree | d06a31d03c61a8cb9504d31dfff60f543cf8a91f /src/cpu/testers/traffic_gen/traffic_gen.hh | |
parent | 4afa6c4c3e7bb4ce0aea876120bf997e42353f67 (diff) | |
download | gem5-35bdee72cbbced98bb93f9e5310c4dbd014dd911.tar.xz |
cpu: Encapsulate traffic generator input in a stream
This patch encapsulates the traffic generator input in a stream class
such that the parsing is not visible to the trace generator. The
change takes us one step closer to using protobuf-based input traces
for the trace replay.
The functionality of the current input stream is identical to what it
was, and the ASCII format remains the same for now.
Diffstat (limited to 'src/cpu/testers/traffic_gen/traffic_gen.hh')
-rw-r--r-- | src/cpu/testers/traffic_gen/traffic_gen.hh | 74 |
1 files changed, 48 insertions, 26 deletions
diff --git a/src/cpu/testers/traffic_gen/traffic_gen.hh b/src/cpu/testers/traffic_gen/traffic_gen.hh index 4e94df548..be1cc0550 100644 --- a/src/cpu/testers/traffic_gen/traffic_gen.hh +++ b/src/cpu/testers/traffic_gen/traffic_gen.hh @@ -439,6 +439,52 @@ class TrafficGen : public MemObject } }; + /** + * The InputStream encapsulates a trace file and the + * internal buffers and populates TraceElements based on + * the input. + */ + class InputStream + { + + private: + + /// Input file stream for the ASCII trace + std::ifstream trace; + + /** + * Create a 4MB read buffer for the input trace + * file. This is to reduce the number of disk accesses + * and thereby speed up the execution. + */ + char readBuffer[4 * 1024 * 1024]; + + public: + + /** + * Create a trace input stream for a given file name. + * + * @param filename Path to the file to read from + */ + InputStream(const std::string& filename); + + /** + * Reset the stream such that it can be played once + * again. + */ + void reset(); + + /** + * Attempt to read a trace element from the stream, + * and also notify the caller if the end of the file + * was reached. + * + * @param element Trace element to populate + * @return True if an element could be read successfully + */ + bool read(TraceElement& element); + }; + public: /** @@ -454,28 +500,10 @@ class TrafficGen : public MemObject Tick _duration, const std::string& trace_file, Addr addr_offset) : BaseGen(_port, master_id, _duration), - traceFile(trace_file), + trace(trace_file), addrOffset(addr_offset), traceComplete(false) { - /** - * Create a 4MB read buffer for the input trace - * file. This is to reduce the number of disk accesses - * and thereby speed up the execution of the code. - */ - readBuffer = new char[4 * 1024 * 1024]; - trace.rdbuf()->pubsetbuf(readBuffer, 4 * 1024 * 1024); - trace.open(traceFile.c_str(), std::ifstream::in); - - if (!trace.is_open()) { - fatal("Traffic generator %s trace file could not be" - " opened: %s\n", name(), traceFile); - } - } - - ~TraceGen() { - // free the memory used by the readBuffer - delete[] readBuffer; } void enter(); @@ -494,14 +522,8 @@ class TrafficGen : public MemObject private: - /** Path to the trace file */ - std::string traceFile; - /** Input stream used for reading the input trace file */ - std::ifstream trace; - - /** Larger buffer used for reading from the stream */ - char* readBuffer; + InputStream trace; /** Store the current and next element in the trace */ TraceElement currElement; |