-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracer.cpp
132 lines (126 loc) · 3.34 KB
/
tracer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include <iostream>
#include <unistd.h>
#include "Decoder.h"
#include "ProcessorTracer.h"
#include "PrintSourceCode.h"
#include "MultiThreadTracer.h"
void usage( void )
{
std::cout << "0. Get bin path" << std::endl;
std::cout << "1. Start capture" << std::endl;
std::cout << "2. Stop capture" << std::endl;
std::cout << "3. Save aux data" << std::endl;
std::cout << "4. Decode" << std::endl;
}
int main( int argc, char *argv[] )
{
ProcessorTracer *pt = nullptr;
MultiThreadTracer *mtt = nullptr;
Decoder *d = nullptr;
pid_t pid;
bool is_multi_thread = false;
std::string binary;
while ( true ) {
switch ( getopt( argc, argv, "mPp:f:" ) )
{
case 'm':
{
is_multi_thread = true;
continue;
}
case 'p':
{
pid = std::stoi( optarg );
continue;
}
case 'f':
{
binary = optarg;
continue;
}
default:
{
break;
}
}
break;
}
PrintSourceCode *psc;
if ( is_multi_thread ) {
mtt = new MultiThreadTracer( pid );
}
else {
pt = new ProcessorTracer( pid );
}
while ( true ) {
usage();
std::cout << ">";
int select;
std::cin >> select;
switch ( select ) {
case -1:
return 0;
case 0:
{
break;
}
case 1:
{
if ( is_multi_thread ) {
mtt->InitTracer();
mtt->StartTrace();
}
else {
pt->InitCapture();
pt->StartTrace();
}
break;
}
case 2:
{
if ( is_multi_thread ) {
}
pt->StopTrace();
psc = new PrintSourceCode( pt->GetProcPath() );
break;
}
case 3:
{
pt->SaveAuxFile();
pt->SaveMapsFile();
break;
}
case 4:
{
if ( pt == nullptr ) {
std::cerr << "Not traced yet" << std::endl;
break;
}
d = new Decoder( pt->GetAux(), pt->GetAuxSize(), pt->GetProcPath(), pt->GetRawFileList(), psc );
d->InitDecoder();
d->Decode();
break;
}
case 5:
{
d = new Decoder( 0, 0, "NULL", nullptr, psc );
d->SetDecoderByFile("/home/lab/lab/intern_work/ProcessorTracerByIntelPT/test/perf.data-aux-idx1.bin");
d->Decode();
break;
}
case 6:
{
d = new Decoder( 0, 0, pt->GetProcPath(), pt->GetRawFileList(), psc );
d->SetDecoderByFile("/home/lab/lab/intern_work/ProcessorTracerByIntelPT/build/aux.bin");
d->Decode();
break;
}
default:
{
std::cout << "wrong command" << std::endl;
break;
}
}
}
return 0;
}