Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf daemon: Add up time for daemon/session list

Display up time for both daemon and sessions.

Example:

# cat ~/.perfconfig
[daemon]
base=/opt/perfdata

[session-cycles]
run = -m 10M -e cycles --overwrite --switch-output -a

[session-sched]
run = -m 20M -e sched:* --overwrite --switch-output -a

Starting the daemon:

# perf daemon start

Get the details with up time:

# perf daemon -v
[778315:daemon] base: /opt/perfdata
output: /opt/perfdata/output
lock: /opt/perfdata/lock
up: 15 minutes
[778316:cycles] perf record -m 20M -e cycles --overwrite --switch-output -a
base: /opt/perfdata/session-cycles
output: /opt/perfdata/session-cycles/output
control: /opt/perfdata/session-cycles/control
ack: /opt/perfdata/session-cycles/ack
up: 10 minutes
[778317:sched] perf record -m 20M -e sched:* --overwrite --switch-output -a
base: /opt/perfdata/session-sched
output: /opt/perfdata/session-sched/output
control: /opt/perfdata/session-sched/control
ack: /opt/perfdata/session-sched/ack
up: 2 minutes

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: https://lore.kernel.org/r/20210208200908.1019149-18-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
5bdee4f0 6d6162d5

+20
+20
tools/perf/builtin-daemon.c
··· 25 25 #include <sys/wait.h> 26 26 #include <poll.h> 27 27 #include <sys/stat.h> 28 + #include <time.h> 28 29 #include "builtin.h" 29 30 #include "perf.h" 30 31 #include "debug.h" ··· 81 80 int pid; 82 81 struct list_head list; 83 82 enum daemon_session_state state; 83 + time_t start; 84 84 }; 85 85 86 86 struct daemon { ··· 95 93 FILE *out; 96 94 char perf[PATH_MAX]; 97 95 int signal_fd; 96 + time_t start; 98 97 }; 99 98 100 99 static struct daemon __daemon = { ··· 337 334 perror("failed: mkdir"); 338 335 return -1; 339 336 } 337 + 338 + session->start = time(NULL); 340 339 341 340 session->pid = fork(); 342 341 if (session->pid < 0) ··· 670 665 { 671 666 char csv_sep = cmd->list.csv_sep; 672 667 struct daemon_session *session; 668 + time_t curr = time(NULL); 673 669 674 670 if (csv_sep) { 675 671 fprintf(out, "%d%c%s%c%s%c%s/%s", ··· 685 679 /* lock */ 686 680 csv_sep, daemon->base, "lock"); 687 681 682 + fprintf(out, "%c%lu", 683 + /* session up time */ 684 + csv_sep, (curr - daemon->start) / 60); 685 + 688 686 fprintf(out, "\n"); 689 687 } else { 690 688 fprintf(out, "[%d:daemon] base: %s\n", getpid(), daemon->base); ··· 697 687 daemon->base, SESSION_OUTPUT); 698 688 fprintf(out, " lock: %s/lock\n", 699 689 daemon->base); 690 + fprintf(out, " up: %lu minutes\n", 691 + (curr - daemon->start) / 60); 700 692 } 701 693 } 702 694 ··· 724 712 /* session ack */ 725 713 csv_sep, session->base, SESSION_ACK); 726 714 715 + fprintf(out, "%c%lu", 716 + /* session up time */ 717 + csv_sep, (curr - session->start) / 60); 718 + 727 719 fprintf(out, "\n"); 728 720 } else { 729 721 fprintf(out, "[%d:%s] perf record %s\n", ··· 742 726 session->base, SESSION_CONTROL); 743 727 fprintf(out, " ack: %s/%s\n", 744 728 session->base, SESSION_ACK); 729 + fprintf(out, " up: %lu minutes\n", 730 + (curr - session->start) / 60); 745 731 } 746 732 } 747 733 ··· 1256 1238 argc = parse_options(argc, argv, start_options, daemon_usage, 0); 1257 1239 if (argc) 1258 1240 usage_with_options(daemon_usage, start_options); 1241 + 1242 + daemon->start = time(NULL); 1259 1243 1260 1244 if (setup_config(daemon)) { 1261 1245 pr_err("failed: config not found\n");