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

Programmatic way to get the cache usage metrics #70

Open
payalghule opened this issue Sep 12, 2024 · 5 comments
Open

Programmatic way to get the cache usage metrics #70

payalghule opened this issue Sep 12, 2024 · 5 comments

Comments

@payalghule
Copy link

payalghule commented Sep 12, 2024

I can NOT use build-scan option due to certain limitations, Is there any way cache usage metrics can be read programmatically and stored? Also how can one identify cache's are coming from local cache or remote cache to measure cache effectiveness ?

@vlsi
Copy link
Contributor

vlsi commented Sep 19, 2024

You might try installing https://github.com/cdsap/Talaiot.
It captures information on local vs remote build cache efficiency: https://github.com/cdsap/Talaiot/blob/5a1fe716c92aa5d9895f543e75ddeebfd7d47df2/resources/taskcache.png

I have not tried it though.

@payalghule
Copy link
Author

payalghule commented Sep 20, 2024

Actually I am using the same plugin, but with it's 2.x version they removed cache related metrics : cdsap/Talaiot#349

example below :

in 1.x:

{
      "ms": 1,
      "taskName": "stripDebugDebugSymbols",
      "taskPath": ":stripDebugDebugSymbols",
      "state": "NO_SOURCE",
      "rootNode": false,
      "module": "no_module",
      "taskDependencies": [
        ":preDebugBuild"
      ],
      "workerId": "worker lease",
      "startMs": 1721298876614,
      "stopMs": 1721298876615,
      "critical": false,
      "isCacheEnabled": false,
      "isLocalCacheHit": false,
      "isLocalCacheMiss": false,
      "isRemoteCacheHit": false,
      "isRemoteCacheMiss": false
    },

now in 2.x:

{
      "ms": 2,
      "taskName": "stripDebugDebugSymbols",
      "taskPath": ":stripDebugDebugSymbols",
      "state": "SKIPPED",
      "rootNode": false,
      "module": "no_module",
      "startMs": 1726169815074,
      "stopMs": 1726169815076,
      `"type":` "com.android.build.gradle.internal.tasks.StripDebugSymbolsTask"
    },
    ```
    Let me know if there is some other way i could track those metrics usage.

@vlsi
Copy link
Contributor

vlsi commented Oct 2, 2024

Could you try org.gradle.internal.operations.notify.BuildOperationListenerManager and add BuildOperationListener that would capture the cache statistics?

I guess https://github.com/gradle/gradle/blob/d0fd4f96a43657af46b8c2165490f8070602b8e0/platforms/core-execution/build-cache/src/main/java/org/gradle/caching/internal/controller/service/OpFiringRemoteBuildCacheServiceHandle.java would generate the build operations.

@payalghule
Copy link
Author

I tried your suggestion @vlsi but i am NOT able to access org.gradle.internal.operations.notify.BuildOperationListenerManager as its gradle's internal API and with that compilation failed. Any idea on how to access it ? I did NOT find any other public APIs suitable for this use case.

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

No branches or pull requests

2 participants