From a307dc6df72a9ccc718a32697c1e0c91201d80a0 Mon Sep 17 00:00:00 2001 From: Lars Rademacher Date: Sun, 10 Nov 2013 01:35:19 +0100 Subject: [PATCH] import-trace: fix for using non-gzipped traces As non-gzipped trace-files cause the tool to always import zero events, the input file is now openend as in the dump-trace tool, where opening non-gzipped files obviously works fine. Change-Id: If2575dbeb93ed657c7b8ddd9f14f41b5cc7bf7c6 --- tools/import-trace/main.cc | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tools/import-trace/main.cc b/tools/import-trace/main.cc index 2f727d39..751da65c 100644 --- a/tools/import-trace/main.cc +++ b/tools/import-trace/main.cc @@ -24,30 +24,31 @@ using std::cout; static Logger LOG("import-trace", true); -ProtoIStream openProtoStream(std::string input_file) { - std::ifstream *gz_test_ptr = new std::ifstream(input_file.c_str()), &gz_test = *gz_test_ptr; - if (!gz_test) { +std::istream& openStream(const char *input_file, + std::ifstream& normal_stream, igzstream& gz_stream) { + normal_stream.open(input_file); + if (!normal_stream) { LOG << "couldn't open " << input_file << endl; exit(-1); } unsigned char b1, b2; - gz_test >> b1 >> b2; + normal_stream >> b1 >> b2; if (b1 == 0x1f && b2 == 0x8b) { - igzstream *tracef = new igzstream(input_file.c_str()); - if (!tracef) { + normal_stream.close(); + gz_stream.open(input_file); + if (!gz_stream) { LOG << "couldn't open " << input_file << endl; exit(-1); } LOG << "opened file " << input_file << " in GZip mode" << endl; - delete gz_test_ptr; - ProtoIStream ps(tracef); - return ps; + return gz_stream; } + normal_stream.seekg(0); + LOG << "opened file " << input_file << " in normal mode" << endl; - ProtoIStream ps(gz_test_ptr); - return ps; + return normal_stream; } int main(int argc, char *argv[]) { @@ -174,7 +175,9 @@ int main(int argc, char *argv[]) { trace_file = "trace.pb"; } - ProtoIStream ps = openProtoStream(trace_file); + std::ifstream normal_stream; + igzstream gz_stream; + ProtoIStream ps(&openStream(trace_file.c_str(), normal_stream, gz_stream)); Database *db = Database::cmdline_connect(); if (cmd[VARIANT]) {