Bug 207243

Summary: `perf stat --timeout` does not return after timeout expires
Product: Tracing/Profiling Reporter: Konstantin Kharlamov (hi-angel)
Component: Perf toolAssignee: Arnaldo Carvalho de Melo (acme)
Status: ASSIGNED ---    
Severity: normal CC: jolsa
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 5.6.2 Subsystem:
Regression: No Bisected commit-id:
Attachments: Fix for 'perf stat --timeout N workload-to-start'

Description Konstantin Kharlamov 2020-04-14 22:22:34 UTC
Description of `timeout` option for `perf stat` says "Stop the perf stat session and print count deltas after N milliseconds". Unfortunately the session does not stop after the time expires.

# Steps to reproduce

1. Run:
    perf stat --timeout 1000 sleep 1h
2. Wait a second.

## Expected

As timeout option is set to 1000ms aka 1 second, a second later the command should return and print statistics.

## Actual

Nothing happens.
Comment 1 Arnaldo Carvalho de Melo 2020-04-15 13:58:56 UTC
So I reproduced the problem, in my testing only system wide mode is working:

[root@five ~]# perf stat -e cycles --timeout 1000 -a

 Performance counter stats for 'system wide':

     7,762,164,845      cycles                                                      

       1.000529516 seconds time elapsed

[root@five ~]# perf stat -e cycles --timeout 150 -a

 Performance counter stats for 'system wide':

     1,291,118,172      cycles                                                      

       0.150428442 seconds time elapsed

[root@five ~]#

I'll try to investigate and fix it, thanks for the report.
Comment 2 Arnaldo Carvalho de Melo 2020-04-15 14:41:15 UTC
Created attachment 288499 [details]
Fix for 'perf stat --timeout N workload-to-start'
Comment 3 Konstantin Kharlamov 2020-04-15 14:50:29 UTC
Wow that was quick! Thank you!
Comment 4 Arnaldo Carvalho de Melo 2020-04-15 14:56:16 UTC
:-)

Can I take that as a:

Tested-by: hi-angel@yandex.ru

And add that to the patch, in addition to:

Reported-by: hi-angel@yandex.ru

And also your name to add there as well if possible?

- Arnaldo
Comment 5 Konstantin Kharlamov 2020-04-15 15:01:04 UTC
(In reply to Arnaldo Carvalho de Melo from comment #4)
> :-)
> 
> Can I take that as a:
> 
> Tested-by: hi-angel@yandex.ru
> 
> And add that to the patch, in addition to:
> 
> Reported-by: hi-angel@yandex.ru
> 
> And also your name to add there as well if possible?
> 
> - Arnaldo

Sounds great, though I gotta need some time. I will test it in a few hours!
Comment 6 Konstantin Kharlamov 2020-04-15 16:47:58 UTC
(In reply to Arnaldo Carvalho de Melo from comment #4)
> :-)
> 
> Can I take that as a:
> 
> Tested-by: hi-angel@yandex.ru
> 
> And add that to the patch, in addition to:
> 
> Reported-by: hi-angel@yandex.ru
> 
> And also your name to add there as well if possible?
> 
> - Arnaldo

Thank you, I tested it, works for me. I replied on the ML