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

Add cache hit percentage to stats #2211

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Saruniks
Copy link

@Saruniks Saruniks commented Jun 21, 2024

Closes #2161

Inspiration from #614

Feedback is welcome.


No compile requests:

Compile requests                      0
Compile requests executed             0
Cache hits                            0
Cache misses                          0
Cache hits rate                       -
Cache timeouts                        0
Cache read errors                     0
Forced recaches                       0
Cache write errors                    0
Compilation failures                  0
Cache errors                          0
Non-cacheable compilations            0
Non-cacheable calls                   0
Non-compilation calls                 0
Unsupported compiler calls            0
Average cache write               0.000 s
Average compiler                  0.000 s
Average cache read hit            0.000 s
Failed distributed compilations       0
Cache location                  Local disk: "/home/ubuntu-user/.cache/sccache"
Use direct/preprocessor mode?   yes
Version (client)                0.8.1
Max cache size                       10 GiB

Zero cache hits:

Compile requests                    397
Compile requests executed           319
Cache hits                            0
Cache misses                        316
Cache misses (C/C++)                 52
Cache misses (Rust)                 264
Cache hits rate                    0.00 %
Cache hits rate (C/C++)            0.00 %
Cache hits rate (Rust)             0.00 %
Cache timeouts                        0
Cache read errors                     0
Forced recaches                       0
Cache write errors                    0
Compilation failures                  3
Cache errors                          0
Non-cacheable compilations            0
Non-cacheable calls                  73
Non-compilation calls                 5
Unsupported compiler calls            0
Average cache write               0.004 s
Average compiler                  0.370 s
Average cache read hit            0.000 s
Failed distributed compilations       0

Non-cacheable reasons:
crate-type                           50
unknown source language              18
-                                     3
-E                                    1
incremental                           1

Cache location                  Local disk: "/home/ubuntu-user/.cache/sccache"
Use direct/preprocessor mode?   yes
Version (client)                0.8.1
Cache size                          234 MiB
Max cache size                       10 GiB

Some cache hits:

Compile requests                   1189
Compile requests executed           957
Cache hits                          632
Cache hits (C/C++)                  104
Cache hits (Rust)                   528
Cache misses                        316
Cache misses (C/C++)                 52
Cache misses (Rust)                 264
Cache hits rate                   66.67 %
Cache hits rate (C/C++)           66.67 %
Cache hits rate (Rust)            66.67 %
Cache timeouts                        0
Cache read errors                     0
Forced recaches                       0
Cache write errors                    0
Compilation failures                  9
Cache errors                          0
Non-cacheable compilations            0
Non-cacheable calls                 217
Non-compilation calls                15
Unsupported compiler calls            0
Average cache write               0.004 s
Average compiler                  0.370 s
Average cache read hit            0.004 s
Failed distributed compilations       0

Non-cacheable reasons:
crate-type                          150
unknown source language              54
-                                     7
incremental                           3
-E                                    3

Cache location                  Local disk: "/home/ubuntu-user/.cache/sccache"
Use direct/preprocessor mode?   yes
Version (client)                0.8.1
Cache size                          234 MiB
Max cache size                       10 GiB

sccache --show-adv-stats:

Compile requests                     401
Compile requests executed            319
Cache hits                           316
Cache hits (c [gcc])                  52
Cache hits (rust)                    264
Cache misses                           0
Cache hits rate                   100.00 %
Cache hits rate (c [gcc])         100.00 %
Cache hits rate (rust)            100.00 %
Cache timeouts                         0
Cache read errors                      0
Forced recaches                        0
Cache write errors                     0
Compilation failures                   3
Cache errors                           0
Non-cacheable compilations             0
Non-cacheable calls                   77
Non-compilation calls                  5
Unsupported compiler calls             0
Average cache write                0.000 s
Average compiler                   0.000 s
Average cache read hit             0.002 s
Failed distributed compilations        0

Non-cacheable reasons:
crate-type                            51
unknown source language               18
-                                      5
incremental                            2
-E                                     1

Cache location                  Local disk: "/home/ubuntu-user/.cache/sccache"
Use direct/preprocessor mode?   yes
Version (client)                0.8.1
Cache size                           235 MiB
Max cache size                        10 GiB

@AJIOB
Copy link
Contributor

AJIOB commented Jun 27, 2024

Hi @Xuanwo,

Is it OK to you?

src/server.rs Outdated
@@ -1510,6 +1510,17 @@ impl Default for ServerStats {
}
}

macro_rules! set_percentage_stat {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a macro and not a function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Picked up code from #614 and experienced tunnel vision.

Function is probably a better choice here indeed.

@sylvestre
Copy link
Collaborator

Could you please add a test to verify the field is present? Thanks

@codecov-commenter
Copy link

codecov-commenter commented Jun 28, 2024

Codecov Report

Attention: Patch coverage is 65.78947% with 91 lines in your changes missing coverage. Please review.

Project coverage is 40.88%. Comparing base (0cc0c62) to head (dd35cfa).
Report is 64 commits behind head on main.

Files Patch % Lines
src/server.rs 45.31% 18 Missing and 52 partials ⚠️
tests/helpers/mod.rs 78.26% 11 Missing and 4 partials ⚠️
tests/cache_hit_rate.rs 91.30% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2211      +/-   ##
==========================================
+ Coverage   30.91%   40.88%   +9.97%     
==========================================
  Files          53       55       +2     
  Lines       20112    20394     +282     
  Branches     9755     9609     -146     
==========================================
+ Hits         6217     8339    +2122     
- Misses       7922     8004      +82     
+ Partials     5973     4051    -1922     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


let output = writer.get_output();

assert!(output.contains("Cache hits rate -"));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting case where PerLanguageCount::all() uses counts.values().sum() and not self.adv_counts.values().sum() in case of printing advanced stats.

In practice should never happen because PerLanguageCount::increment() is used to set the counts.

@@ -1700,7 +1780,7 @@ impl ServerInfo {

/// Print info to stdout in a human-readable format.
pub fn print(&self, advanced: bool) {
let (name_width, stat_width) = self.stats.print(advanced);
let (name_width, stat_width) = self.stats.print(&mut StdoutServerStatsWriter, advanced);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intrusive way to test the code. If anyone has an idea on how to test it in a better way it would be helpful to know.

I was thinking about writing similar test like in sccache_cargo.rs (using Command::new() and capturing the output), but I was hesitant because the test would not be fast.

I was thinking about refactoring this code to free functions and testing the free functions but then it would potentially not cover the whole use case.

@AJIOB
Copy link
Contributor

AJIOB commented Jul 15, 2024

Hi @Saruniks

Is it ready to be merged?

@Saruniks
Copy link
Author

Hello @AJIOB

Ready from my side. Unless perhaps someone has comments on the code and tests.

@AJIOB
Copy link
Contributor

AJIOB commented Jul 15, 2024

Hi @sylvestre & @Xuanwo
Can we merge it?

@sylvestre
Copy link
Collaborator

sylvestre commented Jul 15, 2024

i was hoping to have also integration tests like in https://github.com/mozilla/sccache/blob/main/.github/workflows/integration-tests.yml
and a verification that the json files contain the fields too

@sylvestre
Copy link
Collaborator

and sorry for the latency

@Saruniks
Copy link
Author

Ok. I'll add the integration test

@sylvestre
Copy link
Collaborator

many thanks :)

@Saruniks Saruniks force-pushed the add-hit-miss-ratio-to-stats branch from c50cc12 to dd35cfa Compare July 17, 2024 13:45
@Saruniks
Copy link
Author

Hello,

a) I added integration tests. Not to the GitHub Actions workflow like mentioned above, but "Rust" ones (see tests/cache_hit_rate.rs).

I could add extra jobs to the GitHub Actions workflow, no problems. But I thought that what I developed could be sufficient as no integration with external tool needs to be tested. Let me know if you think otherwise.

b) Regarding the json stats:
Apologies for not mentioning it before, but I didn't develop cache hit rate display for json stats.

The problem is that json stats is just serialized structs. When "StatsFormat::Text" stats are achieved by using "complex" print method.

    match fmt {
        StatsFormat::Text => stats.print(advanced),
        StatsFormat::Json => serde_json::to_writer(&mut io::stdout(), &stats)?,
    }

I am still not sure what would be the best way to implement cache hit rate for json stats. Maybe custom serialize implementation would work (and not derive trait like currently), but then it could be considered magic-like. But then calculating cache hit rate on every stats change could be considered too wasteful (or considered as calculated value anti-pattern).

So not sure how to proceed with json stats.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No new code in this file, only moved things around for deduplication

@sylvestre
Copy link
Collaborator

don't bother for the json output
thanks!

@sylvestre
Copy link
Collaborator

I guess you saw that some tests are failing

@Saruniks
Copy link
Author

I fixed the issue with failing tests. Checks should pass now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sccache lacks basic ratio (percentage) report in --show-stats
4 participants