import-trace: fix for using non-gzipped traces

As non-gzipped trace files cause import-trace 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.

In the medium term we should find a centralized solution for this,
instead of re-implementing it all over the place.

Change-Id: I75845c03c0bbdc2b6b578b83d492b7dbbb40f051
This commit is contained in:
Lars Rademacher
2013-11-10 01:35:19 +01:00
committed by Horst Schirmeier
parent 85fffe007e
commit 8b6d744a3e

View File

@ -24,30 +24,31 @@ using std::cout;
static Logger LOG("import-trace", true); static Logger LOG("import-trace", true);
ProtoIStream openProtoStream(std::string input_file) { std::istream& openStream(const char *input_file,
std::ifstream *gz_test_ptr = new std::ifstream(input_file.c_str()), &gz_test = *gz_test_ptr; std::ifstream& normal_stream, igzstream& gz_stream) {
if (!gz_test) { normal_stream.open(input_file);
if (!normal_stream) {
LOG << "couldn't open " << input_file << endl; LOG << "couldn't open " << input_file << endl;
exit(-1); exit(-1);
} }
unsigned char b1, b2; unsigned char b1, b2;
gz_test >> b1 >> b2; normal_stream >> b1 >> b2;
if (b1 == 0x1f && b2 == 0x8b) { if (b1 == 0x1f && b2 == 0x8b) {
igzstream *tracef = new igzstream(input_file.c_str()); normal_stream.close();
if (!tracef) { gz_stream.open(input_file);
if (!gz_stream) {
LOG << "couldn't open " << input_file << endl; LOG << "couldn't open " << input_file << endl;
exit(-1); exit(-1);
} }
LOG << "opened file " << input_file << " in GZip mode" << endl; LOG << "opened file " << input_file << " in GZip mode" << endl;
delete gz_test_ptr; return gz_stream;
ProtoIStream ps(tracef);
return ps;
} }
normal_stream.seekg(0);
LOG << "opened file " << input_file << " in normal mode" << endl; LOG << "opened file " << input_file << " in normal mode" << endl;
ProtoIStream ps(gz_test_ptr); return normal_stream;
return ps;
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
@ -174,7 +175,9 @@ int main(int argc, char *argv[]) {
trace_file = "trace.pb"; 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(); Database *db = Database::cmdline_connect();
if (cmd[VARIANT]) { if (cmd[VARIANT]) {