#include <stdlib.h>
#include <string.h>
-#include <zlib.h>
-
#include "os.hpp"
#include "trace_writer.hpp"
+#include "trace_file.hpp"
#include "trace_format.hpp"
Writer::Writer() :
- g_gzFile(NULL),
call_no(0)
{
+ m_file = new Trace::SnappyFile;
close();
-};
+}
-Writer::~Writer() {
+Writer::~Writer()
+{
close();
-};
+ delete m_file;
+ m_file = NULL;
+}
void
Writer::close(void) {
- if (g_gzFile != NULL) {
- gzclose(g_gzFile);
- g_gzFile = NULL;
- }
+ m_file->close();
}
bool
Writer::open(const char *filename) {
close();
- g_gzFile = gzopen(filename, "wb");
- if (!g_gzFile) {
+ if (!m_file->open(filename, File::Write)) {
return false;
}
call_no = 0;
- functions = std::vector<bool>();
- structs = std::vector<bool>();
- enums = std::vector<bool>();
- bitmasks = std::vector<bool>();
+ functions.clear();
+ structs.clear();
+ enums.clear();
+ bitmasks.clear();
_writeUInt(TRACE_VERSION);
void inline
Writer::_write(const void *sBuffer, size_t dwBytesToWrite) {
- if (g_gzFile == NULL)
- return;
-
- gzwrite(g_gzFile, sBuffer, dwBytesToWrite);
+ m_file->write(sBuffer, dwBytesToWrite);
}
void inline
}
}
-unsigned Writer::beginEnter(const FunctionSig &function) {
+unsigned Writer::beginEnter(const FunctionSig *sig) {
OS::AcquireMutex();
- if (!g_gzFile) {
+ if (!m_file->isOpened()) {
open();
}
_writeByte(Trace::EVENT_ENTER);
- _writeUInt(function.id);
- if (!lookup(functions, function.id)) {
- _writeString(function.name);
- _writeUInt(function.num_args);
- for (unsigned i = 0; i < function.num_args; ++i) {
- _writeString(function.args[i]);
+ _writeUInt(sig->id);
+ if (!lookup(functions, sig->id)) {
+ _writeString(sig->name);
+ _writeUInt(sig->num_args);
+ for (unsigned i = 0; i < sig->num_args; ++i) {
+ _writeString(sig->arg_names[i]);
}
- functions[function.id] = true;
+ functions[sig->id] = true;
}
return call_no++;
void Writer::endEnter(void) {
_writeByte(Trace::CALL_END);
- gzflush(g_gzFile, Z_SYNC_FLUSH);
+ m_file->flush();
OS::ReleaseMutex();
}
void Writer::endLeave(void) {
_writeByte(Trace::CALL_END);
- gzflush(g_gzFile, Z_SYNC_FLUSH);
+ m_file->flush();
OS::ReleaseMutex();
}
_writeString(sig->name);
_writeUInt(sig->num_members);
for (unsigned i = 0; i < sig->num_members; ++i) {
- _writeString(sig->members[i]);
+ _writeString(sig->member_names[i]);
}
structs[sig->id] = true;
}
}
}
-void Writer::writeBitmask(const BitmaskSig &bitmask, unsigned long long value) {
+void Writer::writeBitmask(const BitmaskSig *sig, unsigned long long value) {
_writeByte(Trace::TYPE_BITMASK);
- _writeUInt(bitmask.id);
- if (!lookup(bitmasks, bitmask.id)) {
- _writeUInt(bitmask.count);
- for (unsigned i = 0; i < bitmask.count; ++i) {
- if (i != 0 && bitmask.values[i].value == 0) {
- OS::DebugMessage("apitrace: bitmask %s is zero but is not first flag\n", bitmask.values[i].name);
+ _writeUInt(sig->id);
+ if (!lookup(bitmasks, sig->id)) {
+ _writeUInt(sig->num_flags);
+ for (unsigned i = 0; i < sig->num_flags; ++i) {
+ if (i != 0 && sig->flags[i].value == 0) {
+ OS::DebugMessage("apitrace: warning: sig %s is zero but is not first flag\n", sig->flags[i].name);
}
- _writeString(bitmask.values[i].name);
- _writeUInt(bitmask.values[i].value);
+ _writeString(sig->flags[i].name);
+ _writeUInt(sig->flags[i].value);
}
- bitmasks[bitmask.id] = true;
+ bitmasks[sig->id] = true;
}
_writeUInt(value);
}