-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.cpp
66 lines (60 loc) · 1.78 KB
/
cli.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
#include "subprocess.hpp"
#include <cstdlib>
#include <unistd.h>
int main(int argc, char *argv[])
{
std::string libraryLocation = "./libhipcapture.so";
std::string outputName = "./tracer-default.db";
std::string mode = "capture";
std::string tool = "./libmemtrace.so";
bool debug = false;
bool progressbar = true;
bool skiphostdata = false;
std::string rest;
int c;
while ((c = getopt(argc, argv, "l:so:dpt:m:")) != -1) {
switch (c) {
case 'l':
libraryLocation = optarg;
break;
case 's':
skiphostdata = true;
break;
case 'o':
outputName = optarg;
break;
case 'd':
debug = true;
break;
case 'p':
progressbar = false;
break;
case 'm':
mode = optarg;
break;
case 't':
tool = optarg;
break;
default:
return EXIT_FAILURE;
}
}
//std::printf("TOOL %s\n", tool.c_str());
//std::printf("EVENTDB %s\n", outputName.c_str());
std::map<std::string, std::string> env =
{{ {"LD_PRELOAD", libraryLocation},
{"HIPTRACER_EVENTDB", outputName},
{"HIPTRACER_TOOL", tool},
{"HIPTRACER_MODE", mode} }};
std::vector<std::string> tail;
for (int i = optind; i < argc; i++) {
tail.push_back(std::string(argv[i]));
}
if (debug) {
env["HIPTRACER_DEBUG"] = "1";
} else if (skiphostdata) {
env["HIPTRACER_SKIPHOSTDATA"] = "1";
}
int sb = subprocess::Popen(tail, subprocess::environment{{env}}, subprocess::output{{stdout}}).wait();
return sb;
}