mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-23 01:33:06 +00:00
libdrgn: add option to time load_debug_info example program
I often use examples/load_debug_info to benchmark loading/DWARF indexing, so add a -T option that prints the time it takes to load debug info. Signed-off-by: Omar Sandoval <osandov@osandov.com>
This commit is contained in:
parent
2d40d6e146
commit
2ad52cb5f4
@ -1,10 +1,27 @@
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "drgn.h"
|
||||
|
||||
static inline struct timespec timespec_sub(struct timespec a, struct timespec b)
|
||||
{
|
||||
if (a.tv_nsec < b.tv_nsec) {
|
||||
return (struct timespec){
|
||||
.tv_sec = a.tv_sec - 1 - b.tv_sec,
|
||||
.tv_nsec = a.tv_nsec + 1000000000L - b.tv_nsec,
|
||||
};
|
||||
} else {
|
||||
return (struct timespec){
|
||||
.tv_sec = a.tv_sec - b.tv_sec,
|
||||
.tv_nsec = a.tv_nsec - b.tv_nsec,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static void usage(bool error)
|
||||
{
|
||||
fprintf(error ? stderr : stdout,
|
||||
@ -16,6 +33,7 @@ static void usage(bool error)
|
||||
" -k, --kernel debug the running kernel (default)\n"
|
||||
" -c PATH, --core PATH debug the given core dump\n"
|
||||
" -p PID, --pid PID debug the running process with the given PID\n"
|
||||
" -T, --time print how long loading debug info took in seconds\n"
|
||||
" -h, --help display this help message and exit\n");
|
||||
exit(error ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||
}
|
||||
@ -26,14 +44,16 @@ int main(int argc, char **argv)
|
||||
{"kernel", no_argument, NULL, 'k'},
|
||||
{"core", required_argument, NULL, 'c'},
|
||||
{"pid", required_argument, NULL, 'p'},
|
||||
{"time", no_argument, NULL, 'T'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{},
|
||||
};
|
||||
bool kernel = false;
|
||||
const char *core = NULL;
|
||||
const char *pid = NULL;
|
||||
bool print_time = false;
|
||||
for (;;) {
|
||||
int c = getopt_long(argc, argv, "kc:p:h", long_options, NULL);
|
||||
int c = getopt_long(argc, argv, "kc:p:Th", long_options, NULL);
|
||||
if (c == -1)
|
||||
break;
|
||||
switch (c) {
|
||||
@ -46,6 +66,9 @@ int main(int argc, char **argv)
|
||||
case 'p':
|
||||
pid = optarg;
|
||||
break;
|
||||
case 'T':
|
||||
print_time = true;
|
||||
break;
|
||||
case 'h':
|
||||
usage(false);
|
||||
default:
|
||||
@ -71,7 +94,16 @@ int main(int argc, char **argv)
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
struct timespec start, end;
|
||||
if (print_time && clock_gettime(CLOCK_MONOTONIC, &start))
|
||||
abort();
|
||||
err = drgn_program_load_debug_info(prog, NULL, 0, true, true);
|
||||
if ((!err || err->code == DRGN_ERROR_MISSING_DEBUG_INFO) && print_time) {
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &end))
|
||||
abort();
|
||||
struct timespec diff = timespec_sub(end, start);
|
||||
printf("%lld.%09ld\n", (long long)diff.tv_sec, diff.tv_nsec);
|
||||
}
|
||||
|
||||
out:;
|
||||
int status;
|
||||
|
Loading…
Reference in New Issue
Block a user