dump-trace: C++ implementation
About 50 times faster than the Python version. Extended trace functionality still untested. Change-Id: I9e41b0283b7d3274c5ea9eba2164f78c04c1ad42
This commit is contained in:
committed by
Horst Schirmeier
parent
001d036613
commit
92e7be0d22
7
tools/dump-trace/CMakeLists.txt
Normal file
7
tools/dump-trace/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
||||
set(SRCS
|
||||
DumpTrace.cc
|
||||
)
|
||||
|
||||
add_executable(dump-trace ${SRCS})
|
||||
target_link_libraries(dump-trace ${PROTOBUF_LIBRARY} fail-util fail-comm)
|
||||
install(TARGETS dump-trace RUNTIME DESTINATION bin)
|
||||
96
tools/dump-trace/DumpTrace.cc
Normal file
96
tools/dump-trace/DumpTrace.cc
Normal file
@ -0,0 +1,96 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include "comm/TracePlugin.pb.h"
|
||||
#include "util/ProtoStream.hpp"
|
||||
#include "../../src/core/util/Logger.hpp"
|
||||
#include "../../src/core/util/gzstream/gzstream.h"
|
||||
|
||||
using namespace fail;
|
||||
using std::string;
|
||||
using std::endl;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::hex;
|
||||
using std::dec;
|
||||
|
||||
Logger log("dump-trace", true);
|
||||
|
||||
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;
|
||||
normal_stream >> b1 >> b2;
|
||||
|
||||
if (b1 == 0x1f && b2 == 0x8b) {
|
||||
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;
|
||||
return gz_stream;
|
||||
}
|
||||
|
||||
normal_stream.seekg(0);
|
||||
|
||||
//log << "opened file " << input_file << " in normal mode" << endl;
|
||||
return normal_stream;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Trace_Event ev;
|
||||
|
||||
if (argc != 2) {
|
||||
cerr << "Usage: " << argv[0] << " tracefile.pb" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::ifstream normal_stream;
|
||||
igzstream gz_stream;
|
||||
ProtoIStream ps(&openStream(argv[1], normal_stream, gz_stream));
|
||||
|
||||
while (ps.getNext(&ev)) {
|
||||
if (!ev.has_memaddr()) {
|
||||
cout << "IP " << hex << ev.ip() << "\n";
|
||||
} else {
|
||||
string ext = ""; // FIXME: use stringstream?
|
||||
if (ev.has_trace_ext()) {
|
||||
const Trace_Event_Extended& temp_ext = ev.trace_ext();
|
||||
ext = " DATA ";
|
||||
ext += temp_ext.data();
|
||||
int i;
|
||||
for (i = 0 ; i < temp_ext.registers_size() ; i++) {
|
||||
const Trace_Event_Extended_Registers& temp_reg = temp_ext.registers(i);
|
||||
ext += "REG: " ;
|
||||
ext += temp_reg.id();
|
||||
ext += " ";
|
||||
ext += temp_reg.value();
|
||||
ext += "=";
|
||||
ext += temp_reg.value_deref();
|
||||
}
|
||||
if (temp_ext.stack_size() > 0 ) {
|
||||
ext += " STACK: ";
|
||||
for (i = 0 ; i< temp_ext.stack_size() ; i++) {
|
||||
const Trace_Event_Extended_Stack& temp_stack = temp_ext.stack(i);
|
||||
ext += temp_stack.value();
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << "MEM "
|
||||
<< (ev.accesstype() == Trace_Event_AccessType_READ ? "R" : "W") << " "
|
||||
<< ev.memaddr()
|
||||
<< dec << " width " << ev.width()
|
||||
<< hex << " IP " << ev.ip()
|
||||
<< ext << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user