spdk_trace: allow specifying a filename on command line
This allows for offline debugging with a tracepoint file - you can copy the shared memory file out of /dev/shm to a normal file, then pass that in to this trace app. Note: Linux puts shared memory files in /dev/shm which makes it easy to copy to a regular file. FreeBSD does not expose shared memory objects in this way - so for now this capability to debug tracepoint files offline will be limited primarily to Linux. Signed-off-by: Jim Harris <james.r.harris@intel.com> Change-Id: I046b71bdd65cab5a76500775838a5072bec8da39 Reviewed-on: https://review.gerrithub.io/424284 Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
11a6ed238b
commit
b7b7c04609
@ -290,11 +290,15 @@ static void usage(void)
|
||||
fprintf(stderr, "usage:\n");
|
||||
fprintf(stderr, " %s <option> <lcore#>\n", exe_name);
|
||||
fprintf(stderr, " option = '-q' to disable verbose mode\n");
|
||||
fprintf(stderr, " '-s' to specify spdk_trace shm name\n");
|
||||
fprintf(stderr, " '-c' to display single lcore history\n");
|
||||
fprintf(stderr, " '-s' to specify spdk_trace shm name for a\n");
|
||||
fprintf(stderr, " currently running process\n");
|
||||
fprintf(stderr, " '-i' to specify the shared memory ID\n");
|
||||
fprintf(stderr, " '-p' to specify the trace PID\n");
|
||||
fprintf(stderr, " (One of -i or -p must be specified)\n");
|
||||
fprintf(stderr, " (If -s is specified, then one of\n");
|
||||
fprintf(stderr, " -i or -p must be specified)\n");
|
||||
fprintf(stderr, " '-f' to specify a tracepoint file name\n");
|
||||
fprintf(stderr, " (-s and -f are mutually exclusive)\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@ -304,7 +308,8 @@ int main(int argc, char **argv)
|
||||
int fd, i;
|
||||
int lcore = SPDK_TRACE_MAX_LCORE;
|
||||
uint64_t tsc_offset;
|
||||
const char *app_name = "spdk";
|
||||
const char *app_name = NULL;
|
||||
const char *file_name = NULL;
|
||||
int op;
|
||||
char shm_name[64];
|
||||
int shm_id = -1, shm_pid = -1;
|
||||
@ -333,21 +338,40 @@ int main(int argc, char **argv)
|
||||
case 's':
|
||||
app_name = optarg;
|
||||
break;
|
||||
case 'f':
|
||||
file_name = optarg;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (file_name != NULL && app_name != NULL) {
|
||||
fprintf(stderr, "-f and -s are mutually exclusive\n");
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (file_name == NULL && app_name == NULL) {
|
||||
fprintf(stderr, "One of -f and -s must be specified\n");
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (shm_id >= 0) {
|
||||
snprintf(shm_name, sizeof(shm_name), "/%s_trace.%d", app_name, shm_id);
|
||||
} else {
|
||||
snprintf(shm_name, sizeof(shm_name), "/%s_trace.pid%d", app_name, shm_pid);
|
||||
}
|
||||
|
||||
fd = shm_open(shm_name, O_RDONLY, 0600);
|
||||
if (file_name) {
|
||||
fd = open(file_name, O_RDONLY);
|
||||
} else {
|
||||
fd = shm_open(shm_name, O_RDONLY, 0600);
|
||||
}
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Could not open shm %s.\n", shm_name);
|
||||
fprintf(stderr, "Could not open %s.\n", file_name ? file_name : shm_name);
|
||||
usage();
|
||||
exit(-1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user