Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timing profiles don't include non-CPU times #86066

Open
andrewbanchich opened this issue Jun 6, 2021 · 6 comments
Open

Timing profiles don't include non-CPU times #86066

andrewbanchich opened this issue Jun 6, 2021 · 6 comments
Labels
A-self-profile Area: Self-profiling feature of the compiler C-bug Category: This is a bug.

Comments

@andrewbanchich
Copy link
Contributor

When debugging slow compile times, I ran cargo rustc --profile check --manifest-path ./my-crate/Cargo.toml -- -Zself-profile. summarize gave Total cpu time: 2.6826241s, but the former command said it finished in 1 minute 45 seconds.

The issue turned out to be SQLx query macros, which make network requests to a live database when expanded.

I think it would be useful to include that information in timing profiles.

@andrewbanchich andrewbanchich added the C-bug Category: This is a bug. label Jun 6, 2021
@jonas-schievink
Copy link
Contributor

"CPU time" generally is the time the process is scheduled on a CPU. Network requests are not included in that time, since they are an I/O operation.

@andrewbanchich
Copy link
Contributor Author

Yes, but it would have been helpful to have timings include the network / non-CPU times as well to make it more obvious what the problem was.

Is that something which could be added?

@andrewbanchich andrewbanchich changed the title Timing profiles don't include proc macros Timing profiles don't include non-CPU times Jun 6, 2021
@wesleywiser
Copy link
Member

-Zself-profile measures wall-clock time not CPU time so it should have picked this up.

@wesleywiser wesleywiser added the A-self-profile Area: Self-profiling feature of the compiler label Jun 7, 2021
@andrewbanchich
Copy link
Contributor Author

Thanks for clarifying @wesleywiser . So should the output file be changed to not say Total cpu time?

@lqd
Copy link
Member

lqd commented Jun 8, 2021

Is there a way to reproduce the issue (ideally, without sqlx and an actual DB) ?

For example, I am unable to trigger this behavior if I just thread::sleep for a few seconds in a:

  • custom derive
  • function-like proc macro
  • attribute macro

-Z self-profile seemed to take all 3 in into account in my test: the time sleeping was accounted for in the expand_crate query.

Could multiple builds without changes have been involved ? So that maybe some of the proc macros weren't re-run on the subsequent profiled run (I also believe sqlx has a way to cache the results of their network requests and query analysis between builds, but that doesn't seem to be involved here).

@andrewbanchich
Copy link
Contributor Author

andrewbanchich commented Jun 26, 2021

@lqd

Is there a way to reproduce the issue (ideally, without sqlx and an actual DB) ?

I'm not sure, I haven't used any other macros that make network requests before.

Could multiple builds without changes have been involved ?

For these stats, I built the entire project, added a newline to invalidate the cache, recorded the time, removed the newline, profiled it with timings, so to the best of my understanding it should be an apples to apples comparison.

Also, the summarize command only says Total cpu time: 2.6826241s, but it was actually much longer than that. It just didn't record it in the total CPU time stat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-self-profile Area: Self-profiling feature of the compiler C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants