summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorGabe Black <gblack@eecs.umich.edu>2012-01-07 02:15:35 -0800
committerGabe Black <gblack@eecs.umich.edu>2012-01-07 02:15:35 -0800
commitec936364b7238cddea7734ea79c6e04b52a683c6 (patch)
tree788fc19c3ba599d6f39d3990769888a0650be5ff /src/base
parent36a822f08e88483b41af214ace4fd3dccf3aa8cb (diff)
parent9b52717a92ed9592bd98a41683509f538262a5c7 (diff)
downloadgem5-ec936364b7238cddea7734ea79c6e04b52a683c6.tar.xz
Merge with the main repository again.
Diffstat (limited to 'src/base')
-rw-r--r--src/base/bitmap.cc44
-rw-r--r--src/base/bitmap.hh15
-rw-r--r--src/base/compiler.hh2
-rw-r--r--src/base/output.cc140
-rw-r--r--src/base/output.hh121
-rw-r--r--src/base/stats/text.cc6
-rw-r--r--src/base/trace.cc2
-rw-r--r--src/base/vnc/VncServer.py1
-rw-r--r--src/base/vnc/convert.cc23
-rw-r--r--src/base/vnc/convert.hh18
-rw-r--r--src/base/vnc/vncserver.cc54
-rw-r--r--src/base/vnc/vncserver.hh22
12 files changed, 407 insertions, 41 deletions
diff --git a/src/base/bitmap.cc b/src/base/bitmap.cc
index 0d2a9302b..08425d74f 100644
--- a/src/base/bitmap.cc
+++ b/src/base/bitmap.cc
@@ -36,6 +36,7 @@
*
* Authors: William Wang
* Ali Saidi
+ * Chris Emmons
*/
#include <cassert>
@@ -43,29 +44,50 @@
#include "base/bitmap.hh"
#include "base/misc.hh"
+const size_t Bitmap::sizeofHeaderBuffer = sizeof(Magic) + sizeof(Header) +
+ sizeof(Info);
+
// bitmap class ctor
Bitmap::Bitmap(VideoConvert::Mode _mode, uint16_t w, uint16_t h, uint8_t *d)
: mode(_mode), height(h), width(w), data(d),
- vc(mode, VideoConvert::rgb8888, width, height)
+ vc(mode, VideoConvert::rgb8888, width, height), headerBuffer(0)
{
}
+Bitmap::~Bitmap() {
+ if (headerBuffer)
+ delete [] headerBuffer;
+}
+
void
-Bitmap::write(std::ostream *bmp)
+Bitmap::write(std::ostream *bmp) const
{
assert(data);
- // For further information see: http://en.wikipedia.org/wiki/BMP_file_format
- Magic magic = {{'B','M'}};
- Header header = {sizeof(VideoConvert::Rgb8888) * width * height , 0, 0, 54};
- Info info = {sizeof(Info), width, height, 1,
- sizeof(VideoConvert::Rgb8888) * 8, 0,
- sizeof(VideoConvert::Rgb8888) * width * height, 1, 1, 0, 0};
+ // header is always the same for a bitmap object; compute the info once per
+ // bitmap object
+ if (!headerBuffer) {
+ // For further information see:
+ // http://en.wikipedia.org/wiki/BMP_file_format
+ Magic magic = {{'B','M'}};
+ Header header = {sizeof(VideoConvert::Rgb8888) * width * height,
+ 0, 0, 54};
+ Info info = {sizeof(Info), width, height, 1,
+ sizeof(VideoConvert::Rgb8888) * 8, 0,
+ sizeof(VideoConvert::Rgb8888) * width * height, 1, 1, 0, 0};
+
+ char *p = headerBuffer = new char[sizeofHeaderBuffer];
+ memcpy(p, &magic, sizeof(Magic));
+ p += sizeof(Magic);
+ memcpy(p, &header, sizeof(Header));
+ p += sizeof(Header);
+ memcpy(p, &info, sizeof(Info));
+ }
- bmp->write(reinterpret_cast<char*>(&magic), sizeof(magic));
- bmp->write(reinterpret_cast<char*>(&header), sizeof(header));
- bmp->write(reinterpret_cast<char*>(&info), sizeof(info));
+ // 1. write the header
+ bmp->write(headerBuffer, sizeofHeaderBuffer);
+ // 2. write the bitmap data
uint8_t *tmp = vc.convert(data);
uint32_t *tmp32 = (uint32_t*)tmp;
diff --git a/src/base/bitmap.hh b/src/base/bitmap.hh
index 9dfaa87a1..e9ad15473 100644
--- a/src/base/bitmap.hh
+++ b/src/base/bitmap.hh
@@ -36,6 +36,7 @@
*
* Authors: William Wang
* Ali Saidi
+ * Chris Emmons
*/
#ifndef __BASE_BITMAP_HH__
#define __BASE_BITMAP_HH__
@@ -62,6 +63,9 @@ class Bitmap
*/
Bitmap(VideoConvert::Mode mode, uint16_t w, uint16_t h, uint8_t *d);
+ /** Destructor */
+ ~Bitmap();
+
/** Provide the converter with the data that should be output. It will be
* converted into rgb8888 and write out when write() is called.
* @param d the data
@@ -71,7 +75,13 @@ class Bitmap
/** Write the provided data into the fstream provided
* @param bmp stream to write to
*/
- void write(std::ostream *bmp);
+ void write(std::ostream *bmp) const;
+
+ /** Gets a hash over the bitmap for quick comparisons to other bitmaps.
+ * @return hash of the bitmap
+ */
+ uint64_t getHash() const { return vc.getHash(data); }
+
private:
VideoConvert::Mode mode;
@@ -81,6 +91,9 @@ class Bitmap
VideoConvert vc;
+ mutable char *headerBuffer;
+ static const size_t sizeofHeaderBuffer;
+
struct Magic
{
unsigned char magic_number[2];
diff --git a/src/base/compiler.hh b/src/base/compiler.hh
index 3315fb2f7..a95cb791c 100644
--- a/src/base/compiler.hh
+++ b/src/base/compiler.hh
@@ -42,6 +42,7 @@
#define M5_DUMMY_RETURN
#define M5_VAR_USED __attribute__((unused))
#define M5_ATTR_PACKED __attribute__ ((__packed__))
+#define M5_NO_INLINE __attribute__ ((__noinline__))
#elif defined(__SUNPRO_CC)
// this doesn't do anything with sun cc, but why not
#define M5_ATTR_NORETURN __sun_attr__((__noreturn__))
@@ -50,6 +51,7 @@
#define M5_VAR_USED
#define M5_PRAGMA_NORETURN(x) DO_PRAGMA(does_not_return(x))
#define M5_ATTR_PACKED __attribute__ ((__packed__))
+#define M5_NO_INLINE __attribute__ ((__noinline__))
#else
#error "Need to define compiler options in base/compiler.hh"
#endif
diff --git a/src/base/output.cc b/src/base/output.cc
index 020247152..1c749e5bf 100644
--- a/src/base/output.cc
+++ b/src/base/output.cc
@@ -26,11 +26,14 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Nathan Binkert
+ * Chris Emmons
*/
#include <sys/stat.h>
#include <sys/types.h>
+#include <dirent.h>
+#include <cassert>
#include <cerrno>
#include <climits>
#include <cstdlib>
@@ -46,7 +49,7 @@ using namespace std;
OutputDirectory simout;
/**
- *
+ * @file This file manages creating / deleting output files for the simulator.
*/
OutputDirectory::OutputDirectory()
{}
@@ -73,26 +76,54 @@ OutputDirectory::checkForStdio(const string &name) const
ostream *
OutputDirectory::openFile(const string &filename,
- ios_base::openmode mode) const
+ ios_base::openmode mode)
{
if (filename.find(".gz", filename.length()-3) < filename.length()) {
ogzstream *file = new ogzstream(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
+OutputDirectory::close(ostream *openStream) {
+ map_t::iterator i;
+ for (i = files.begin(); i != files.end(); i++) {
+ if (i->second != openStream)
+ continue;
+
+ ofstream *fs = dynamic_cast<ofstream*>(i->second);
+ if (fs) {
+ fs->close();
+ delete i->second;
+ break;
+ } else {
+ ogzstream *gfs = dynamic_cast<ogzstream*>(i->second);
+ if (gfs) {
+ gfs->close();
+ delete i->second;
+ break;
+ }
+ }
+ }
+
+ if (i == files.end())
+ fatal("Attempted to close an unregistred file stream");
+
+ files.erase(i);
+}
+
+void
OutputDirectory::setDirectory(const string &d)
{
if (!dir.empty())
@@ -100,9 +131,9 @@ OutputDirectory::setDirectory(const string &d)
dir = d;
- // guarantee that directory ends with a '/'
- if (dir[dir.size() - 1] != '/')
- dir += "/";
+ // guarantee that directory ends with a path separator
+ if (dir[dir.size() - 1] != PATH_SEPARATOR)
+ dir += PATH_SEPARATOR;
}
const string &
@@ -117,7 +148,7 @@ OutputDirectory::directory() const
inline string
OutputDirectory::resolve(const string &name) const
{
- return (name[0] != '/') ? dir + name : name;
+ return (name[0] != PATH_SEPARATOR) ? dir + name : name;
}
ostream *
@@ -136,20 +167,18 @@ OutputDirectory::create(const string &name, bool binary)
}
ostream *
-OutputDirectory::find(const string &name)
+OutputDirectory::find(const string &name) const
{
ostream *file = checkForStdio(name);
if (file)
return file;
- string filename = resolve(name);
- map_t::iterator i = files.find(filename);
+ const string filename = resolve(name);
+ map_t::const_iterator i = files.find(filename);
if (i != files.end())
return (*i).second;
- file = openFile(filename);
- files[filename] = file;
- return file;
+ return NULL;
}
bool
@@ -157,3 +186,82 @@ OutputDirectory::isFile(const std::ostream *os)
{
return os && os != &cerr && os != &cout;
}
+
+bool
+OutputDirectory::isFile(const string &name) const
+{
+ // definitely a file if in our data structure
+ if (find(name) != NULL) return true;
+
+ struct stat st_buf;
+ int st = stat(name.c_str(), &st_buf);
+ return (st == 0) && S_ISREG(st_buf.st_mode);
+}
+
+string
+OutputDirectory::createSubdirectory(const string &name) const
+{
+ const string new_dir = resolve(name);
+ if (new_dir.find(directory()) == string::npos)
+ 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
+ if ((mkdir(new_dir.c_str(), 0755) != 0) && (errno != EEXIST))
+ fatal("Failed to create new output subdirectory '%s'\n", new_dir);
+
+ return name + PATH_SEPARATOR;
+}
+
+void
+OutputDirectory::remove(const string &name, bool recursive)
+{
+ const string fname = resolve(name);
+
+ if (fname.find(directory()) == string::npos)
+ fatal("Attempting to remove file/dir not in output dir\n");
+
+ if (isFile(fname)) {
+ // close and release file if we have it open
+ map_t::iterator itr = files.find(fname);
+ if (itr != files.end()) {
+ delete itr->second;
+ files.erase(itr);
+ }
+
+ if (::remove(fname.c_str()) != 0)
+ fatal("Could not erase file '%s'\n", fname);
+ } else {
+ // assume 'name' is a directory
+ if (recursive) {
+ DIR *dir = opendir(fname.c_str());
+
+ // silently ignore removal request for non-existent directory
+ if ((!dir) && (errno == ENOENT))
+ return;
+
+ // fail on other errors
+ if (!dir) {
+ perror("opendir");
+ fatal("Error opening directory for recursive removal '%s'\n",
+ fname);
+ }
+
+ struct dirent *de = readdir(dir);
+ while (de != NULL) {
+ // ignore files starting with a '.'; user must delete those
+ // manually if they really want to
+ if (de->d_name[0] != '.')
+ remove(name + PATH_SEPARATOR + de->d_name, recursive);
+
+ de = readdir(dir);
+ }
+ }
+
+ // try to force recognition that we deleted the files in the directory
+ sync();
+
+ if (::remove(fname.c_str()) != 0) {
+ perror("Warning! 'remove' failed. Could not erase directory.");
+ }
+ }
+}
diff --git a/src/base/output.hh b/src/base/output.hh
index 38c63714c..b86e68856 100644
--- a/src/base/output.hh
+++ b/src/base/output.hh
@@ -26,6 +26,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Nathan Binkert
+ * Chris Emmons
*/
#ifndef __BASE_OUTPUT_HH__
@@ -35,33 +36,147 @@
#include <map>
#include <string>
+/** Interface for creating files in a gem5 output directory. */
class OutputDirectory
{
private:
+ /** File names and associated stream handles */
typedef std::map<std::string, std::ostream *> map_t;
+ /** Open file streams within this directory */
map_t files;
+
+ /** Name of this directory */
std::string dir;
+ /** System-specific path separator character */
+ static const char PATH_SEPARATOR = '/';
+
+ /**
+ * Returns relative file names prepended with name of this directory.
+ * Returns absolute file names unaltered.
+ *
+ * @param name file name to prepend with directory name
+ * @return file name prepended with base directory name or unaltered
+ * absolute file name
+ */
std::string resolve(const std::string &name) const;
protected:
+ /**
+ * Determines whether given file name corresponds to standard output
+ * streams.
+ *
+ * @param name name of file to check
+ * @return output stream for standard output or error stream if name
+ * corresponds to one or the other; NULL otherwise
+ */
std::ostream *checkForStdio(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
+ * @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) const;
+ std::ios_base::openmode mode = std::ios::trunc);
public:
+ /** Constructor. */
OutputDirectory();
+
+ /** Destructor. */
~OutputDirectory();
+ /**
+ * Sets name of this directory.
+ * @param dir name of this directory
+ */
void setDirectory(const std::string &dir);
+
+ /**
+ * Gets name of this directory.
+ * @return name of this directory
+ */
const std::string &directory() const;
+ /**
+ * Creates a file in this directory (optionally compressed).
+ *
+ * Will open a file as a compressed stream if filename ends in .gz.
+ *
+ * @param name name of file to create (without this directory's name
+ * leading it)
+ * @param binary true to create a binary file; false otherwise
+ * @return stream to the opened file
+ */
std::ostream *create(const std::string &name, bool binary = false);
- std::ostream *find(const std::string &name);
+ /**
+ * Closes a file stream.
+ *
+ * Stream must have been opened through this interface, or sim will fail.
+ *
+ * @param openStream open stream to close
+ */
+ void close(std::ostream *openStream);
+
+ /**
+ * Finds stream associated with a file.
+ * @param name of file
+ * @return stream to specified file or NULL if file does not exist
+ */
+ std::ostream *find(const std::string &name) const;
+
+ /**
+ * 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);
- static inline bool isFile(const std::ostream &os) { return isFile(&os); }
+
+ /**
+ * Determines whether a file name corresponds to a file in this directory.
+ * @param name name of file to evaluate
+ * @return true iff file has been opened in this directory or exists on the
+ * file system within this directory
+ */
+ bool isFile(const std::string &name) const;
+
+ /**
+ * 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 inline bool isFile(const std::ostream &os) {
+ return isFile(&os);
+ }
+
+ /**
+ * Creates a subdirectory within this directory.
+ * @param name name of subdirectory
+ * @return the new subdirectory's name suffixed with a path separator
+ */
+ std::string createSubdirectory(const std::string &name) const;
+
+ /**
+ * 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).
+ *
+ * @param name name of file or subdirectory to remove; name should not
+ * be prepended with the name of this directory object
+ * @param recursive set to true to attempt to recursively delete a
+ * subdirectory and its contents
+ */
+ void remove(const std::string &name, bool recursive=false);
};
extern OutputDirectory simout;
diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc
index f8471f1a1..683ba7fe4 100644
--- a/src/base/stats/text.cc
+++ b/src/base/stats/text.cc
@@ -674,7 +674,11 @@ initText(const string &filename, bool desc)
static bool connected = false;
if (!connected) {
- text.open(*simout.find(filename));
+ ostream *os = simout.find(filename);
+ if (!os)
+ os = simout.create(filename);
+
+ text.open(*os);
text.descriptions = desc;
connected = true;
}
diff --git a/src/base/trace.cc b/src/base/trace.cc
index 1a035d400..fa55e42a9 100644
--- a/src/base/trace.cc
+++ b/src/base/trace.cc
@@ -64,6 +64,8 @@ void
setOutput(const string &filename)
{
dprintf_stream = simout.find(filename);
+ if (!dprintf_stream)
+ dprintf_stream = simout.create(filename);
}
ObjectMatch ignore;
diff --git a/src/base/vnc/VncServer.py b/src/base/vnc/VncServer.py
index 21eb3ed28..6b746f2e2 100644
--- a/src/base/vnc/VncServer.py
+++ b/src/base/vnc/VncServer.py
@@ -43,3 +43,4 @@ class VncServer(SimObject):
type = 'VncServer'
port = Param.TcpPort(5900, "listen port")
number = Param.Int(0, "vnc client number")
+ frame_capture = Param.Bool(False, "capture changed frames to files")
diff --git a/src/base/vnc/convert.cc b/src/base/vnc/convert.cc
index cd1502ce6..915a99407 100644
--- a/src/base/vnc/convert.cc
+++ b/src/base/vnc/convert.cc
@@ -67,7 +67,7 @@ VideoConvert::~VideoConvert()
}
uint8_t*
-VideoConvert::convert(uint8_t *fb)
+VideoConvert::convert(const uint8_t *fb) const
{
switch (inputMode) {
case bgr565:
@@ -82,7 +82,7 @@ VideoConvert::convert(uint8_t *fb)
}
uint8_t*
-VideoConvert::m565rgb8888(uint8_t *fb, bool bgr)
+VideoConvert::m565rgb8888(const uint8_t *fb, bool bgr) const
{
uint8_t *out = new uint8_t[area() * sizeof(uint32_t)];
uint32_t *out32 = (uint32_t*)out;
@@ -113,7 +113,7 @@ VideoConvert::m565rgb8888(uint8_t *fb, bool bgr)
uint8_t*
-VideoConvert::bgr8888rgb8888(uint8_t *fb)
+VideoConvert::bgr8888rgb8888(const uint8_t *fb) const
{
uint8_t *out = new uint8_t[area() * sizeof(uint32_t)];
uint32_t *out32 = (uint32_t*)out;
@@ -136,4 +136,21 @@ VideoConvert::bgr8888rgb8888(uint8_t *fb)
return out;
}
+/*
+uint64_t
+VideoConvert::getHash(const uint8_t *fb) const
+{
+ const uint8_t *fb_e = fb + area();
+
+ uint64_t hash = 1;
+ while (fb < fb_e - 8) {
+ hash += *((const uint64_t*)fb);
+ fb += 8;
+ }
+
+ while (fb < fb_e) {
+ hash += *(fb++);
+ }
+ return hash;
+}*/
diff --git a/src/base/vnc/convert.hh b/src/base/vnc/convert.hh
index 68a21d677..17df0747b 100644
--- a/src/base/vnc/convert.hh
+++ b/src/base/vnc/convert.hh
@@ -44,6 +44,7 @@
#ifndef __BASE_VNC_CONVERT_HH__
#define __BASE_VNC_CONVERT_HH__
+#include <zlib.h>
#include "base/bitunion.hh"
class VideoConvert
@@ -107,12 +108,21 @@ class VideoConvert
* @param fb the frame buffer to convert
* @return the converted data (user must free)
*/
- uint8_t* convert(uint8_t *fb);
+ uint8_t* convert(const uint8_t *fb) const;
/** Return the number of pixels that this buffer specifies
* @return number of pixels
*/
- int area() { return width * height; }
+ int area() const { return width * height; }
+
+ /**
+ * Returns a hash on the raw data.
+ *
+ * @return hash of the buffer
+ */
+ inline uint64_t getHash(const uint8_t *fb) const {
+ return adler32(0UL, fb, width * height);
+ }
private:
@@ -121,7 +131,7 @@ class VideoConvert
* @param fb the data to convert
* @return converted data
*/
- uint8_t* bgr8888rgb8888(uint8_t *fb);
+ uint8_t* bgr8888rgb8888(const uint8_t *fb) const;
/**
* Convert a bgr565 or rgb565 input to rgb8888.
@@ -129,7 +139,7 @@ class VideoConvert
* @param bgr true if the input data is bgr565
* @return converted data
*/
- uint8_t* m565rgb8888(uint8_t *fb, bool bgr);
+ uint8_t* m565rgb8888(const uint8_t *fb, bool bgr) const;
Mode inputMode;
Mode outputMode;
diff --git a/src/base/vnc/vncserver.cc b/src/base/vnc/vncserver.cc
index 18e581bfe..b4a783219 100644
--- a/src/base/vnc/vncserver.cc
+++ b/src/base/vnc/vncserver.cc
@@ -43,7 +43,10 @@
*/
#include <sys/ioctl.h>
+#include <sys/stat.h>
#include <sys/termios.h>
+#include <sys/types.h>
+#include <fcntl.h>
#include <poll.h>
#include <unistd.h>
@@ -52,11 +55,14 @@
#include "base/vnc/vncserver.hh"
#include "base/atomicio.hh"
+#include "base/bitmap.hh"
#include "base/misc.hh"
+#include "base/output.hh"
#include "base/socket.hh"
#include "base/trace.hh"
#include "debug/VNC.hh"
#include "sim/byteswap.hh"
+#include "sim/core.hh"
using namespace std;
@@ -98,14 +104,14 @@ VncServer::VncServer(const Params *p)
: SimObject(p), listenEvent(NULL), dataEvent(NULL), number(p->number),
dataFd(-1), _videoWidth(1), _videoHeight(1), clientRfb(0), keyboard(NULL),
mouse(NULL), sendUpdate(false), videoMode(VideoConvert::UnknownMode),
- vc(NULL)
+ vc(NULL), captureEnabled(p->frame_capture), captureCurrentFrame(0),
+ captureLastHash(0), captureBitmap(0)
{
if (p->port)
listen(p->port);
curState = WaitForProtocolVersion;
-
// currently we only support this one pixel format
// unpacked 32bit rgb (rgb888 + 8 bits of nothing/alpha)
// keep it around for telling the client and making
@@ -121,6 +127,14 @@ VncServer::VncServer(const Params *p)
pixelFormat.greenshift = 8;
pixelFormat.blueshift = 0;
+ if (captureEnabled) {
+ // remove existing frame output directory if it exists, then create a
+ // clean empty directory
+ const string FRAME_OUTPUT_SUBDIR = "frames_" + name();
+ simout.remove(FRAME_OUTPUT_SUBDIR, true);
+ captureOutputDirectory = simout.createSubdirectory(
+ FRAME_OUTPUT_SUBDIR);
+ }
DPRINTF(VNC, "Vnc server created at port %d\n", p->port);
}
@@ -686,6 +700,16 @@ VncServer::setFrameBufferParams(VideoConvert::Mode mode, int width, int height)
vc = new VideoConvert(mode, VideoConvert::rgb8888, videoWidth(),
videoHeight());
+ if (captureEnabled) {
+ // create bitmap of the frame with new attributes
+ if (captureBitmap)
+ delete captureBitmap;
+
+ assert(clientRfb);
+ captureBitmap = new Bitmap(videoMode, width, height, clientRfb);
+ assert(captureBitmap);
+ }
+
if (dataFd > 0 && clientRfb && curState == NormalPhase) {
if (supportsResizeEnc)
sendFrameBufferResized();
@@ -702,3 +726,29 @@ VncServerParams::create()
{
return new VncServer(this);
}
+
+void
+VncServer::captureFrameBuffer()
+{
+ assert(captureBitmap);
+
+ // skip identical frames
+ uint64_t new_hash = captureBitmap->getHash();
+ if (captureLastHash == new_hash)
+ return;
+ captureLastHash = new_hash;
+
+ // get the filename for the current frame
+ char frameFilenameBuffer[64];
+ snprintf(frameFilenameBuffer, 64, "fb.%06d.%lld.bmp.gz",
+ captureCurrentFrame, static_cast<long long int>(curTick()));
+ const string frameFilename(frameFilenameBuffer);
+
+ // create the compressed framebuffer file
+ ostream *fb_out = simout.create(captureOutputDirectory + frameFilename,
+ true);
+ captureBitmap->write(fb_out);
+ simout.close(fb_out);
+
+ ++captureCurrentFrame;
+}
diff --git a/src/base/vnc/vncserver.hh b/src/base/vnc/vncserver.hh
index 96dbdedda..33d833f26 100644
--- a/src/base/vnc/vncserver.hh
+++ b/src/base/vnc/vncserver.hh
@@ -48,6 +48,7 @@
#include <iostream>
#include "base/vnc/convert.hh"
+#include "base/bitmap.hh"
#include "base/circlebuf.hh"
#include "base/pollevent.hh"
#include "base/socket.hh"
@@ -55,6 +56,7 @@
#include "params/VncServer.hh"
#include "sim/sim_object.hh"
+
/**
* A device that expects to receive input from the vnc server should derrive
* (through mulitple inheritence if necessary from VncKeyboard or VncMouse
@@ -316,7 +318,25 @@ class VncServer : public SimObject
/** The video converter that transforms data for us */
VideoConvert *vc;
+ /** Flag indicating whether to capture snapshots of frame buffer or not */
+ bool captureEnabled;
+
+ /** Current frame number being captured to a file */
+ int captureCurrentFrame;
+
+ /** Directory to store captured frames to */
+ std::string captureOutputDirectory;
+
+ /** Computed hash of the last captured frame */
+ uint64_t captureLastHash;
+
+ /** Cached bitmap object for writing out frame buffers to file */
+ Bitmap *captureBitmap;
+
protected:
+ /** Captures the current frame buffer to a file */
+ void captureFrameBuffer();
+
/**
* vnc client Interface
*/
@@ -449,6 +469,8 @@ class VncServer : public SimObject
setDirty()
{
sendUpdate = true;
+ if (captureEnabled)
+ captureFrameBuffer();
sendFrameBufferUpdate();
}