https://sourceware.org/bugzilla/show_bug.cgi?id=30575
Bug ID: 30575 Summary: gprofng cannot profile application with clone3() Product: binutils Version: unspecified Status: NEW Severity: minor Priority: P2 Component: gprofng Assignee: vladimir.mezentsev at oracle dot com Reporter: vladimir.mezentsev at oracle dot com Target Milestone: --- % cat clone.c #define _GNU_SOURCE #include <linux/sched.h> #include <sys/types.h> #include <unistd.h> #include <stdio.h> #include <string.h> #include <signal.h> #include <sys/syscall.h> #include <stdlib.h> #include <errno.h> #include <stdint.h> #include <sys/wait.h> #include <time.h> #ifndef __NR_clone3 #define __NR_clone3 -1 #endif static pid_t sys_clone3(struct clone_args *args) { return syscall(__NR_clone3, args, sizeof(struct clone_args)); } #define ptr_to_u64(ptr) ((unsigned long)((uintptr_t)(ptr))) time_t gethrtime (void) { struct timespec tp; time_t rc = 0; #ifdef CLOCK_MONOTONIC_RAW int r = clock_gettime (CLOCK_MONOTONIC_RAW, &tp); #else int r = clock_gettime (CLOCK_MONOTONIC, &tp); #endif if (r == 0) rc = ((time_t) tp.tv_sec) * 1e9 + (time_t) tp.tv_nsec; return rc; } volatile long ax; /* temp variable for long calculation */ static void aaa() { long long count = 0; time_t start = gethrtime (); do { ax = 0; for (int j = 0; j < 1000000; j++) ax = ax + 1; count++; } while (start + 1e9 > gethrtime ()); char buf[256]; snprintf(buf, sizeof (buf), "aaa(): Child process with pid: %lld count=%lld ax=%lld\n", (long long) getpid(), count, ax); write(1, buf, strlen(buf)); } volatile long bx; /* temp variable for long calculation */ static void bbb() { long long count = 0; time_t start = gethrtime (); do { bx = 0; for (int j = 0; j < 1000000; j++) bx = bx + 1; count++; } while (start + 1e9 > gethrtime ()); char buf[256]; snprintf(buf, sizeof (buf), "bbb(): Parent process with pid: %lld count=%lld bx=%lld\n", (long long) getpid(), count, bx); write(1, buf, strlen(buf)); } int main (int argc, char **argv) { int pidfd = -1; pid_t parent_tid = -1, pid = -1; struct clone_args args; memset(&args, 0, sizeof(args)); args.parent_tid = ptr_to_u64(&parent_tid); /* CLONE_PARENT_SETTID */ args.pidfd = ptr_to_u64(&pidfd); /* CLONE_PIDFD */ args.flags = CLONE_PIDFD | CLONE_PARENT_SETTID; args.exit_signal = SIGCHLD; pid = sys_clone3(&args); // pid = clone3(&args, sizeof(args)); if (pid < 0) { fprintf(stderr, "%s - Failed to create new process\n", strerror(errno)); exit(EXIT_FAILURE); } if (pid == 0) { printf("Child process with pid %d\n", getpid()); aaa(); exit(EXIT_SUCCESS); } bbb(); printf("Parent process received child's pid %d as return value\n", pid); printf("Parent process received child's pidfd %d\n", *(int *)args.pidfd); printf("Parent process received child's pid %d as return argument\n", *(pid_t *)args.parent_tid); if (waitid(P_ALL, pid, NULL, 0) == 0) { fprintf(stderr, "Managed to wait on CLONE_NO_WAITALL process with waitid(P_ALL)\n"); } return 0; } % gcc clone3.c % gprofng collect app -O t.er ./a.out Creating experiment directory t.er (Process ID: 535114) ... Child process with pid 535117 bbb(): Parent process with pid: 535114 count=331 bx=1000000 Parent process received child's pid 535117 as return value Parent process received child's pidfd 3 Parent process received child's pid 535117 as return argument aaa(): Child process with pid: 535117 count=336 ax=1000000 aaa is not in the function list: % gprofng display text -func t.er/ Functions sorted by metric: Exclusive Total CPU Time Excl. Total Incl. Total Name CPU CPU sec. % sec. % 0.650 100.00 0.650 100.00 <Total> 0.650 100.00 0.650 100.00 bbb 0. 0. 0.650 100.00 __libc_start_call_main 0. 0. 0.650 100.00 main -- You are receiving this mail because: You are on the CC list for the bug.