gem5 v24.0.0.0
Loading...
Searching...
No Matches
gem5::OutputDirectory Class Reference

Interface for creating files in a gem5 output directory. More...

#include <output.hh>

Public Member Functions

 OutputDirectory ()
 Constructor.
 
 OutputDirectory (const std::string &name)
 Constructor.
 
 ~OutputDirectory ()
 Destructor.
 
std::string resolve (const std::string &name) const
 Returns relative file names prepended with name of this directory.
 
void setDirectory (const std::string &dir)
 Sets name of this directory.
 
const std::string & directory () const
 Gets name of this directory.
 
OutputStreamcreate (const std::string &name, bool binary=false, bool no_gz=false)
 Creates a file in this directory (optionally compressed).
 
OutputStreamopen (const std::string &name, std::ios_base::openmode mode, bool recreateable=true, bool no_gz=false)
 Open a file in this directory (optionally compressed).
 
void close (OutputStream *file)
 Closes an output file and free the corresponding OutputFile.
 
OutputStreamfind (const std::string &name) const
 Finds stream associated with an open file or stdout/stderr.
 
OutputStreamfindOrCreate (const std::string &name, bool binary=false)
 
bool isFile (const std::string &name) const
 Determines whether a file name corresponds to a file in this directory.
 
OutputDirectorycreateSubdirectory (const std::string &name)
 Creates a subdirectory within this directory.
 
void remove (const std::string &name, bool recursive=false)
 Removes a specified file or subdirectory.
 

Static Public Member Functions

static bool isAbsolute (const std::string &name)
 Test if a path is absolute.
 

Static Protected Member Functions

static OutputStreamcheckForStdio (const std::string &name)
 Determines whether given file name corresponds to standard output streams.
 

Private Types

typedef std::map< std::string, OutputStream * > file_map_t
 File names and associated stream handles.
 
typedef std::map< std::string, OutputDirectory * > dir_map_t
 Output subdirectories.
 

Private Attributes

file_map_t files
 Open file streams within this directory.
 
dir_map_t dirs
 Output sub-directories.
 
std::string dir
 Name of this directory.
 

Static Private Attributes

static const char PATH_SEPARATOR = '/'
 System-specific path separator character.
 
static OutputStream stdout
 
static OutputStream stderr
 

Detailed Description

Interface for creating files in a gem5 output directory.

Definition at line 137 of file output.hh.

Member Typedef Documentation

◆ dir_map_t

typedef std::map<std::string, OutputDirectory *> gem5::OutputDirectory::dir_map_t
private

Output subdirectories.

Definition at line 144 of file output.hh.

◆ file_map_t

typedef std::map<std::string, OutputStream *> gem5::OutputDirectory::file_map_t
private

File names and associated stream handles.

Definition at line 141 of file output.hh.

Constructor & Destructor Documentation

◆ OutputDirectory() [1/2]

gem5::OutputDirectory::OutputDirectory ( )

Constructor.

Definition at line 118 of file output.cc.

Referenced by createSubdirectory().

◆ OutputDirectory() [2/2]

gem5::OutputDirectory::OutputDirectory ( const std::string & name)

Constructor.

Definition at line 121 of file output.cc.

References name(), and setDirectory().

◆ ~OutputDirectory()

gem5::OutputDirectory::~OutputDirectory ( )

Destructor.

Definition at line 126 of file output.cc.

References gem5::ArmISA::f, and files.

Member Function Documentation

◆ checkForStdio()

OutputStream * gem5::OutputDirectory::checkForStdio ( const std::string & name)
staticprotected

Determines whether given file name corresponds to standard output streams.

Parameters
namename of file to check
Returns
output stream for standard output or error stream if name corresponds to one or the other; NULL otherwise

Definition at line 135 of file output.cc.

References name(), stderr, and stdout.

Referenced by create(), and find().

◆ close()

void gem5::OutputDirectory::close ( OutputStream * 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.

Parameters
fileOutputStream instance in this OutputDirectory.

Definition at line 147 of file output.cc.

References fatal, files, gem5::ArmISA::i, gem5::OutputStream::name(), stderr, stdout, and gem5::OutputStream::stream().

Referenced by gem5::VncInput::captureFrameBuffer(), gem5::linux::PanicOrOopsEvent::process(), gem5::pseudo_inst::writefile(), gem5::ProtocolTester::~ProtocolTester(), gem5::SimPoint::~SimPoint(), and sc_gem5::TraceFile::~TraceFile().

◆ create()

OutputStream * gem5::OutputDirectory::create ( const std::string & name,
bool binary = false,
bool no_gz = false )

Creates a file in this directory (optionally compressed).

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.

Parameters
namename of file to create (without this directory's name leading it)
binarytrue to create a binary file; false otherwise
no_gztrue to disable opening the file as a gzip compressed output stream; false otherwise
Returns
OutputStream instance representing the created file

Definition at line 210 of file output.cc.

References checkForStdio(), isAbsolute(), gem5::ArmISA::mode, name(), and open().

Referenced by gem5::VncInput::captureFrameBuffer(), gem5::Pl111::dmaDone(), gem5::ComputeUnit::exitCallback(), gem5::X86ISA::GpuTLB::exitCallback(), findOrCreate(), gem5::output(), gem5::linux::PanicOrOopsEvent::process(), gem5::ProtocolTester::ProtocolTester(), gem5::HDLcd::pxlFrameDone(), gem5::SimPoint::SimPoint(), gem5::ArmISA::FsLinux::startup(), and gem5::pseudo_inst::writefile().

◆ createSubdirectory()

OutputDirectory * gem5::OutputDirectory::createSubdirectory ( const std::string & name)

Creates a subdirectory within this directory.

Parameters
namename of subdirectory
Returns
the new subdirectory's name suffixed with a path separator

Definition at line 283 of file output.cc.

References dir, directory(), dirs, fatal, name(), OutputDirectory(), and resolve().

Referenced by gem5::VncInput::VncInput().

◆ directory()

const std::string & gem5::OutputDirectory::directory ( ) const

Gets name of this directory.

Returns
name of this directory

Definition at line 195 of file output.cc.

References dir, and panic.

Referenced by createSubdirectory(), and remove().

◆ find()

OutputStream * gem5::OutputDirectory::find ( const std::string & name) const

Finds stream associated with an open file or stdout/stderr.

Parameters
nameof file
Returns
stream to specified file or NULL if file does not exist

Definition at line 247 of file output.cc.

References checkForStdio(), files, gem5::ArmISA::i, and name().

Referenced by findOrCreate(), isFile(), and gem5::output().

◆ findOrCreate()

OutputStream * gem5::OutputDirectory::findOrCreate ( const std::string & name,
bool binary = false )

Definition at line 262 of file output.cc.

References create(), find(), name(), and gem5::X86ISA::os.

Referenced by gem5::statistics::initText(), and gem5::Terminal::terminalDump().

◆ isAbsolute()

static bool gem5::OutputDirectory::isAbsolute ( const std::string & name)
inlinestatic

Test if a path is absolute.

Definition at line 277 of file output.hh.

References name(), and PATH_SEPARATOR.

Referenced by create(), resolve(), and gem5::VirtIO9PDiod::startDiod().

◆ isFile()

bool gem5::OutputDirectory::isFile ( const std::string & name) const

Determines whether a file name corresponds to a file in this directory.

Parameters
namename of file to evaluate
Returns
true iff file has been opened in this directory or exists on the file system within this directory

Definition at line 272 of file output.cc.

References find(), name(), and gem5::ArmISA::st.

Referenced by remove().

◆ open()

OutputStream * gem5::OutputDirectory::open ( const std::string & name,
std::ios_base::openmode mode,
bool recreateable = true,
bool no_gz = false )

Open a file in this directory (optionally compressed).

Will open a file as a compressed stream if filename ends in .gz, unless explicitly disabled.

Parameters
filenamefile to open
modeattributes to open file with
recreateableSet to true if the file can be recreated in a new location.
no_gztrue to disable opening the file as a gzip compressed output stream; false otherwise
Returns
OutputStream instance representing the opened file

Definition at line 224 of file output.cc.

References files, gem5::ArmISA::mode, name(), and gem5::X86ISA::os.

Referenced by create(), and gem5::pseudo_inst::writefile().

◆ remove()

void gem5::OutputDirectory::remove ( const std::string & name,
bool recursive = false )

Removes a specified file or subdirectory.

Will cause sim to fail for most errors. However, it will only warn the user if a directory could not be removed. This is in place to accommodate slow file systems where file deletions within a subdirectory may not be recognized quickly enough thereby causing the subsequent call to remove the directory to fail (seemingly unempty directory).

Parameters
namename of file or subdirectory to remove; name should not be prepended with the name of this directory object
recursiveset to true to attempt to recursively delete a subdirectory and its contents

Definition at line 296 of file output.cc.

References gem5::X86ISA::de, directory(), fatal, files, gem5::ArmISA::i, isFile(), name(), PATH_SEPARATOR, remove(), and resolve().

Referenced by remove(), and gem5::VncInput::VncInput().

◆ resolve()

std::string gem5::OutputDirectory::resolve ( const std::string & name) const

Returns relative file names prepended with name of this directory.

Returns absolute file names unaltered.

Parameters
namefile name to prepend with directory name
Returns
file name prepended with base directory name or unaltered absolute file name

Definition at line 204 of file output.cc.

References dir, isAbsolute(), and name().

Referenced by gem5::BaseSemihosting::callTmpNam(), createSubdirectory(), gem5::trace::InstPBTrace::createTraceFile(), gem5::statistics::initHDF5(), gem5::ListenSocketUnixFile::listen(), gem5::MemTraceProbe::MemTraceProbe(), gem5::FDArray::openOutputFile(), gem5::OutputFile< StreamType >::OutputFile(), gem5::OutputFile< StreamType >::relocate(), remove(), and gem5::VirtIO9PDiod::startDiod().

◆ setDirectory()

void gem5::OutputDirectory::setDirectory ( const std::string & dir)

Sets name of this directory.

Parameters
dirname of this directory

Definition at line 164 of file output.cc.

References gem5::ArmISA::d, dir, dirs, fatal, files, gem5::ArmISA::i, and PATH_SEPARATOR.

Referenced by OutputDirectory(), and gem5::setOutputDir().

Member Data Documentation

◆ dir

std::string gem5::OutputDirectory::dir
private

Name of this directory.

Definition at line 153 of file output.hh.

Referenced by createSubdirectory(), directory(), resolve(), and setDirectory().

◆ dirs

dir_map_t gem5::OutputDirectory::dirs
private

Output sub-directories.

Definition at line 150 of file output.hh.

Referenced by createSubdirectory(), and setDirectory().

◆ files

file_map_t gem5::OutputDirectory::files
private

Open file streams within this directory.

Definition at line 147 of file output.hh.

Referenced by close(), find(), open(), remove(), setDirectory(), and ~OutputDirectory().

◆ PATH_SEPARATOR

const char gem5::OutputDirectory::PATH_SEPARATOR = '/'
staticprivate

System-specific path separator character.

Definition at line 156 of file output.hh.

Referenced by isAbsolute(), remove(), and setDirectory().

◆ stderr

OutputStream gem5::OutputDirectory::stderr
staticprivate

Definition at line 159 of file output.hh.

Referenced by checkForStdio(), and close().

◆ stdout

OutputStream gem5::OutputDirectory::stdout
staticprivate

Definition at line 158 of file output.hh.

Referenced by checkForStdio(), and close().


The documentation for this class was generated from the following files:

Generated on Tue Jun 18 2024 16:24:13 for gem5 by doxygen 1.11.0