diff options
author | Steve Reinhardt <stever@eecs.umich.edu> | 2004-10-19 20:00:20 -0400 |
---|---|---|
committer | Steve Reinhardt <stever@eecs.umich.edu> | 2004-10-19 20:00:20 -0400 |
commit | f267dc4a8729179ed99ec591af2ba434cb644755 (patch) | |
tree | 83f1263d80cd74acd8e617b988290239cfdada5a /sim | |
parent | f0aed43b93c133a617a5260911777a9434f6b76c (diff) | |
download | gem5-f267dc4a8729179ed99ec591af2ba434cb644755.tar.xz |
Clean up/standardize handling of various output files.
No more non-intuitive behavior shifts depending on whether
outputDirectory is set (at the expense of backwards compatibility).
outputDirectory is now always valid, defaults to ".".
dev/etherdump.cc:
Use makeOutputStream() to create output file.
New behavior: actually complain if dump file can't
be opened, instead of quietly ignoring the problem.
dev/etherdump.hh:
dev/simconsole.cc:
dev/simconsole.hh:
Use makeOutputStream() to create output file.
sim/builder.cc:
sim/builder.hh:
sim/main.cc:
builderStream() is now *configStream.
sim/serialize.cc:
outputDirectory is now always valid, no need to check.
sim/universe.cc:
Clean up/standardize handling of various output files.
No more non-intuitive behavior shifts depending on whether
outputDirectory is set (at the expense of backwards compatibility).
outputDirectory is now always valid, defaults to ".".
New function makeOutputStream() does "the right thing" to
associate a stream with a filename.
--HG--
extra : convert_revision : a03c58c547221b3906e0d6f55e4a569843f2d646
Diffstat (limited to 'sim')
-rw-r--r-- | sim/builder.cc | 28 | ||||
-rw-r--r-- | sim/builder.hh | 3 | ||||
-rw-r--r-- | sim/main.cc | 2 | ||||
-rw-r--r-- | sim/serialize.cc | 5 | ||||
-rw-r--r-- | sim/universe.cc | 78 |
5 files changed, 58 insertions, 58 deletions
diff --git a/sim/builder.cc b/sim/builder.cc index 53e5cf3d8..890451ec4 100644 --- a/sim/builder.cc +++ b/sim/builder.cc @@ -39,26 +39,6 @@ using namespace std; - -ostream & -builderStream() -{ - static ofstream file; - static ostream *stream = NULL; - - if (!stream) { - if (!outputDirectory.empty()) { - string filename = outputDirectory + "builder.txt"; - file.open(filename.c_str()); - stream = &file; - } else { - stream = outputStream; - } - } - - return *stream; -} - SimObjectBuilder::SimObjectBuilder(const string &_configClass, const string &_instanceName, ConfigNode *_configNode, @@ -187,10 +167,10 @@ SimObjectClass::createObject(IniFile &configDB, // echo object parameters to stats file (for documenting the // config used to generate the associated stats) - builderStream() << "[" << object->name() << "]" << endl; - builderStream() << "type=" << simObjClassName << endl; - objectBuilder->showParams(builderStream()); - builderStream() << endl; + *configStream << "[" << object->name() << "]" << endl; + *configStream << "type=" << simObjClassName << endl; + objectBuilder->showParams(*configStream); + *configStream << endl; // done with the SimObjectBuilder now delete objectBuilder; diff --git a/sim/builder.hh b/sim/builder.hh index a85c88b76..36e40c2a9 100644 --- a/sim/builder.hh +++ b/sim/builder.hh @@ -38,9 +38,6 @@ class SimObject; -std::ostream & -builderStream(); - // // A SimObjectBuilder serves as an evaluation context for a set of // parameters that describe a specific instance of a SimObject. This diff --git a/sim/main.cc b/sim/main.cc index 2a0427303..0147ffcc3 100644 --- a/sim/main.cc +++ b/sim/main.cc @@ -396,7 +396,7 @@ main(int argc, char **argv) // Echo command line and all parameter settings to stats file as well. echoCommandLine(argc, argv, *outputStream); - ParamContext::showAllContexts(builderStream()); + ParamContext::showAllContexts(*configStream); // Now process the configuration hierarchy and create the SimObjects. ConfigHierarchy configHierarchy(simConfigDB); diff --git a/sim/serialize.cc b/sim/serialize.cc index 91548f653..2a5e3d398 100644 --- a/sim/serialize.cc +++ b/sim/serialize.cc @@ -335,10 +335,7 @@ SerializeParamContext::checkParams() if (serialize_dir.isValid()) { checkpointDirBase = serialize_dir; } else { - if (outputDirectory.empty()) - checkpointDirBase = "m5.%012d"; - else - checkpointDirBase = outputDirectory + "cpt.%012d"; + checkpointDirBase = outputDirectory + "cpt.%012d"; } // guarantee that directory ends with a '/' diff --git a/sim/universe.cc b/sim/universe.cc index 79e32098c..ffff52104 100644 --- a/sim/universe.cc +++ b/sim/universe.cc @@ -51,12 +51,10 @@ double __ticksPerPS; string outputDirectory; ostream *outputStream; +ostream *configStream; class UniverseParamContext : public ParamContext { - private: - ofstream outputFile; - public: UniverseParamContext(const string &is) : ParamContext(is) {} void checkParams(); @@ -68,9 +66,14 @@ Param<Tick> universe_freq(&universe, "frequency", "tick frequency", 200000000); Param<string> universe_output_dir(&universe, "output_dir", - "directory to output data to"); + "directory to output data to", + "."); Param<string> universe_output_file(&universe, "output_file", - "file to dump simulator output to"); + "file to dump simulator output to", + "cout"); +Param<string> universe_config_output_file(&universe, "config_output_file", + "file to dump simulator config to", + "m5config.out"); void UniverseParamContext::checkParams() @@ -97,26 +100,49 @@ UniverseParamContext::checkParams() } } - 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"; - } + outputStream = makeOutputStream(universe_output_file); + configStream = universe_config_output_file.isValid() + ? makeOutputStream(universe_config_output_file) + : outputStream; +} - 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; - } + +std::ostream * +makeOutputStream(std::string &name) +{ + if (name == "cerr" || name == "stderr") + return &std::cerr; + + if (name == "cout" || name == "stdout") + return &std::cout; + + string path = (name[0] != '/') ? outputDirectory + name : name; + + // have to dynamically allocate a stream since we're going to + // return it... though the caller can't easily free it since it + // may be cerr or cout. need GC! + ofstream *s = new ofstream(path.c_str(), ios::trunc); + + if (!s->is_open()) + fatal("Cannot open file %s", path); + + return s; } + + +void +closeOutputStream(std::ostream *os) +{ + // can't close cerr or cout + if (os == &std::cerr || os == &std::cout) + return; + + // can only close ofstreams, not generic ostreams, so try to + // downcast and close only if the downcast succeeds + std::ofstream *ofs = dynamic_cast<std::ofstream *>(os); + if (ofs) + ofs->close(); +} + + + |