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

feat: cost reporting via tests #116

Merged
merged 14 commits into from
Sep 23, 2021
Merged

feat: cost reporting via tests #116

merged 14 commits into from
Sep 23, 2021

Conversation

lgalabru
Copy link
Contributor

This PR starts addressing #41, by introducing a flag --cost that can be passed when running tests.

➜  counter git:(feat/cost-tracking) ✗ clarinet test --costs

Running file:///Users/ludovic/Coding/clarinet/clarinet-cli/examples/counter/tests/counter_test.ts
* Ensure that counter can be incremented multiples per block, accross multiple blocks ... ok (24ms)

Contract calls cost synthesis
+-----------+------------+------------+-----------------+-------------+----------------+--------------+
| ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.counter::increment                                        |
+-----------+------------+------------+-----------------+-------------+----------------+--------------+
|           | Runtime    | Read Count | Read Length     | Write Count | Write Length   | Tx per Block |
+-----------+------------+------------+-----------------+-------------+----------------+--------------+
| Max       | 838000     | 5          | 613 bytes       | 1           | 17 bytes       | 1550         |
+-----------+------------+------------+-----------------+-------------+----------------+--------------+
| ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.counter::read-counter                                     |
+-----------+------------+------------+-----------------+-------------+----------------+--------------+
|           | Runtime    | Read Count | Read Length     | Write Count | Write Length   | Tx per Block |
+-----------+------------+------------+-----------------+-------------+----------------+--------------+
| Max       | 617000     | 4          | 613 bytes       | 0           | 0 bytes        | 1937         |
+-----------+------------+------------+-----------------+-------------+----------------+--------------+
| Block Limits                                                                                        |
+-----------+------------+------------+-----------------+-------------+----------------+--------------+
| Mainnet   | 5000000000 | 7750       | 100000000 bytes | 7750        | 15000000 bytes | /            |
+-----------+------------+------------+-----------------+-------------+----------------+--------------+

The costs for every method explicitly invoked when mining tests blocks

        let block = chain.mineBlock([
            Tx.contractCall("counter", "increment", [types.uint(1)], wallet_1.address),
            ...
        ]);

are collected, and rendered in the terminal. If multiple invocations for a given method were collected, the most expensive instance is being displayed.

* feat: ability to cache repl sessions

* feat: create stacksjs-helper-generator extension
* chore: update repl

* feat: ability to cache repl sessions

* feat: create stacksjs-helper-generator extension

* feat: add decrement function (#109)
@codecov-commenter
Copy link

codecov-commenter commented Sep 14, 2021

Codecov Report

Merging #116 (8d8a5af) into main (21b91e5) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##            main    #116      +/-   ##
========================================
- Coverage   4.21%   4.17%   -0.04%     
========================================
  Files        129     129              
  Lines      27546   27796     +250     
========================================
  Hits        1161    1161              
- Misses     26385   26635     +250     
Flag Coverage Δ
unittests 4.17% <0.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/frontend/cli.rs 0.00% <0.00%> (ø)
src/integrate/events_observer.rs 0.00% <0.00%> (ø)
src/main.rs 25.00% <ø> (ø)
src/runnner/deno.rs 0.00% <0.00%> (ø)
src/runnner/mod.rs 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21b91e5...8d8a5af. Read the comment docs.

@kyranjamie
Copy link

abbreviated flag -c 🤔

@LNow
Copy link
Contributor

LNow commented Sep 15, 2021

This looks great!!
Would it be possible to add % values to this report? So that we won't have to calculate it on a side, to find out if our contract will eat 0.01% or 10% of a whole block execution costs limits.

@lgalabru
Copy link
Contributor Author

lgalabru commented Sep 15, 2021

@LNow already the case, the latest version of the reports looks like this:

Screen Shot 2021-09-15 at 4 06 12 PM

@LNow
Copy link
Contributor

LNow commented Sep 15, 2021

I love it. @whoabuddy look at this!

@lgalabru lgalabru requested a review from kantai September 16, 2021 15:46
@lgalabru lgalabru marked this pull request as ready for review September 16, 2021 15:46
@lgalabru
Copy link
Contributor Author

Screen.Recording.2021-09-16.at.11.33.43.AM.mov

@unclemantis
Copy link

Please build into windows binary .msi file. I downloaded the recent msi for x63 and the --costs flag does not work.

Thank you!!!!

@lgalabru lgalabru changed the base branch from main to develop September 23, 2021 21:59
# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	deno/ext/stacksjs-helper-generator.ts
#	examples/counter/contracts/counter.clar
#	src/frontend/cli.rs
#	src/integrate/events_observer.rs
#	src/runnner/deno.rs
@lgalabru lgalabru merged commit a0117aa into develop Sep 23, 2021
@lgalabru lgalabru deleted the feat/cost-tracking branch September 23, 2021 22:21
blockstack-devops pushed a commit that referenced this pull request Oct 5, 2021
# [0.17.0](v0.16.0...v0.17.0) (2021-10-05)

### Features

* ability to cache repl sessions ([5e086cb](5e086cb))
* acknowledge check ok ([f6a6143](f6a6143))
* add decrement function ([#109](#109)) ([56e5477](56e5477))
* cascade changes ([fb6d9a9](fb6d9a9))
* cost reporting via tests ([#116](#116)) ([a0117aa](a0117aa))
* create abi-generator extension ([e5b46c4](e5b46c4))
* revamp extension usage ([ec8cdfc](ec8cdfc))
@blockstack-devops
Copy link
Collaborator

🎉 This PR is included in version 0.17.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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.

6 participants