base: Add support for changing output directories

This changeset adds support for changing the simulator output
directory. This can be useful when the simulation goes through several
stages (e.g., a warming phase, a simulation phase, and a verification
phase) since it allows the output from each stage to be located in a
different directory. Relocation is done by calling core.setOutputDir()
from Python or simout.setOutputDirectory() from C++.

This change affects several parts of the design of the gem5's output
subsystem. First, files returned by an OutputDirectory instance (e.g.,
simout) are of the type OutputStream instead of a std::ostream. This
allows us to do some more book keeping and control re-opening of files
when the output directory is changed. Second, new subdirectories are
OutputDirectory instances, which should be used to create files in
that sub-directory.

Signed-off-by: Andreas Sandberg <andreas@sandberg.pp.se>
[sascha.bischoff@arm.com: Rebased patches onto a newer gem5 version]
Signed-off-by: Sascha Bischoff <sascha.bischoff@arm.com>
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
This commit is contained in:
Andreas Sandberg 2015-11-27 14:41:59 +00:00
parent fed0ea55c4
commit 5383e1ada4
21 changed files with 361 additions and 170 deletions

View file

@ -304,15 +304,15 @@ DumpStatsPCEvent::process(ThreadContext *tc)
tc->getCpuPtr()->taskId(taskMap[pid]); tc->getCpuPtr()->taskId(taskMap[pid]);
tc->getCpuPtr()->setPid(pid); tc->getCpuPtr()->setPid(pid);
std::ostream* taskFile = sys->taskFile; OutputStream* taskFile = sys->taskFile;
// Task file is read by cache occupancy plotting script or // Task file is read by cache occupancy plotting script or
// Streamline conversion script. // Streamline conversion script.
ccprintf(*taskFile, ccprintf(*(taskFile->stream()),
"tick=%lld %d cpu_id=%d next_pid=%d next_tgid=%d next_task=%s\n", "tick=%lld %d cpu_id=%d next_pid=%d next_tgid=%d next_task=%s\n",
curTick(), taskMap[pid], tc->cpuId(), (int) pid, (int) tgid, curTick(), taskMap[pid], tc->cpuId(), (int) pid, (int) tgid,
next_task_str); next_task_str);
taskFile->flush(); taskFile->stream()->flush();
// Dump and reset statistics // Dump and reset statistics
Stats::schedStatEvent(true, true, curTick(), 0); Stats::schedStatEvent(true, true, curTick(), 0);

View file

@ -82,7 +82,7 @@ class LinuxArmSystem : public GenericArmSystem
/** This is a file that is placed in the run directory that prints out /** This is a file that is placed in the run directory that prints out
* mappings between taskIds and OS process IDs */ * mappings between taskIds and OS process IDs */
std::ostream* taskFile; OutputStream* taskFile;
LinuxArmSystem(Params *p); LinuxArmSystem(Params *p);
~LinuxArmSystem(); ~LinuxArmSystem();

View file

@ -1,4 +1,17 @@
/* /*
* Copyright (c) 2015 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Copyright (c) 2013 Andreas Sandberg
* Copyright (c) 2005 The Regents of The University of Michigan * Copyright (c) 2005 The Regents of The University of Michigan
* All rights reserved. * All rights reserved.
* *
@ -27,6 +40,8 @@
* *
* Authors: Nathan Binkert * Authors: Nathan Binkert
* Chris Emmons * Chris Emmons
* Andreas Sandberg
* Sascha Bischoff
*/ */
#include <sys/stat.h> #include <sys/stat.h>
@ -49,94 +64,127 @@ using namespace std;
OutputDirectory simout; OutputDirectory simout;
OutputStream::OutputStream(const std::string &name, std::ostream *stream)
: _name(name), _stream(stream)
{
}
OutputStream::~OutputStream()
{
}
void
OutputStream::relocate(const OutputDirectory &dir)
{
}
template<class StreamType>
OutputFile<StreamType>::OutputFile(const OutputDirectory &dir,
const std::string &name,
std::ios_base::openmode mode,
bool recreateable)
: OutputStream(name, new stream_type_t()),
_mode(mode), _recreateable(recreateable),
_fstream(static_cast<stream_type_t *>(_stream))
{
_fstream->open(dir.resolve(_name).c_str(), _mode);
assert(_fstream->is_open());
}
template<class StreamType>
OutputFile<StreamType>::~OutputFile()
{
if (_fstream->is_open())
_fstream->close();
}
template<class StreamType>
void
OutputFile<StreamType>::relocate(const OutputDirectory &dir)
{
if (_recreateable) {
_fstream->close();
_fstream->open(dir.resolve(_name).c_str(), _mode);
}
}
OutputStream OutputDirectory::stdout("stdout", &cout);
OutputStream OutputDirectory::stderr("stderr", &cerr);
/** /**
* @file This file manages creating / deleting output files for the simulator. * @file This file manages creating / deleting output files for the simulator.
*/ */
OutputDirectory::OutputDirectory() OutputDirectory::OutputDirectory()
{} {}
OutputDirectory::OutputDirectory(const std::string &name)
{
setDirectory(name);
}
OutputDirectory::~OutputDirectory() OutputDirectory::~OutputDirectory()
{ {
for (map_t::iterator i = files.begin(); i != files.end(); i++) { for (auto& f: files) {
if (i->second) if (f.second)
delete i->second; delete f.second;
} }
} }
std::ostream * OutputStream *
OutputDirectory::checkForStdio(const string &name) const OutputDirectory::checkForStdio(const string &name)
{ {
if (name == "cerr" || name == "stderr") if (name == "cerr" || name == "stderr")
return &cerr; return &stderr;
if (name == "cout" || name == "stdout") if (name == "cout" || name == "stdout")
return &cout; return &stdout;
return NULL; return NULL;
} }
ostream *
OutputDirectory::openFile(const string &filename,
ios_base::openmode mode, bool no_gz)
{
bool gz = !no_gz;
gz = gz && filename.find(".gz", filename.length()-3) < filename.length();
if (gz) {
gzofstream *file = new gzofstream(filename.c_str(), mode);
if (!file->is_open())
fatal("Cannot open file %s", filename);
assert(files.find(filename) == files.end());
files[filename] = file;
return file;
} else {
ofstream *file = new ofstream(filename.c_str(), mode);
if (!file->is_open())
fatal("Cannot open file %s", filename);
assert(files.find(filename) == files.end());
files[filename] = file;
return file;
}
}
void void
OutputDirectory::close(ostream *openStream) { OutputDirectory::close(OutputStream *file)
map_t::iterator i; {
for (i = files.begin(); i != files.end(); i++) { auto i = files.find(file->name());
if (i->second != openStream)
continue;
ofstream *fs = dynamic_cast<ofstream*>(i->second);
if (fs) {
fs->close();
delete i->second;
break;
} else {
gzofstream *gfs = dynamic_cast<gzofstream*>(i->second);
if (gfs) {
gfs->close();
delete i->second;
break;
}
}
}
if (i == files.end()) if (i == files.end())
fatal("Attempted to close an unregistred file stream"); fatal("Attempted to close an unregistred file stream");
files.erase(i); files.erase(i);
delete file;
} }
void void
OutputDirectory::setDirectory(const string &d) OutputDirectory::setDirectory(const string &d)
{ {
if (!dir.empty()) const string old_dir(dir);
panic("Output directory already set!\n");
dir = d; dir = d;
// guarantee that directory ends with a path separator // guarantee that directory ends with a path separator
if (dir[dir.size() - 1] != PATH_SEPARATOR) if (dir[dir.size() - 1] != PATH_SEPARATOR)
dir += PATH_SEPARATOR; dir += PATH_SEPARATOR;
// Try to create the directory. If it already exists, that's ok;
// otherwise, fail if we couldn't create it.
if ((mkdir(dir.c_str(), 0755) != 0) && (errno != EEXIST))
fatal("Failed to create new output subdirectory '%s'\n", dir);
// Check if we need to recreate anything
if (!old_dir.empty()) {
// Recreate output files
for (file_map_t::iterator i = files.begin(); i != files.end(); ++i) {
i->second->relocate(*this);
}
// Relocate sub-directories
for (dir_map_t::iterator i = dirs.begin(); i != dirs.end(); ++i) {
i->second->setDirectory(dir + PATH_SEPARATOR + i->first);
}
}
} }
const string & const string &
@ -151,43 +199,69 @@ OutputDirectory::directory() const
string string
OutputDirectory::resolve(const string &name) const OutputDirectory::resolve(const string &name) const
{ {
return (name[0] != PATH_SEPARATOR) ? dir + name : name; return !isAbsolute(name) ? dir + name : name;
} }
ostream * OutputStream *
OutputDirectory::create(const string &name, bool binary, bool no_gz) OutputDirectory::create(const string &name, bool binary, bool no_gz)
{ {
ostream *file = checkForStdio(name); OutputStream *file = checkForStdio(name);
if (file) if (file)
return file; return file;
string filename = resolve(name); const ios_base::openmode mode(
ios_base::openmode mode = ios::trunc | (binary ? ios::binary : (ios::openmode)0));
ios::trunc | (binary ? ios::binary : (ios::openmode)0); const bool recreateable(!isAbsolute(name));
file = openFile(filename, mode, no_gz);
return file; return open(name, mode, recreateable, no_gz);
} }
ostream * OutputStream *
OutputDirectory::open(const std::string &name,
ios_base::openmode mode,
bool recreateable,
bool no_gz)
{
OutputStream *os;
if (!no_gz && name.find(".gz", name.length() - 3) < name.length()) {
// Although we are creating an output stream, we still need to pass the
// correct mode for gzofstream as this used directly to set the file
// mode.
mode |= std::ios::out;
os = new OutputFile<gzofstream>(*this, name, mode, recreateable);
} else {
os = new OutputFile<ofstream>(*this, name, mode, recreateable);
}
files[name] = os;
return os;
}
OutputStream *
OutputDirectory::find(const string &name) const OutputDirectory::find(const string &name) const
{ {
ostream *file = checkForStdio(name); OutputStream *file = checkForStdio(name);
if (file) if (file)
return file; return file;
const string filename = resolve(name); auto i = files.find(name);
map_t::const_iterator i = files.find(filename);
if (i != files.end()) if (i != files.end())
return (*i).second; return (*i).second;
return NULL; return NULL;
} }
bool
OutputDirectory::isFile(const std::ostream *os) OutputStream *
OutputDirectory::findOrCreate(const std::string &name, bool binary)
{ {
return os && os != &cerr && os != &cout; OutputStream *os(find(name));
if (os)
return os;
else
return create(name, binary);
} }
bool bool
@ -201,18 +275,17 @@ OutputDirectory::isFile(const string &name) const
return (st == 0) && S_ISREG(st_buf.st_mode); return (st == 0) && S_ISREG(st_buf.st_mode);
} }
string OutputDirectory *
OutputDirectory::createSubdirectory(const string &name) const OutputDirectory::createSubdirectory(const string &name)
{ {
const string new_dir = resolve(name); const string new_dir = resolve(name);
if (new_dir.find(directory()) == string::npos) if (new_dir.find(directory()) == string::npos)
fatal("Attempting to create subdirectory not in m5 output dir\n"); fatal("Attempting to create subdirectory not in m5 output dir\n");
// if it already exists, that's ok; otherwise, fail if we couldn't create OutputDirectory *dir(new OutputDirectory(new_dir));
if ((mkdir(new_dir.c_str(), 0755) != 0) && (errno != EEXIST)) dirs[name] = dir;
fatal("Failed to create new output subdirectory '%s'\n", new_dir);
return name + PATH_SEPARATOR; return dir;
} }
void void
@ -225,10 +298,10 @@ OutputDirectory::remove(const string &name, bool recursive)
if (isFile(fname)) { if (isFile(fname)) {
// close and release file if we have it open // close and release file if we have it open
map_t::iterator itr = files.find(fname); auto i = files.find(fname);
if (itr != files.end()) { if (i != files.end()) {
delete itr->second; delete i->second;
files.erase(itr); files.erase(i);
} }
if (::remove(fname.c_str()) != 0) if (::remove(fname.c_str()) != 0)

View file

@ -1,4 +1,17 @@
/* /*
* Copyright (c) 2015 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Copyright (c) 2013 Andreas Sandberg
* Copyright (c) 2005 The Regents of The University of Michigan * Copyright (c) 2005 The Regents of The University of Michigan
* All rights reserved. * All rights reserved.
* *
@ -27,6 +40,8 @@
* *
* Authors: Nathan Binkert * Authors: Nathan Binkert
* Chris Emmons * Chris Emmons
* Andreas Sandberg
* Sascha Bischoff
*/ */
#ifndef __BASE_OUTPUT_HH__ #ifndef __BASE_OUTPUT_HH__
@ -36,15 +51,105 @@
#include <map> #include <map>
#include <string> #include <string>
#include "base/compiler.hh"
class OutputDirectory;
class OutputStream
{
public:
virtual ~OutputStream();
/** Get the output underlying output stream */
std::ostream *stream() const { return _stream; };
/**
* Can the file be recreated if the output directory is moved?
*
* @return true if the file will be created in the new location,
* false otherwise.
*/
virtual bool recreateable() const { return false; }
/** Get the file name in the output directory */
const std::string &name() const { return _name; }
protected:
friend class OutputDirectory;
/** Wrap an existing stream */
OutputStream(const std::string &name,
std::ostream *stream);
/* Prevent copying */
OutputStream(const OutputStream &f);
/** Re-create the in a new location if recreateable. */
virtual void relocate(const OutputDirectory &dir);
/** Name in output directory */
const std::string _name;
/** Underlying output stream */
std::ostream *const _stream;
};
template<class StreamType>
class OutputFile
: public OutputStream
{
public:
typedef StreamType stream_type_t;
virtual ~OutputFile();
/**
* Can the file be recreated if the output directory is moved?
*
* @return true if the file will be created in the new location,
* false otherwise.
*/
bool recreateable() const override { return _recreateable; }
protected:
friend class OutputDirectory;
OutputFile(const OutputDirectory &dir,
const std::string &name,
std::ios_base::openmode mode,
bool recreateable);
/* Prevent copying */
OutputFile(const OutputFile<StreamType> &f);
/** Re-create the file in a new location if it is relocatable. */
void relocate(const OutputDirectory &dir) override;
/** File mode when opened */
const std::ios_base::openmode _mode;
/** Can the file be recreated in a new location? */
const bool _recreateable;
/** Pointer to the file stream */
stream_type_t *const _fstream;
};
/** Interface for creating files in a gem5 output directory. */ /** Interface for creating files in a gem5 output directory. */
class OutputDirectory class OutputDirectory
{ {
private: private:
/** File names and associated stream handles */ /** File names and associated stream handles */
typedef std::map<std::string, std::ostream *> map_t; typedef std::map<std::string, OutputStream *> file_map_t;
/** Output subdirectories */
typedef std::map<std::string, OutputDirectory *> dir_map_t;
/** Open file streams within this directory */ /** Open file streams within this directory */
map_t files; file_map_t files;
/** Output sub-directories */
dir_map_t dirs;
/** Name of this directory */ /** Name of this directory */
std::string dir; std::string dir;
@ -52,6 +157,9 @@ class OutputDirectory
/** System-specific path separator character */ /** System-specific path separator character */
static const char PATH_SEPARATOR = '/'; static const char PATH_SEPARATOR = '/';
static OutputStream stdout;
static OutputStream stderr;
protected: protected:
/** /**
* Determines whether given file name corresponds to standard output * Determines whether given file name corresponds to standard output
@ -61,12 +169,15 @@ class OutputDirectory
* @return output stream for standard output or error stream if name * @return output stream for standard output or error stream if name
* corresponds to one or the other; NULL otherwise * corresponds to one or the other; NULL otherwise
*/ */
std::ostream *checkForStdio(const std::string &name) const; static OutputStream *checkForStdio(const std::string &name);
public: public:
/** Constructor. */ /** Constructor. */
OutputDirectory(); OutputDirectory();
/** Constructor. */
OutputDirectory(const std::string &name);
/** Destructor. */ /** Destructor. */
~OutputDirectory(); ~OutputDirectory();
@ -80,20 +191,6 @@ class OutputDirectory
*/ */
std::string resolve(const std::string &name) const; std::string resolve(const std::string &name) const;
/** Opens a file (optionally compressed).
*
* Will open a file as a compressed stream if filename ends in .gz.
*
* @param filename file to open
* @param mode attributes to open file with
* @param no_gz true to disable opening the file as a gzip compressed output
* stream; false otherwise
* @return stream pointer to opened file; will cause sim fail on error
*/
std::ostream *openFile(const std::string &filename,
std::ios_base::openmode mode = std::ios::trunc,
bool no_gz = false);
/** /**
* Sets name of this directory. * Sets name of this directory.
* @param dir name of this directory * @param dir name of this directory
@ -109,40 +206,64 @@ class OutputDirectory
/** /**
* Creates a file in this directory (optionally compressed). * Creates a file in this directory (optionally compressed).
* *
* Will open a file as a compressed stream if filename ends in .gz. * Will open a file as a compressed stream if filename ends in .gz, unless
* explicitly disabled.
*
* Relative output paths will result in the creation of a
* recreateable (see OutputFile) output file in the current output
* directory. Files created with an absolute path will not be
* recreateable.
* *
* @param name name of file to create (without this directory's name * @param name name of file to create (without this directory's name
* leading it) * leading it)
* @param binary true to create a binary file; false otherwise * @param binary true to create a binary file; false otherwise
* @param no_gz true to disable creating a gzip compressed output stream; * @param no_gz true to disable opening the file as a gzip compressed output
* false otherwise * stream; false otherwise
* @return stream to the opened file * @return OutputStream instance representing the created file
*/ */
std::ostream *create(const std::string &name, bool binary = false, OutputStream *create(const std::string &name,
bool binary = false,
bool no_gz = false); bool no_gz = false);
/** /**
* Closes a file stream. * Open a file in this directory (optionally compressed).
* *
* Stream must have been opened through this interface, or sim will fail. * Will open a file as a compressed stream if filename ends in .gz, unless
* explicitly disabled.
* *
* @param openStream open stream to close * @param filename file to open
* @param mode attributes to open file with
* @param recreateable Set to true if the file can be recreated in a new
* location.
* @param no_gz true to disable opening the file as a gzip compressed output
* stream; false otherwise
* @return OutputStream instance representing the opened file
*/ */
void close(std::ostream *openStream); OutputStream *open(const std::string &name,
std::ios_base::openmode mode,
bool recreateable = true,
bool no_gz = false);
/** /**
* Finds stream associated with a file. * Closes an output file and free the corresponding OutputFile.
*
* The output file must have been opened by the same
* OutputDirectory instance as the one closing it, or sim will
* fail.
*
* @param file OutputStream instance in this OutputDirectory.
*/
void close(OutputStream *file);
/**
* Finds stream associated with an open file or stdout/stderr.
*
* @param name of file * @param name of file
* @return stream to specified file or NULL if file does not exist * @return stream to specified file or NULL if file does not exist
*/ */
std::ostream *find(const std::string &name) const; OutputStream *find(const std::string &name) const;
/** OutputStream *findOrCreate(const std::string &name, bool binary = false);
* Returns true if stream is open and not standard output or error.
* @param os output stream to evaluate
* @return true if os is non-NULL and not cout or cerr
*/
static bool isFile(const std::ostream *os);
/** /**
* Determines whether a file name corresponds to a file in this directory. * Determines whether a file name corresponds to a file in this directory.
@ -153,12 +274,10 @@ class OutputDirectory
bool isFile(const std::string &name) const; bool isFile(const std::string &name) const;
/** /**
* Returns true if stream is open and not standard output or error. * Test if a path is absolute.
* @param os output stream to evaluate
* @return true if os is non-NULL and not cout or cerr
*/ */
static inline bool isFile(const std::ostream &os) { static inline bool isAbsolute(const std::string &name) {
return isFile(&os); return name[0] == PATH_SEPARATOR;
} }
/** /**
@ -166,7 +285,7 @@ class OutputDirectory
* @param name name of subdirectory * @param name name of subdirectory
* @return the new subdirectory's name suffixed with a path separator * @return the new subdirectory's name suffixed with a path separator
*/ */
std::string createSubdirectory(const std::string &name) const; OutputDirectory *createSubdirectory(const std::string &name);
/** /**
* Removes a specified file or subdirectory. * Removes a specified file or subdirectory.

View file

@ -740,11 +740,7 @@ initText(const string &filename, bool desc)
static bool connected = false; static bool connected = false;
if (!connected) { if (!connected) {
ostream *os = simout.find(filename); text.open(*simout.findOrCreate(filename)->stream());
if (!os)
os = simout.create(filename);
text.open(*os);
text.descriptions = desc; text.descriptions = desc;
connected = true; connected = true;
} }

View file

@ -123,10 +123,9 @@ VncInput::captureFrameBuffer()
const string frameFilename(frameFilenameBuffer); const string frameFilename(frameFilenameBuffer);
// create the compressed framebuffer file // create the compressed framebuffer file
ostream *fb_out = simout.create(captureOutputDirectory + frameFilename, OutputStream *fb_out(captureOutputDirectory->create(frameFilename, true));
true); captureBitmap->write(*fb_out->stream());
captureBitmap->write(*fb_out); captureOutputDirectory->close(fb_out);
simout.close(fb_out);
++captureCurrentFrame; ++captureCurrentFrame;
} }

View file

@ -52,6 +52,8 @@
#include "params/VncInput.hh" #include "params/VncInput.hh"
#include "sim/sim_object.hh" #include "sim/sim_object.hh"
class OutputDirectory;
/** /**
* A device that expects to receive input from the vnc server should derrive * A device that expects to receive input from the vnc server should derrive
* (through mulitple inheritence if necessary from VncKeyboard or VncMouse * (through mulitple inheritence if necessary from VncKeyboard or VncMouse
@ -219,7 +221,7 @@ class VncInput : public SimObject
int captureCurrentFrame; int captureCurrentFrame;
/** Directory to store captured frames to */ /** Directory to store captured frames to */
std::string captureOutputDirectory; OutputDirectory *captureOutputDirectory;
/** Computed hash of the last captured frame */ /** Computed hash of the last captured frame */
uint64_t captureLastHash; uint64_t captureLastHash;

View file

@ -218,9 +218,7 @@ BaseCPU::BaseCPU(Params *p, bool is_checker)
functionTracingEnabled = false; functionTracingEnabled = false;
if (p->function_trace) { if (p->function_trace) {
const string fname = csprintf("ftrace.%s", name()); const string fname = csprintf("ftrace.%s", name());
functionTraceStream = simout.find(fname); functionTraceStream = simout.findOrCreate(fname)->stream();
if (!functionTraceStream)
functionTraceStream = simout.create(fname);
currentFunctionStart = currentFunctionEnd = 0; currentFunctionStart = currentFunctionEnd = 0;
functionEntryTick = p->function_trace_start; functionEntryTick = p->function_trace_start;

View file

@ -144,8 +144,10 @@ struct O3ThreadState : public ThreadState {
void dumpFuncProfile() void dumpFuncProfile()
{ {
std::ostream *os = simout.create(csprintf("profile.%s.dat", cpu->name())); OutputStream *os(
profile->dump(tc, *os); simout.create(csprintf("profile.%s.dat", cpu->name())));
profile->dump(tc, *os->stream());
simout.close(os);
} }
}; };

View file

@ -126,13 +126,13 @@ SimPoint::profile(const std::pair<SimpleThread*, StaticInstPtr>& p)
std::sort(counts.begin(), counts.end()); std::sort(counts.begin(), counts.end());
// Print output BBV info // Print output BBV info
*simpointStream << "T"; *simpointStream->stream() << "T";
for (auto cnt_itr = counts.begin(); cnt_itr != counts.end(); for (auto cnt_itr = counts.begin(); cnt_itr != counts.end();
++cnt_itr) { ++cnt_itr) {
*simpointStream << ":" << cnt_itr->first *simpointStream->stream() << ":" << cnt_itr->first
<< ":" << cnt_itr->second << " "; << ":" << cnt_itr->second << " ";
} }
*simpointStream << "\n"; *simpointStream->stream() << "\n";
intervalDrift = (intervalCount + intervalDrift) - intervalSize; intervalDrift = (intervalCount + intervalDrift) - intervalSize;
intervalCount = 0; intervalCount = 0;

View file

@ -43,6 +43,7 @@
#include <unordered_map> #include <unordered_map>
#include "base/output.hh"
#include "cpu/simple_thread.hh" #include "cpu/simple_thread.hh"
#include "params/SimPoint.hh" #include "params/SimPoint.hh"
#include "sim/probe/probe.hh" #include "sim/probe/probe.hh"
@ -97,7 +98,7 @@ class SimPoint : public ProbeListenerObject
/** Excess inst count from previous interval*/ /** Excess inst count from previous interval*/
uint64_t intervalDrift; uint64_t intervalDrift;
/** Pointer to SimPoint BBV output stream */ /** Pointer to SimPoint BBV output stream */
std::ostream *simpointStream; OutputStream *simpointStream;
/** Basic Block information */ /** Basic Block information */
struct BBInfo { struct BBInfo {

View file

@ -154,9 +154,9 @@ SimpleThread::startup()
void void
SimpleThread::dumpFuncProfile() SimpleThread::dumpFuncProfile()
{ {
std::ostream *os = simout.create(csprintf("profile.%s.dat", OutputStream *os(simout.create(csprintf("profile.%s.dat", baseCpu->name())));
baseCpu->name())); profile->dump(tc, *os->stream());
profile->dump(tc, *os); simout.close(os);
} }
void void

View file

@ -544,8 +544,8 @@ HDLcd::pxlFrameDone()
} }
assert(pic); assert(pic);
pic->seekp(0); pic->stream()->seekp(0);
bmp.write(*pic); bmp.write(*pic->stream());
} }
} }

View file

@ -81,6 +81,7 @@
#include "base/bitmap.hh" #include "base/bitmap.hh"
#include "base/framebuffer.hh" #include "base/framebuffer.hh"
#include "base/output.hh"
#include "dev/arm/amba_device.hh" #include "dev/arm/amba_device.hh"
#include "dev/pixelpump.hh" #include "dev/pixelpump.hh"
#include "sim/serialize.hh" #include "sim/serialize.hh"
@ -347,7 +348,7 @@ class HDLcd: public AmbaDmaDevice
Bitmap bmp; Bitmap bmp;
/** Picture of what the current frame buffer looks like */ /** Picture of what the current frame buffer looks like */
std::ostream *pic; OutputStream *pic;
/** Cached pixel converter, set when the converter is enabled. */ /** Cached pixel converter, set when the converter is enabled. */
PixelConverter conv; PixelConverter conv;

View file

@ -523,11 +523,12 @@ Pl111::dmaDone()
DPRINTF(PL111, "-- write out frame buffer into bmp\n"); DPRINTF(PL111, "-- write out frame buffer into bmp\n");
if (!pic) if (!pic)
pic = simout.create(csprintf("%s.framebuffer.bmp", sys->name()), true); pic = simout.create(csprintf("%s.framebuffer.bmp", sys->name()),
true);
assert(pic); assert(pic);
pic->seekp(0); pic->stream()->seekp(0);
bmp.write(*pic); bmp.write(*pic->stream());
} }
// schedule the next read based on when the last frame started // schedule the next read based on when the last frame started

View file

@ -51,6 +51,7 @@
#include "base/bitmap.hh" #include "base/bitmap.hh"
#include "base/framebuffer.hh" #include "base/framebuffer.hh"
#include "base/output.hh"
#include "dev/arm/amba_device.hh" #include "dev/arm/amba_device.hh"
#include "params/Pl111.hh" #include "params/Pl111.hh"
#include "sim/serialize.hh" #include "sim/serialize.hh"
@ -268,7 +269,7 @@ class Pl111: public AmbaDmaDevice
Bitmap bmp; Bitmap bmp;
/** Picture of what the current frame buffer looks like */ /** Picture of what the current frame buffer looks like */
std::ostream *pic; OutputStream *pic;
/** Frame buffer width - pixels per line */ /** Frame buffer width - pixels per line */
uint16_t width; uint16_t width;

View file

@ -45,7 +45,7 @@
using std::string; using std::string;
EtherDump::EtherDump(const Params *p) EtherDump::EtherDump(const Params *p)
: SimObject(p), stream(simout.create(p->file, true)), : SimObject(p), stream(simout.create(p->file, true)->stream()),
maxlen(p->maxlen) maxlen(p->maxlen)
{ {
} }

View file

@ -108,18 +108,14 @@ Terminal::DataEvent::process(int revent)
*/ */
Terminal::Terminal(const Params *p) Terminal::Terminal(const Params *p)
: SimObject(p), termDataAvail(NULL), listenEvent(NULL), dataEvent(NULL), : SimObject(p), termDataAvail(NULL), listenEvent(NULL), dataEvent(NULL),
number(p->number), data_fd(-1), txbuf(16384), rxbuf(16384), outfile(NULL) number(p->number), data_fd(-1), txbuf(16384), rxbuf(16384),
outfile(p->output ? simout.findOrCreate(p->name) : NULL)
#if TRACING_ON == 1 #if TRACING_ON == 1
, linebuf(16384) , linebuf(16384)
#endif #endif
{ {
if (p->output) { if (outfile)
outfile = simout.find(p->name); outfile->stream()->setf(ios::unitbuf);
if (!outfile)
outfile = simout.create(p->name);
outfile->setf(ios::unitbuf);
}
if (p->port) if (p->port)
listen(p->port); listen(p->port);
@ -347,7 +343,7 @@ Terminal::out(char c)
write(c); write(c);
if (outfile) if (outfile)
outfile->write(&c, 1); outfile->stream()->write(&c, 1);
DPRINTF(TerminalVerbose, "out: \'%c\' %#02x\n", DPRINTF(TerminalVerbose, "out: \'%c\' %#02x\n",
isprint(c) ? c : ' ', (int)c); isprint(c) ? c : ' ', (int)c);

View file

@ -46,6 +46,7 @@
#include "params/Terminal.hh" #include "params/Terminal.hh"
#include "sim/sim_object.hh" #include "sim/sim_object.hh"
class OutputStream;
class TerminalListener; class TerminalListener;
class Terminal : public SimObject class Terminal : public SimObject
@ -111,7 +112,7 @@ class Terminal : public SimObject
protected: protected:
CircleBuf<char> txbuf; CircleBuf<char> txbuf;
CircleBuf<char> rxbuf; CircleBuf<char> rxbuf;
std::ostream *outfile; OutputStream *outfile;
#if TRACING_ON == 1 #if TRACING_ON == 1
CircleBuf<char> linebuf; CircleBuf<char> linebuf;
#endif #endif

View file

@ -38,12 +38,12 @@
inline void inline void
output(const char *filename) output(const char *filename)
{ {
std::ostream *file_stream = simout.find(filename); OutputStream *file_stream = simout.find(filename);
if (!file_stream) if (!file_stream)
file_stream = simout.create(filename); file_stream = simout.create(filename);
Trace::setDebugLogger(new Trace::OstreamLogger(*file_stream)); Trace::setDebugLogger(new Trace::OstreamLogger(*file_stream->stream()));
} }
inline void inline void

View file

@ -592,7 +592,6 @@ writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset,
{ {
DPRINTF(PseudoInst, "PseudoInst::writefile(0x%x, 0x%x, 0x%x, 0x%x)\n", DPRINTF(PseudoInst, "PseudoInst::writefile(0x%x, 0x%x, 0x%x, 0x%x)\n",
vaddr, len, offset, filename_addr); vaddr, len, offset, filename_addr);
ostream *os;
// copy out target filename // copy out target filename
char fn[100]; char fn[100];
@ -600,16 +599,18 @@ writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset,
CopyStringOut(tc, fn, filename_addr, 100); CopyStringOut(tc, fn, filename_addr, 100);
filename = std::string(fn); filename = std::string(fn);
OutputStream *out;
if (offset == 0) { if (offset == 0) {
// create a new file (truncate) // create a new file (truncate)
os = simout.create(filename, true, true); out = simout.create(filename, true, true);
} else { } else {
// do not truncate file if offset is non-zero // do not truncate file if offset is non-zero
// (ios::in flag is required as well to keep the existing data // (ios::in flag is required as well to keep the existing data
// intact, otherwise existing data will be zeroed out.) // intact, otherwise existing data will be zeroed out.)
os = simout.openFile(simout.directory() + filename, out = simout.open(filename, ios::in | ios::out | ios::binary, true);
ios::in | ios::out | ios::binary, true);
} }
ostream *os(out->stream());
if (!os) if (!os)
panic("could not open file %s\n", filename); panic("could not open file %s\n", filename);
@ -623,7 +624,7 @@ writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset,
if (os->fail() || os->bad()) if (os->fail() || os->bad())
panic("Error while doing writefile!\n"); panic("Error while doing writefile!\n");
simout.close(os); simout.close(out);
delete [] buf; delete [] buf;