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 3 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 45.31250% with 70 lines in your changes missing coverage. Please review.

Project coverage is 51.56%. Comparing base (0cc0c62) to head (c50cc12).
Report is 61 commits behind head on main.

Files Patch % Lines
src/server.rs 45.31% 18 Missing and 52 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2211       +/-   ##
===========================================
+ Coverage   30.91%   51.56%   +20.65%     
===========================================
  Files          53       53               
  Lines       20112    20577      +465     
  Branches     9755     9725       -30     
===========================================
+ Hits         6217    10611     +4394     
- Misses       7922     7954       +32     
+ Partials     5973     2012     -3961     

☔ 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 :)

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