summaryrefslogtreecommitdiff
path: root/sim/universe.cc
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2004-01-29 00:38:18 -0500
committerNathan Binkert <binkertn@umich.edu>2004-01-29 00:38:18 -0500
commit2db1b6ea1b61665908138d7004001d494c168d85 (patch)
treee57ab8297cc47a1bfc93bd63e84577f4ad59303f /sim/universe.cc
parentf994cf4b5edb0eea23b695e1ee4f3a9d7b811b82 (diff)
downloadgem5-2db1b6ea1b61665908138d7004001d494c168d85.tar.xz
provide an output stream for simulator output. (This takes place of the
statStream catchall that we had before) Also provide an optional output directory that multiple simulator output files can be written to. Make most output files use the output directory base/misc.cc: send warnings to the outputStream as well base/trace.cc: dprintf_stream defaults to cerr dev/console.cc: use the output directory for the console output if it exists dev/etherdump.cc: dump to the output directory if it exists sim/builder.cc: sim/builder.hh: move constructor and destructor to .cc file use a function to get the stream that the builder dumps its output to, and create a separate file in the output directory if able sim/main.cc: statStream -> outputStream sim/serialize.cc: dump checkpoints to the output directory if specified sim/universe.cc: provide an output stream for simulator output. (This takes place of the statStream catchall that we had before) Also provide an optional output directory that multiple simulator output files can be written to. --HG-- extra : convert_revision : 03abce20edbbf7ec19c9ddd8d69ec8485c383532
Diffstat (limited to 'sim/universe.cc')
-rw-r--r--sim/universe.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/sim/universe.cc b/sim/universe.cc
index b75b1f78a..440c6363f 100644
--- a/sim/universe.cc
+++ b/sim/universe.cc
@@ -26,10 +26,17 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <cstring>
+#include <fstream>
#include <list>
#include <string>
#include <vector>
+#include "base/files.hh"
+#include "base/misc.hh"
#include "sim/universe.hh"
#include "sim/host.hh"
#include "sim/param.hh"
@@ -42,8 +49,14 @@ double __ticksPerMS;
double __ticksPerUS;
double __ticksPerNS;
+string outputDirectory;
+ostream *outputStream;
+
class UniverseParamContext : public ParamContext
{
+ private:
+ ofstream outputFile;
+
public:
UniverseParamContext(const string &is) : ParamContext(is) {}
void checkParams();
@@ -54,6 +67,11 @@ UniverseParamContext universe("Universe");
Param<Tick> universe_freq(&universe, "frequency", "tick frequency",
200000000);
+Param<string> universe_output_dir(&universe, "output_dir",
+ "directory to output data to");
+Param<string> universe_output_file(&universe, "output_file",
+ "file to dump simulator output to");
+
void
UniverseParamContext::checkParams()
{
@@ -62,4 +80,42 @@ UniverseParamContext::checkParams()
__ticksPerMS = freq / 1.0e3;
__ticksPerUS = freq / 1.0e6;
__ticksPerNS = freq / 1.0e9;
+
+ if (universe_output_dir.isValid()) {
+ outputDirectory = universe_output_dir;
+
+ // guarantee that directory ends with a '/'
+ if (outputDirectory[outputDirectory.size() - 1] != '/')
+ outputDirectory += "/";
+
+ if (mkdir(outputDirectory.c_str(), 0777) < 0) {
+ if (errno != EEXIST) {
+ panic("%s\ncould not make output directory: %s\n",
+ strerror(errno), outputDirectory);
+ }
+ }
+ }
+
+ string filename;
+ if (universe_output_file.isValid()) {
+ string f = universe_output_file;
+ if (f != "stdout" && f != "cout" && f != "stderr" && f != "cerr")
+ filename = outputDirectory + f;
+ else
+ filename = f;
+ } else {
+ if (outputDirectory.empty())
+ filename = "stdout";
+ else
+ filename = outputDirectory + "output.txt";
+ }
+
+ if (filename == "stdout" || filename == "cout")
+ outputStream = &cout;
+ else if (filename == "stderr" || filename == "cerr")
+ outputStream = &cerr;
+ else {
+ outputFile.open(filename.c_str(), ios::trunc);
+ outputStream = &outputFile;
+ }
}