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
This commit is contained in:
parent
f994cf4b5e
commit
2db1b6ea1b
9 changed files with 151 additions and 35 deletions
|
@ -121,6 +121,8 @@ __warn(const string &format, cp::ArgList &args, const char *func,
|
|||
#endif
|
||||
|
||||
args.dump(cerr, fmt);
|
||||
if (outputStream != &cerr && outputStream != &cout)
|
||||
args.dump(*outputStream, fmt);
|
||||
|
||||
delete &args;
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ FlagVec flags(NumFlags, false);
|
|||
// directly; use DebugOut() (see below) to access this stream for
|
||||
// output.
|
||||
//
|
||||
ostream *dprintf_stream = NULL;
|
||||
ostream *dprintf_stream = &cerr;
|
||||
|
||||
int dprintf_ignore_size;
|
||||
vector<string> dprintf_ignore;
|
||||
|
@ -267,10 +267,7 @@ RawDataRecord::dump(ostream &os)
|
|||
std::ostream &
|
||||
DebugOut()
|
||||
{
|
||||
if (Trace::dprintf_stream)
|
||||
return *Trace::dprintf_stream;
|
||||
else
|
||||
return cerr;
|
||||
return *Trace::dprintf_stream;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
|
|
|
@ -383,8 +383,16 @@ END_INIT_SIM_OBJECT_PARAMS(SimConsole)
|
|||
CREATE_SIM_OBJECT(SimConsole)
|
||||
{
|
||||
string filename = output;
|
||||
if (!filename.empty() && append_name)
|
||||
filename += "." + getInstanceName();
|
||||
if (filename.empty()) {
|
||||
if (!outputDirectory.empty())
|
||||
filename = outputDirectory + getInstanceName();
|
||||
} else {
|
||||
if (append_name)
|
||||
filename += "." + getInstanceName();
|
||||
if (!outputDirectory.empty())
|
||||
filename = outputDirectory + filename;
|
||||
}
|
||||
|
||||
SimConsole *console = new SimConsole(getInstanceName(), filename, number);
|
||||
((ConsoleListener *)listener)->add(console);
|
||||
((SimConsole *)console)->initInt(intr_control);
|
||||
|
|
|
@ -126,13 +126,27 @@ END_DECLARE_SIM_OBJECT_PARAMS(EtherDump)
|
|||
|
||||
BEGIN_INIT_SIM_OBJECT_PARAMS(EtherDump)
|
||||
|
||||
INIT_PARAM_DFLT(file, "file to dump packets to", "")
|
||||
INIT_PARAM(file, "file to dump packets to")
|
||||
|
||||
END_INIT_SIM_OBJECT_PARAMS(EtherDump)
|
||||
|
||||
CREATE_SIM_OBJECT(EtherDump)
|
||||
{
|
||||
return new EtherDump(getInstanceName(), file);
|
||||
string filename;
|
||||
if (file.isValid()) {
|
||||
filename = file;
|
||||
|
||||
if (filename[0] != '/' && !outputDirectory.empty())
|
||||
filename = outputDirectory + filename;
|
||||
} else {
|
||||
if (outputDirectory.empty()) {
|
||||
filename = "etherdump";
|
||||
} else {
|
||||
filename = outputDirectory + "etherdump";
|
||||
}
|
||||
}
|
||||
|
||||
return new EtherDump(getInstanceName(), filename);
|
||||
}
|
||||
|
||||
REGISTER_SIM_OBJECT("EtherDump", EtherDump)
|
||||
|
|
|
@ -34,10 +34,45 @@
|
|||
#include "sim/configfile.hh"
|
||||
#include "sim/host.hh"
|
||||
#include "sim/sim_object.hh"
|
||||
#include "sim/sim_stats.hh"
|
||||
#include "sim/universe.hh"
|
||||
|
||||
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,
|
||||
const string &_simObjClassName)
|
||||
: ParamContext(_configClass, true),
|
||||
instanceName(_instanceName),
|
||||
configNode(_configNode),
|
||||
simObjClassName(_simObjClassName)
|
||||
{
|
||||
}
|
||||
|
||||
SimObjectBuilder::~SimObjectBuilder()
|
||||
{
|
||||
}
|
||||
|
||||
///////////////////////////////////////////
|
||||
//
|
||||
// SimObjectBuilder member definitions
|
||||
|
@ -151,10 +186,10 @@ SimObjectClass::createObject(IniFile &configDB,
|
|||
|
||||
// echo object parameters to stats file (for documenting the
|
||||
// config used to generate the associated stats)
|
||||
*statStream << "[" << object->name() << "]" << endl;
|
||||
*statStream << "type=" << simObjClassName << endl;
|
||||
objectBuilder->showParams(*statStream);
|
||||
*statStream << endl;
|
||||
builderStream() << "[" << object->name() << "]" << endl;
|
||||
builderStream() << "type=" << simObjClassName << endl;
|
||||
objectBuilder->showParams(builderStream());
|
||||
builderStream() << endl;
|
||||
|
||||
// done with the SimObjectBuilder now
|
||||
delete objectBuilder;
|
||||
|
|
|
@ -29,15 +29,18 @@
|
|||
#ifndef __BUILDER_HH__
|
||||
#define __BUILDER_HH__
|
||||
|
||||
#include <map>
|
||||
#include <iosfwd>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
#include "sim/param.hh"
|
||||
|
||||
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
|
||||
|
@ -69,15 +72,9 @@ class SimObjectBuilder : public ParamContext
|
|||
SimObjectBuilder(const std::string &_configClass,
|
||||
const std::string &_instanceName,
|
||||
ConfigNode *_configNode,
|
||||
const std::string &_simObjClassName)
|
||||
: ParamContext(_configClass, true),
|
||||
instanceName(_instanceName),
|
||||
configNode(_configNode),
|
||||
simObjClassName(_simObjClassName)
|
||||
{
|
||||
}
|
||||
const std::string &_simObjClassName);
|
||||
|
||||
virtual ~SimObjectBuilder() {}
|
||||
virtual ~SimObjectBuilder();
|
||||
|
||||
// call parse() on all params in this context to convert string
|
||||
// representations to parameter values
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
#include "sim/sim_init.hh"
|
||||
#include "sim/sim_object.hh"
|
||||
#include "sim/sim_stats.hh"
|
||||
#include "sim/universe.hh"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -355,12 +356,12 @@ main(int argc, char **argv)
|
|||
|
||||
// Print hello message to stats file if it's actually a file. If
|
||||
// it's not (i.e. it's cout or cerr) then we already did it above.
|
||||
if (statStreamIsFile)
|
||||
sayHello(*statStream);
|
||||
if (outputStream != &cout && outputStream != &cerr)
|
||||
sayHello(*outputStream);
|
||||
|
||||
// Echo command line and all parameter settings to stats file as well.
|
||||
echoCommandLine(argc, argv, *statStream);
|
||||
ParamContext::showAllContexts(*statStream);
|
||||
echoCommandLine(argc, argv, *outputStream);
|
||||
ParamContext::showAllContexts(builderStream());
|
||||
|
||||
// Now process the configuration hierarchy and create the SimObjects.
|
||||
ConfigHierarchy configHierarchy(simConfigDB);
|
||||
|
|
|
@ -305,10 +305,9 @@ class SerializeParamContext : public ParamContext
|
|||
|
||||
SerializeParamContext serialParams("serialize");
|
||||
|
||||
Param<string> serialize_dir(&serialParams,
|
||||
"dir",
|
||||
Param<string> serialize_dir(&serialParams, "dir",
|
||||
"dir to stick checkpoint in "
|
||||
"(sprintf format with cycle #)", "m5.%012d");
|
||||
"(sprintf format with cycle #)");
|
||||
|
||||
Param<Counter> serialize_cycle(&serialParams,
|
||||
"cycle",
|
||||
|
@ -333,12 +332,19 @@ SerializeParamContext::~SerializeParamContext()
|
|||
void
|
||||
SerializeParamContext::checkParams()
|
||||
{
|
||||
checkpointDirBase = serialize_dir;
|
||||
// guarantee that directory ends with a '/'
|
||||
if (checkpointDirBase[checkpointDirBase.size() - 1] != '/') {
|
||||
checkpointDirBase += "/";
|
||||
if (serialize_dir.isValid()) {
|
||||
checkpointDirBase = serialize_dir;
|
||||
} else {
|
||||
if (outputDirectory.empty())
|
||||
checkpointDirBase = "m5.%012d";
|
||||
else
|
||||
checkpointDirBase = outputDirectory + "cpt.%012d";
|
||||
}
|
||||
|
||||
// guarantee that directory ends with a '/'
|
||||
if (checkpointDirBase[checkpointDirBase.size() - 1] != '/')
|
||||
checkpointDirBase += "/";
|
||||
|
||||
if (serialize_cycle > 0)
|
||||
Checkpoint::setup(serialize_cycle, serialize_period);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue