Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions libbpf-tools/bashreadline.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,9 @@ static int libbpf_print_fn(enum libbpf_print_level level, const char *format, va
static void handle_event(void *ctx, int cpu, void *data, __u32 data_size)
{
struct str_t *e = data;
struct tm *tm;
char ts[16];
time_t t;

time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%m:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));

printf("%-9s %-7d %s\n", ts, e->pid, e->str);
}
Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/bindsnoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,13 @@ static void sig_int(int signo)
static void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
{
struct bind_event *e = data;
time_t t;
struct tm *tm;
char ts[32], addr[48];
char opts[] = {'F', 'T', 'N', 'R', 'r', '\0'};
const char *proto;
int i = 0;

if (emit_timestamp) {
time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));
printf("%8s ", ts);
}
if (e->proto == IPPROTO_TCP)
Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/biolatency.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,7 @@ int main(int argc, char **argv)
.doc = argp_program_doc,
};
struct biolatency_bpf *obj;
struct tm *tm;
char ts[32];
time_t t;
int err;
int idx, cg_map_fd;
int cgfd = -1;
Expand Down Expand Up @@ -370,9 +368,7 @@ int main(int argc, char **argv)
printf("\n");

if (env.timestamp) {
time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));
printf("%-8s\n", ts);
}

Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/biopattern.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ static int print_map(struct bpf_map *counters, struct partitions *partitions)
int err, fd = bpf_map__fd(counters);
const struct partition *partition;
struct counter counter;
struct tm *tm;
char ts[32];
time_t t;

while (!bpf_map_get_next_key(fd, &lookup_key, &next_key)) {
err = bpf_map_lookup_elem(fd, &next_key, &counter);
Expand All @@ -131,9 +129,7 @@ static int print_map(struct bpf_map *counters, struct partitions *partitions)
if (!total)
continue;
if (env.timestamp) {
time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));
printf("%-9s ", ts);
}
partition = partitions__get_by_dev(partitions, next_key);
Expand Down
4 changes: 1 addition & 3 deletions libbpf-tools/biosnoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
struct event e;
char rwbs[RWBS_LEN];
struct timespec ct;
struct tm *tm;
char ts[32];

if (data_sz < sizeof(e)) {
Expand All @@ -194,8 +193,7 @@ void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
/* Since `bpf_ktime_get_boot_ns` requires at least 5.8 kernel,
* so get time from usespace instead */
clock_gettime(CLOCK_REALTIME, &ct);
tm = localtime(&ct.tv_sec);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));
printf("%-8s.%03ld ", ts, ct.tv_nsec / 1000000);
} else {
if (!start_ts) {
Expand Down
25 changes: 8 additions & 17 deletions libbpf-tools/biotop.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,24 +301,15 @@ static int read_stat(struct biotop_bpf *obj, struct data_t *datas, __u32 *count)

static int print_stat(struct biotop_bpf *obj)
{
FILE *f;
time_t t;
struct tm *tm;
char ts[16], buf[256];
char loadavg[256], ts[64];
static struct data_t datas[OUTPUT_ROWS_LIMIT];
int n, i, err = 0, rows = OUTPUT_ROWS_LIMIT;

f = fopen("/proc/loadavg", "r");
if (f) {
time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
memset(buf, 0, sizeof(buf));
n = fread(buf, 1, sizeof(buf), f);
if (n)
printf("%8s loadavg: %s\n", ts, buf);
fclose(f);
}
int i, err = 0, rows = OUTPUT_ROWS_LIMIT;

err = str_loadavg(loadavg, sizeof(loadavg)) <= 0;
err = err ?: (str_timestamp("%H:%M:%S", ts, sizeof(ts)) <= 0);
if (!err)
printf("%8s %s\n", ts, loadavg);

printf("%-7s %-16s %1s %-3s %-3s %-8s %5s %7s %6s\n",
"PID", "COMM", "D", "MAJ", "MIN", "DISK", "I/O", "Kbytes", "AVGms");

Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/bitesize.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,8 @@ int main(int argc, char **argv)
.doc = argp_program_doc,
};
struct bitesize_bpf *obj;
struct tm *tm;
char ts[32];
int fd, err;
time_t t;

err = argp_parse(&argp, argc, argv, 0, NULL, NULL);
if (err)
Expand Down Expand Up @@ -218,9 +216,7 @@ int main(int argc, char **argv)
printf("\n");

if (env.timestamp) {
time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));
printf("%-8s\n", ts);
}

Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/cachestat.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,8 @@ int main(int argc, char **argv)
__u64 buffers, cached, mbd;
struct cachestat_bpf *obj;
__s64 total, misses, hits;
struct tm *tm;
float ratio;
char ts[32];
time_t t;
int err;

err = argp_parse(&argp, argc, argv, 0, NULL, NULL);
Expand Down Expand Up @@ -262,9 +260,7 @@ int main(int argc, char **argv)
goto cleanup;
}
if (env.timestamp) {
time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));
printf("%-8s ", ts);
}
printf("%8lld %8lld %8llu %7.2f%% %12llu %10llu\n",
Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/capable.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,9 @@ static void print_map(struct ksyms *ksyms, struct syms_cache *syms_cache)
static void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
{
const struct cap_event *e = data;
struct tm *tm;
char ts[32];
time_t t;

time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));

char *verdict = "deny";
if (!e->ret)
Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/cpudist.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ int main(int argc, char **argv)
};
struct cpudist_bpf *obj;
int pid_max, fd, err;
struct tm *tm;
char ts[32];
time_t t;
int idx, cg_map_fd;
int cgfd = -1;

Expand Down Expand Up @@ -280,9 +278,7 @@ int main(int argc, char **argv)
printf("\n");

if (env.timestamp) {
time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));
printf("%-8s\n", ts);
}

Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/drsnoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ static void sig_int(int signo)
void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
{
struct event e;
struct tm *tm;
char ts[32];
time_t t;

if (data_sz < sizeof(e)) {
printf("Error: packet too small\n");
Expand All @@ -130,9 +128,7 @@ void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
/* Copy data as alignment in the perf buffer isn't guaranteed. */
memcpy(&e, data, sizeof(e));

time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));
printf("%-8s %-16s %-6d %8.3f %5lld",
ts, e.task, e.pid, e.delta_ns / 1000000.0,
e.nr_reclaimed);
Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/execsnoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ static void print_args(const struct event *e, bool quote)
static void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
{
const struct event *e = data;
time_t t;
struct tm *tm;
char ts[32];

/* TODO: use pcre lib */
Expand All @@ -241,9 +239,7 @@ static void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
if (env.line && strstr(e->comm, env.line) == NULL)
return;

time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));

if (env.time) {
printf("%-8s ", ts);
Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/exitsnoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ static void sig_int(int signo)
static void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
{
struct event e;
time_t t;
struct tm *tm;
char ts[32];
double age;
int sig, coredump;
Expand All @@ -135,9 +133,7 @@ static void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
memcpy(&e, data, sizeof(e));

if (emit_timestamp) {
time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));
printf("%8s ", ts);
}

Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/filelife.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ static void sig_int(int signo)
int handle_event(void *ctx, void *data, size_t data_sz)
{
struct event e;
struct tm *tm;
char ts[32];
time_t t;

if (data_sz < sizeof(e)) {
printf("Error: packet too small\n");
Expand All @@ -106,9 +104,7 @@ int handle_event(void *ctx, void *data, size_t data_sz)
/* Copy data as alignment in the ring buffer isn't guaranteed. */
memcpy(&e, data, sizeof(e));

time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));
printf("%-8s %-6d %-16s %-7.2f ",
ts, e.tgid, e.task, (double)e.delta_ns / 1000000000);
if (env.full_path) {
Expand Down
22 changes: 6 additions & 16 deletions libbpf-tools/filetop.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,16 @@ static int sort_column(const void *obj1, const void *obj2)

static int print_stat(struct filetop_bpf *obj)
{
FILE *f;
time_t t;
struct tm *tm;
char ts[16], buf[256];
char loadavg[256], ts[64];
struct file_id key, *prev_key = NULL;
static struct file_stat values[OUTPUT_ROWS_LIMIT];
int n, i, err = 0, rows = 0;
int i, err = 0, rows = 0;
int fd = bpf_map__fd(obj->maps.entries);

f = fopen("/proc/loadavg", "r");
if (f) {
time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
memset(buf, 0, sizeof(buf));
n = fread(buf, 1, sizeof(buf), f);
if (n)
printf("%8s loadavg: %s\n", ts, buf);
fclose(f);
}
err = str_loadavg(loadavg, sizeof(loadavg)) <= 0;
err = err ?: (str_timestamp("%H:%M:%S", ts, sizeof(ts)) <= 0);
if (!err)
printf("%8s %s\n", ts, loadavg);

printf("%-7s %-16s %-6s %-6s %-7s %-7s %1s %s\n",
"TID", "COMM", "READS", "WRITES", "R_Kb", "W_Kb", "T", "FILE");
Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/fsdist.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,7 @@ int main(int argc, char **argv)
.doc = argp_program_doc,
};
struct fsdist_bpf *skel;
struct tm *tm;
char ts[32];
time_t t;
int err;
bool support_fentry;

Expand Down Expand Up @@ -464,9 +462,7 @@ int main(int argc, char **argv)
printf("\n");

if (emit_timestamp) {
time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));
printf("%-8s\n", ts);
}

Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/fsslower.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,7 @@ static void print_headers()
static void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
{
struct event e;
struct tm *tm;
char ts[32];
time_t t;

if (data_sz < sizeof(e)) {
printf("Error: packet too small\n");
Expand All @@ -372,9 +370,7 @@ static void handle_event(void *ctx, int cpu, void *data, __u32 data_sz)
return;
}

time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));

printf("%-8s %-16s %-7d %c ", ts, e.task, e.pid, file_op[e.op]);
if (e.size == LLONG_MAX)
Expand Down
6 changes: 1 addition & 5 deletions libbpf-tools/funclatency.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,7 @@ int main(int argc, char **argv)
};
struct funclatency_bpf *obj;
int i, err;
struct tm *tm;
char ts[32];
time_t t;
int idx, cg_map_fd;
int cgfd = -1;
bool used_fentry = false;
Expand Down Expand Up @@ -413,9 +411,7 @@ int main(int argc, char **argv)

printf("\n");
if (env.timestamp) {
time(&t);
tm = localtime(&t);
strftime(ts, sizeof(ts), "%H:%M:%S", tm);
str_timestamp("%H:%M:%S", ts, sizeof(ts));
printf("%-8s\n", ts);
}

Expand Down
Loading
Loading