perf data idle time
- Dominant language
- TypeScript
- Stars
- 6.8k
- Forks
- 320
- PR merge metrics
- No merged PRs in 30d
Description
speedscope provides a great time order view.
But for perf data, when the program is idle, speedscope will think that the time is consumed by the next sampled call stack. This is wrong, the program should be idle at this time.
```text
$ cat test.c
#include
#include
#include
#include
#include
#include
void fselect() {
fd_set rfds;
struct timeval tv;
int retval;
FD_ZERO(&rfds);
FD_SET(0, &rfds);
tv.tv_sec = 2;
tv.tv_usec = 0;
retval = select(1, &rfds, NULL, NULL, &tv);
if (retval == -1)
perror("select()");
else if (retval)
printf("Data is available now.\n");
/* FD_ISSET(0, &rfds) will be true. */
else
printf("No data within two seconds.\n");
}
void timed(int microseconds) {
int sec, usec, diff;
struct timeval tv;
gettimeofday(&tv, NULL);
// printf("begin seconds : %ld micro seconds : %ld\n", tv.tv_sec, tv.tv_usec);
sec = tv.tv_sec;
usec = tv.tv_usec;
while (1) {
gettimeofday(&tv, NULL);
diff = (tv.tv_sec - sec) * 1000000 + tv.tv_usec - usec;
if (diff > microseconds) {
// printf("end seconds : %ld micro seconds : %ld\n", tv.tv_sec, tv.tv_usec);
break;
}
}
}
void a() { timed(500000); }
void b() { timed(500000); }
void c() { timed(500000); }
void d() { timed(500000); }
void e() { timed(500000); }
void *fthread(void *args) {
func();
return NULL;
}
void func() {
while (1) {
a();
b();
fselect();
c();
d();
e();
printf("sleep begin\n");
sleep(1.5);
printf("sleep end\n");
}
}
int main() {
pthread_t thread;
pthread_create(&thread, NULL, fthread, NULL);
func();
return 0;
}
$ gcc test.c -O0 -g -lpthread && ./a.out
$ perf record -F 99 -p 320355 -g -e cpu-clock
```
The result now looks like this:

A more correct result should look like this:

Contributor guide
Assessment
This issue has not been assessed yet.