-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i#4318 xarch memtrace: Support gzipped .raw files (#4332)
Adds a new gzip wrapper around std::istream to support compressing .raw files. This lets us easily shrink checked-in test files, and aids other relocate-then-process situations with raw files. Updates the altbin test by compressing its .raw files. Issue: #4318
- Loading branch information
1 parent
5d49675
commit 8da4e78
Showing
15 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* ********************************************************** | ||
* Copyright (c) 2018-2020 Google, Inc. All rights reserved. | ||
* **********************************************************/ | ||
|
||
/* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of Google, Inc. nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
* DAMAGE. | ||
*/ | ||
|
||
/* gzip_istream_t: a wrapper around zlib gzFile to match the parts of the | ||
* std::istream interface we use for raw2trace and file_reader_t. | ||
* Supports only limited seeking within the current internal buffer. | ||
*/ | ||
|
||
#ifndef _GZIP_ISTREAM_H_ | ||
#define _GZIP_ISTREAM_H_ 1 | ||
|
||
#ifndef HAS_ZLIB | ||
# error HAS_ZLIB is required | ||
#endif | ||
#include <fstream> | ||
#include <zlib.h> | ||
|
||
/* We need to override the stream buffer class which is where the file | ||
* reads happen. The stream buffer base class reads from eback()..egptr() | ||
* with the next to read at gptr(). | ||
*/ | ||
class gzip_istreambuf_t : public std::basic_streambuf<char, std::char_traits<char>> { | ||
public: | ||
gzip_istreambuf_t(const std::string &path) | ||
{ | ||
file_ = gzopen(path.c_str(), "rb"); | ||
if (file_ != nullptr) { | ||
buf_ = new char[buffer_size_]; | ||
} | ||
} | ||
~gzip_istreambuf_t() override | ||
{ | ||
delete[] buf_; | ||
if (file_ != nullptr) | ||
gzclose(file_); | ||
} | ||
int | ||
underflow() override | ||
{ | ||
if (file_ == nullptr) | ||
return traits_type::eof(); | ||
if (gptr() == egptr()) { | ||
int len = gzread(file_, buf_, buffer_size_); | ||
if (len <= 0) | ||
return traits_type::eof(); | ||
setg(buf_, buf_, buf_ + len); | ||
} | ||
return *gptr(); | ||
} | ||
std::iostream::pos_type | ||
seekoff(std::iostream::off_type off, std::ios_base::seekdir dir, | ||
std::ios_base::openmode which = std::ios_base::in) override | ||
{ | ||
if (dir == std::ios_base::cur && | ||
((off >= 0 && gptr() + off < egptr()) || | ||
(off < 0 && gptr() + off >= eback()))) | ||
gbump(off); | ||
else { | ||
// Unsupported! | ||
return -1; | ||
} | ||
return gptr() - eback(); | ||
} | ||
|
||
private: | ||
static const int buffer_size_ = 4096; | ||
gzFile file_ = nullptr; | ||
char *buf_ = nullptr; | ||
}; | ||
|
||
class gzip_istream_t : public std::istream { | ||
public: | ||
explicit gzip_istream_t(const std::string &path) | ||
: std::istream(new gzip_istreambuf_t(path)) | ||
{ | ||
if (!rdbuf()) | ||
setstate(std::ios::badbit); | ||
} | ||
virtual ~gzip_istream_t() override | ||
{ | ||
delete rdbuf(); | ||
} | ||
}; | ||
|
||
#endif /* _GZIP_ISTREAM_H_ */ |
Binary file removed
BIN
-71.9 KB
...drcachesim/tests/drmemtrace.threadsig.aarch64.raw/raw/drmemtrace.threadsig.44811.2612.raw
Binary file not shown.
Binary file added
BIN
+11.1 KB
...achesim/tests/drmemtrace.threadsig.aarch64.raw/raw/drmemtrace.threadsig.44811.2612.raw.gz
Binary file not shown.
Binary file removed
BIN
-60 KB
...drcachesim/tests/drmemtrace.threadsig.aarch64.raw/raw/drmemtrace.threadsig.44812.0713.raw
Binary file not shown.
Binary file added
BIN
+919 Bytes
...achesim/tests/drmemtrace.threadsig.aarch64.raw/raw/drmemtrace.threadsig.44812.0713.raw.gz
Binary file not shown.
Binary file removed
BIN
-60 KB
...drcachesim/tests/drmemtrace.threadsig.aarch64.raw/raw/drmemtrace.threadsig.44813.3661.raw
Binary file not shown.
Binary file added
BIN
+922 Bytes
...achesim/tests/drmemtrace.threadsig.aarch64.raw/raw/drmemtrace.threadsig.44813.3661.raw.gz
Binary file not shown.
Binary file removed
BIN
-60 KB
...drcachesim/tests/drmemtrace.threadsig.aarch64.raw/raw/drmemtrace.threadsig.44814.4595.raw
Binary file not shown.
Binary file added
BIN
+918 Bytes
...achesim/tests/drmemtrace.threadsig.aarch64.raw/raw/drmemtrace.threadsig.44814.4595.raw.gz
Binary file not shown.
Binary file removed
BIN
-60 KB
...drcachesim/tests/drmemtrace.threadsig.aarch64.raw/raw/drmemtrace.threadsig.44815.2323.raw
Binary file not shown.
Binary file added
BIN
+917 Bytes
...achesim/tests/drmemtrace.threadsig.aarch64.raw/raw/drmemtrace.threadsig.44815.2323.raw.gz
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters