diff --git a/.github/workflows/performance_counters.yml b/.github/workflows/performance_counters.yml new file mode 100644 index 000000000..cb2794d30 --- /dev/null +++ b/.github/workflows/performance_counters.yml @@ -0,0 +1,28 @@ +name: performance_counters + +on: + push: + branches: [master] + pull_request: + paths: + - rust/performance_counters/** + - .github/workflows/performance_counters.yml + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rust-performance_counters: + runs-on: ubuntu-24.04 + container: ghcr.io/dfinity/icp-dev-env-rust:1.0.0 + env: + ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 + - name: Deploy and test + working-directory: rust/performance_counters + run: | + icp network start -d + icp deploy + make test diff --git a/rust/performance_counters/.devcontainer/devcontainer.json b/rust/performance_counters/.devcontainer/devcontainer.json deleted file mode 100644 index ebb0b8bcc..000000000 --- a/rust/performance_counters/.devcontainer/devcontainer.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "ICP Dev Environment", - "image": "ghcr.io/dfinity/icp-dev-env-slim:22", - "forwardPorts": [4943, 5173], - "portsAttributes": { - "4943": { - "label": "dfx", - "onAutoForward": "ignore" - }, - "5173": { - "label": "vite", - "onAutoForward": "openBrowser" - } - }, - "customizations": { - "vscode": { - "extensions": ["dfinity-foundation.vscode-motoko"] - } - } -} diff --git a/rust/performance_counters/BUILD.md b/rust/performance_counters/BUILD.md deleted file mode 100644 index 24cfcb754..000000000 --- a/rust/performance_counters/BUILD.md +++ /dev/null @@ -1,113 +0,0 @@ -# Continue building locally - -Projects deployed through ICP Ninja are temporary; they will only be live for 20 minutes before they are removed. The command-line tool `dfx` can be used to continue building your ICP Ninja project locally and deploy it to the mainnet. - -To migrate your ICP Ninja project off of the web browser and develop it locally, follow these steps. - -### 1. Install developer tools. - -You can install the developer tools natively or use Dev Containers. - -#### Option 1: Natively install developer tools - -> Installing `dfx` natively is currently only supported on macOS and Linux systems. On Windows, it is recommended to use the Dev Containers option. - -1. Install `dfx` with the following command: - -``` - -sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)" - -``` - -> On Apple Silicon (e.g., Apple M1 chip), make sure you have Rosetta installed (`softwareupdate --install-rosetta`). - -2. [Install NodeJS](https://nodejs.org/en/download/package-manager). - -3. For Rust projects, you will also need to: - -- Install [Rust](https://doc.rust-lang.org/cargo/getting-started/installation.html#install-rust-and-cargo): `curl https://sh.rustup.rs -sSf | sh` - -- Install [candid-extractor](https://crates.io/crates/candid-extractor): `cargo install candid-extractor` - -4. For Motoko projects, you will also need to: - -- Install the Motoko package manager [Mops](https://docs.mops.one/quick-start#2-install-mops-cli): `npm i -g ic-mops` - -Lastly, navigate into your project's directory that you downloaded from ICP Ninja. - -#### Option 2: Dev Containers - -Continue building your projects locally by installing the [Dev Container extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) for VS Code and [Docker](https://docs.docker.com/engine/install/). - -Make sure Docker is running, then navigate into your project's directory that you downloaded from ICP Ninja and start the Dev Container by selecting `Dev-Containers: Reopen in Container` in VS Code's command palette (F1 or Ctrl/Cmd+Shift+P). - -> Note that local development ports (e.g. the ports used by `dfx` or `vite`) are forwarded from the Dev Container to your local machine. In the VS code terminal, use Ctrl/Cmd+Click on the displayed local URLs to open them in your browser. To view the current port mappings, click the "Ports" tab in the VS Code terminal window. - -### 2. Start the local development environment. - -``` -dfx start --background -``` - -### 3. Create a local developer identity. - -To manage your project's canisters, it is recommended that you create a local [developer identity](https://internetcomputer.org/docs/building-apps/getting-started/identities) rather than use the `dfx` default identity that is not stored securely. - -To create a new identity, run the commands: - -``` - -dfx identity new IDENTITY_NAME - -dfx identity use IDENTITY_NAME - -``` - -Replace `IDENTITY_NAME` with your preferred identity name. The first command `dfx start --background` starts the local `dfx` processes, then `dfx identity new` will create a new identity and return your identity's seed phase. Be sure to save this in a safe, secure location. - -The third command `dfx identity use` will tell `dfx` to use your new identity as the active identity. Any canister smart contracts created after running `dfx identity use` will be owned and controlled by the active identity. - -Your identity will have a principal ID associated with it. Principal IDs are used to identify different entities on ICP, such as users and canisters. - -[Learn more about ICP developer identities](https://internetcomputer.org/docs/building-apps/getting-started/identities). - -### 4. Deploy the project locally. - -Deploy your project to your local developer environment with: - -``` -npm install -dfx deploy - -``` - -Your project will be hosted on your local machine. The local canister URLs for your project will be shown in the terminal window as output of the `dfx deploy` command. You can open these URLs in your web browser to view the local instance of your project. - -### 5. Obtain cycles. - -To deploy your project to the mainnet for long-term public accessibility, first you will need [cycles](https://internetcomputer.org/docs/building-apps/getting-started/tokens-and-cycles). Cycles are used to pay for the resources your project uses on the mainnet, such as storage and compute. - -> This cost model is known as ICP's [reverse gas model](https://internetcomputer.org/docs/building-apps/essentials/gas-cost), where developers pay for their project's gas fees rather than users pay for their own gas fees. This model provides an enhanced end user experience since they do not need to hold tokens or sign transactions when using a dapp deployed on ICP. - -> Learn how much a project may cost by using the [pricing calculator](https://internetcomputer.org/docs/building-apps/essentials/cost-estimations-and-examples). - -Cycles can be obtained through [converting ICP tokens into cycles using `dfx`](https://internetcomputer.org/docs/building-apps/developer-tools/dfx/dfx-cycles#dfx-cycles-convert). - -### 6. Deploy to the mainnet. - -Once you have cycles, run the command: - -``` - -dfx deploy --network ic - -``` - -After your project has been deployed to the mainnet, it will continuously require cycles to pay for the resources it uses. You will need to [top up](https://internetcomputer.org/docs/building-apps/canister-management/topping-up) your project's canisters or set up automatic cycles management through a service such as [CycleOps](https://cycleops.dev/). - -> If your project's canisters run out of cycles, they will be removed from the network. - -## Additional examples - -Additional code examples and sample applications can be found in the [DFINITY examples repo](https://github.com/dfinity/examples). diff --git a/rust/performance_counters/Cargo.lock b/rust/performance_counters/Cargo.lock index 83d97695d..4a968368d 100644 --- a/rust/performance_counters/Cargo.lock +++ b/rust/performance_counters/Cargo.lock @@ -1,12 +1,21 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "ar_archive_writer" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4087686b4b0a3427190bae57a1d9a478dbb2d40c5dc1bd6e2b6d797913bdd348" +dependencies = [ + "object", +] [[package]] name = "arrayvec" @@ -16,9 +25,17 @@ checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "backend" +version = "0.1.0" +dependencies = [ + "candid", + "ic-cdk", +] [[package]] name = "binread" @@ -60,9 +77,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "candid" -version = "0.10.0" +version = "0.10.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2525ab7a58543c132da8c780abe3aa1ba394ddcc1888a4ad2ba4f5100906ebe" +checksum = "f8f781afa4a1303e3eab4ada0720a874942bcfa936ce01b816ac6378945c43a9" dependencies = [ "anyhow", "binread", @@ -78,69 +95,104 @@ dependencies = [ "serde", "serde_bytes", "stacker", - "thiserror", + "thiserror 1.0.69", ] [[package]] name = "candid_derive" -version = "0.6.5" +version = "0.10.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "970c220da8aa2fa6f7ef5dbbf3ea5b620a59eb3ac107cfb95ae8c6eebdfb7a08" +checksum = "ad6ae8e7944dd0035651bc0e7b3a3e4cb16f5fc43f8ae4fd76b36ff2cd52759f" dependencies = [ "lazy_static", "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.118", ] [[package]] name = "cc" -version = "1.0.83" +version = "1.2.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +checksum = "dad887fd958be91b5098c0248def011f4523ab786cd411be668777e55063501f" dependencies = [ - "libc", + "find-msvc-tools", + "shlex", ] [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "cpufeatures" -version = "0.2.11" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" dependencies = [ "libc", ] [[package]] name = "crc32fast" -version = "1.3.2" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" dependencies = [ "cfg-if", ] [[package]] name = "crypto-common" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" dependencies = [ "generic-array", "typenum", ] +[[package]] +name = "darling" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25ae13da2f202d56bd7f91c25fba009e7717a1e4a1cc98a76d844b65ae912e9d" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9865a50f7c335f53564bb694ef660825eb8610e0a53d3e11bf1b0d3df31e03b0" +dependencies = [ + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 2.0.118", +] + +[[package]] +name = "darling_macro" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" +dependencies = [ + "darling_core", + "quote", + "syn 2.0.118", +] + [[package]] name = "data-encoding" -version = "2.5.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5" +checksum = "a4ae5f15dda3c708c0ade84bfee31ccab44a3da4f88015ed22f63732abe300c8" [[package]] name = "digest" @@ -154,9 +206,15 @@ dependencies = [ [[package]] name = "either" -version = "1.9.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] name = "generic-array" @@ -168,6 +226,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hex" version = "0.4.3" @@ -176,77 +240,110 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "ic-cdk" -version = "0.12.0" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4ec8231f413b8a4d74b99d7df26d6e917d6528a6245abde27f251210dcf9b72" +checksum = "6a7971f4983db147afbbc4e7f87f60b09fcd60ac707af37ff3d2468dcddbf551" dependencies = [ "candid", + "ic-cdk-executor", "ic-cdk-macros", + "ic-error-types", "ic0", + "pin-project-lite", "serde", - "serde_bytes", + "thiserror 2.0.18", +] + +[[package]] +name = "ic-cdk-executor" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33716b730ded33690b8a704bff3533fda87d229e58046823647d28816e9bcee7" +dependencies = [ + "ic0", + "slotmap", + "smallvec", ] [[package]] name = "ic-cdk-macros" -version = "0.8.2" +version = "0.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba23aedf7b8f89201dd778ad1bc8a04c35e3fda6fa6402f51da2cd9bb21045e6" +checksum = "a7c20c002200c720958f321bb78b4d4987fc2c380bf9ef69ed4404730810f45f" dependencies = [ "candid", + "darling", "proc-macro2", "quote", + "syn 2.0.118", +] + +[[package]] +name = "ic-error-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbeeb3d91aa179d6496d7293becdacedfc413c825cac79fd54ea1906f003ee55" +dependencies = [ "serde", - "serde_tokenstream", - "syn 1.0.109", + "strum", + "strum_macros", ] [[package]] name = "ic0" -version = "0.21.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a54b5297861c651551676e8c43df805dad175cc33bc97dbd992edbbb85dcbcdf" +checksum = "c77c8932bff1f09502d0d8c079d5a206a06afe523e35e816162cf4d30b5bf80d" [[package]] name = "ic_principal" -version = "0.1.0" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899a4e8ddada85b91a2fe32b4dc6c0d475ef7bfef3f51cf2aecb26ee4ac4724f" +checksum = "1aea751965eaf92990be8c79c64b4f3174ff22dd3604e6696a06a494afbaba2a" dependencies = [ "crc32fast", "data-encoding", - "hex", "serde", - "serde_bytes", "sha2", - "thiserror", + "thiserror 1.0.69", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "leb128" -version = "0.2.5" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" +checksum = "c83bff1d572d6b9aeef67ddfc8448e4a3737909cb28e81f97c791b9018703e52" [[package]] name = "libc" -version = "0.2.150" +version = "0.2.186" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" + +[[package]] +name = "memchr" +version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" +checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4" [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ - "autocfg", "num-integer", "num-traits", "serde", @@ -254,43 +351,48 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.17" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] +[[package]] +name = "object" +version = "0.37.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe" +dependencies = [ + "memchr", +] + [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] -name = "performance_counters" -version = "1.0.0" -dependencies = [ - "candid", - "ic-cdk", - "ic-cdk-macros", -] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] name = "pretty" -version = "0.12.3" +version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b55c4d17d994b637e2f4daf6e5dc5d660d209d5642377d675d7a1c3ab69fa579" +checksum = "0d22152487193190344590e4f30e219cf3fe140d9e7a3fdb683d82aa2c5f4156" dependencies = [ "arrayvec", "typed-arena", @@ -299,99 +401,149 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] [[package]] name = "psm" -version = "0.1.21" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" +checksum = "645dbe486e346d9b5de3ef16ede18c26e6c70ad97418f4874b8b1889d6e761ea" dependencies = [ + "ar_archive_writer", "cc", ] [[package]] name = "quote" -version = "1.0.33" +version = "1.0.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" dependencies = [ "proc-macro2", ] [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" dependencies = [ + "serde_core", "serde_derive", ] [[package]] name = "serde_bytes" -version = "0.11.12" +version = "0.11.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" +checksum = "a5d440709e79d88e51ac01c4b72fc6cb7314017bb7da9eeff678aa94c10e3ea8" dependencies = [ "serde", + "serde_core", ] [[package]] -name = "serde_derive" -version = "1.0.193" +name = "serde_core" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.39", + "serde_derive", ] [[package]] -name = "serde_tokenstream" -version = "0.1.7" +name = "serde_derive" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "797ba1d80299b264f3aac68ab5d12e5825a561749db4df7cd7c8083900c5d4e9" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", - "serde", - "syn 1.0.109", + "quote", + "syn 2.0.118", ] [[package]] name = "sha2" -version = "0.10.8" +version = "0.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", "cpufeatures", "digest", ] +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "slotmap" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdd58c3c93c3d278ca835519292445cb4b0d4dc59ccfdf7ceadaab3f8aeb4038" +dependencies = [ + "version_check", +] + +[[package]] +name = "smallvec" +version = "1.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" + [[package]] name = "stacker" -version = "0.1.15" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce" +checksum = "640c8cdd92b6b12f5bcb1803ca3bbf5ab96e5e6b6b96b9ab77dabe9e880b3190" dependencies = [ "cc", "cfg-if", "libc", "psm", - "winapi", + "windows-sys", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.118", ] [[package]] @@ -407,9 +559,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.39" +version = "2.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" +checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" dependencies = [ "proc-macro2", "quote", @@ -418,22 +570,42 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ - "thiserror-impl", + "thiserror-impl 2.0.18", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.39", + "syn 2.0.118", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.118", ] [[package]] @@ -444,46 +616,39 @@ checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" [[package]] name = "typenum" -version = "1.17.0" +version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" [[package]] name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "winapi" -version = "0.3.9" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "windows-link" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "windows-sys" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] diff --git a/rust/performance_counters/Cargo.toml b/rust/performance_counters/Cargo.toml index 3b248f68a..d1e49e317 100644 --- a/rust/performance_counters/Cargo.toml +++ b/rust/performance_counters/Cargo.toml @@ -1,12 +1,3 @@ -[package] -edition = "2021" -name = "performance_counters" -version = "1.0.0" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -candid = "0.10" -ic-cdk = "0.12" -ic-cdk-macros = "0.8" +[workspace] +members = ["backend"] +resolver = "2" diff --git a/rust/performance_counters/Makefile b/rust/performance_counters/Makefile index bdc9ce3ff..8fd26afd4 100644 --- a/rust/performance_counters/Makefile +++ b/rust/performance_counters/Makefile @@ -1,38 +1,20 @@ -.PHONY: all -all: build - -.PHONY: build -.SILENT: build -build: - dfx canister create --all - dfx build - -.PHONY: install -.SILENT: install -install: build - dfx canister install performance_counters - -.PHONY: upgrade -.SILENT: upgrade -upgrade: build - dfx canister install performance_counters --mode=upgrade +.PHONY: test -.PHONY: deploy -.SILENT: deploy -deploy: - # Deploy the canisters and run periodic tasks with 1s interval. - dfx deploy performance_counters +test: + @echo "=== Test 1: for_update returns non-zero instruction counters ===" + @result=$$(icp canister call backend for_update '()') && \ + echo "$$result" && \ + echo "$$result" | grep -qv '(0 : nat64, 0 : nat64)' && \ + echo "PASS" || (echo "FAIL" && exit 1) -.PHONY: test -.SILENT: test -test: deploy - # Wait at least 2 seconds. - sleep 2 - # Validate the counters are non-zero. - dfx canister call performance_counters for_update | grep -vw '0' && echo 'PASS' - dfx canister call performance_counters for_composite_query | grep -vw '0' && echo 'PASS' + @echo "=== Test 2: for_composite_query returns non-zero instruction counters ===" + @result=$$(icp canister call --query backend for_composite_query '()') && \ + echo "$$result" && \ + echo "$$result" | grep -qv '(0 : nat64, 0 : nat64)' && \ + echo "PASS" || (echo "FAIL" && exit 1) -.PHONY: clean -.SILENT: clean -clean: - rm -fr .dfx + @echo "=== Test 3: example returns non-zero instruction counters ===" + @result=$$(icp canister call --query backend example '()') && \ + echo "$$result" && \ + echo "$$result" | grep -qv '(0 : nat64, 0 : nat64)' && \ + echo "PASS" || (echo "FAIL" && exit 1) diff --git a/rust/performance_counters/README.md b/rust/performance_counters/README.md index c4262cf2e..3011c2d8f 100644 --- a/rust/performance_counters/README.md +++ b/rust/performance_counters/README.md @@ -1,12 +1,12 @@ -# Performance counter +# Performance counters -A canister can query one of the "performance counters", which is a deterministic monotonically increasing integer approximating the amount of work the canister has done. Developers might use this data to profile and optimize the canister performance. +A canister can query one of the "performance counters", which is a deterministic monotonically increasing integer approximating the amount of work the canister has done. Developers can use this data to profile and optimize canister performance. ```Candid ic0.performance_counter : (counter_type : i32) -> i64 ``` -The argument `type` decides which performance counter to return: +The argument `counter_type` decides which performance counter to return: - 0 : current execution instruction counter. The number of WebAssembly instructions the canister has executed @@ -29,40 +29,46 @@ The argument `type` decides which performance counter to return: In the future, ICP might expose more performance counters. -## Deploying from ICP Ninja +## Build and deploy from the command line -[![](https://icp.ninja/assets/open.svg)](https://icp.ninja/editor?g=https://github.com/dfinity/examples/tree/master/rust/performance_counters) +### Prerequisites -## Build and deploy from the command-line +- Node.js +- icp-cli: `npm install -g @icp-sdk/icp-cli @icp-sdk/ic-wasm` -### 1. [Download and install the IC SDK.](https://internetcomputer.org/docs/building-apps/getting-started/install) +### Install -### 2. Download your project from ICP Ninja using the 'Download files' button on the upper left corner, or [clone the GitHub examples repository.](https://github.com/dfinity/examples/) +```bash +git clone https://github.com/dfinity/examples +cd examples/rust/performance_counters +``` -### 3. Navigate into the project's directory. +### Deploy and test -### 4. Deploy the project to your local environment. +```bash +icp network start -d +icp deploy +make test +icp network stop +``` -Run `dfx start`, then open a new terminal and run `dfx deploy` to deploy the project to your local environment. +### Calling the canister -Call `performance_counters` canister `for_update` method: +Call `backend` canister `for_update` method: ```sh -dfx canister call performance_counters for_update +icp canister call backend for_update '()' ``` Example output: ```sh -% dfx canister call performance_counters for_update (6_618_678 : nat64, 19_886_107 : nat64) ``` Note how the current message execution counter (~6M instructions) is much different from the call context counter (~19M instructions). -### 5. Check the first terminal window for more details. - -Example log output: +The canister also prints detailed logs. Example log output for `for_update`: ```text Performance counters for update call: current (0) call context (1) @@ -76,18 +82,17 @@ Performance counters for update call: current (0) call context (1) Note how the current execution instruction counter (0) stays at ~6M instructions after each await point. By contrast, the call context performance counter (1) is monotonically increasing (~6M, ~13M, ~19M instructions). -Also note, that both counters start over for each nested execution (~12K instructions). +Also note that both counters start over for each nested execution (~12K instructions). -### 6. Repeat the steps above calling `for_composite_query` method. +Call `for_composite_query` method: ```sh -dfx canister call performance_counters for_composite_query +icp canister call --query backend for_composite_query '()' ``` Example output: ```sh -% dfx canister call performance_counters for_update (6_621_477 : nat64, 19_893_467 : nat64) ``` @@ -106,4 +111,4 @@ Note the same performance counters behavior for composite queries. ## Security considerations and best practices -If you base your application on this example, it is recommended that you familiarize yourself with and adhere to the [security best practices](https://internetcomputer.org/docs/building-apps/security/overview) for developing on ICP. This example may not implement all the best practices. +Refer to the [security best practices](https://docs.internetcomputer.org/guides/security/overview) for information on security and best practices for your ICP app. diff --git a/rust/performance_counters/backend/Cargo.toml b/rust/performance_counters/backend/Cargo.toml new file mode 100644 index 000000000..a4ca6ee17 --- /dev/null +++ b/rust/performance_counters/backend/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "backend" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib"] +path = "lib.rs" + +[dependencies] +candid = "0.10" +ic-cdk = "0.20" diff --git a/rust/performance_counters/src/lib.rs b/rust/performance_counters/backend/lib.rs similarity index 67% rename from rust/performance_counters/src/lib.rs rename to rust/performance_counters/backend/lib.rs index c6c6934ca..ff576d3be 100644 --- a/rust/performance_counters/src/lib.rs +++ b/rust/performance_counters/backend/lib.rs @@ -1,8 +1,6 @@ //! An example of performance counters usage. -//! -//! dfx deploy && dfx canister call performance_counters get -// The following performance counters supported: +// The following performance counters are supported: // // - 0 : current execution instruction counter. // The number of WebAssembly instructions the canister has executed @@ -21,11 +19,9 @@ // (ignoring WebAssembly instructions executed within any further downstream calls // of `composite_query_helper`). // -// In the future, the IC might expose more performance counters. -use ic_cdk::{ - api::{call_context_instruction_counter, instruction_counter, performance_counter}, - call, id, -}; +// In the future, ICP might expose more performance counters. +use ic_cdk::api::{call_context_instruction_counter, canister_self, instruction_counter, performance_counter}; +use ic_cdk::call::Call; /// Pretty print the `title` and a corresponding `tuple` with counters. fn pretty_print(title: N, counters: (T, T)) { @@ -46,41 +42,45 @@ fn counters() -> (u64, u64) { } /// Emulate a nested inter-canister update call. -#[ic_cdk_macros::update] +#[ic_cdk::update] fn nested_update_call() -> (u64, u64) { counters() } /// Emulate a nested inter-canister composite query call. -#[ic_cdk_macros::query(composite = true)] +#[ic_cdk::query(composite = true)] fn nested_composite_query_call() -> (u64, u64) { counters() } -/// Emulate a nested inter-canister update call. -#[ic_cdk_macros::query] +/// Emulate a nested inter-canister query call. +#[ic_cdk::query] fn nested_call() {} //////////////////////////////////////////////////////////////////////// // Canister interface //////////////////////////////////////////////////////////////////////// -/// Example usage: `dfx deploy && dfx canister call performance_counters for_update` -#[ic_cdk_macros::update] +/// Example usage: `icp canister call backend for_update` +#[ic_cdk::update] async fn for_update() -> (u64, u64) { do_some_work(); let before = counters(); - let inside_1st: (u64, u64) = ic_cdk::call(ic_cdk::id(), "nested_update_call", ()) + let inside_1st: (u64, u64) = Call::unbounded_wait(canister_self(), "nested_update_call") .await - .unwrap(); + .expect("nested_update_call failed") + .candid() + .expect("Candid decoding failed"); do_some_work(); let after_1st = counters(); - let inside_2nd: (u64, u64) = ic_cdk::call(ic_cdk::id(), "nested_update_call", ()) + let inside_2nd: (u64, u64) = Call::unbounded_wait(canister_self(), "nested_update_call") .await - .unwrap(); + .expect("nested_update_call failed") + .candid() + .expect("Candid decoding failed"); do_some_work(); let after_2nd = counters(); @@ -98,22 +98,28 @@ async fn for_update() -> (u64, u64) { after_2nd } -/// Example usage: `dfx deploy && dfx canister call performance_counters for_composite_query` -#[ic_cdk_macros::query(composite = true)] +/// Example usage: `icp canister call --query backend for_composite_query` +#[ic_cdk::query(composite = true)] async fn for_composite_query() -> (u64, u64) { do_some_work(); let before = counters(); - let inside_1st: (u64, u64) = ic_cdk::call(ic_cdk::id(), "nested_composite_query_call", ()) - .await - .unwrap(); + let inside_1st: (u64, u64) = + Call::unbounded_wait(canister_self(), "nested_composite_query_call") + .await + .expect("nested_composite_query_call failed") + .candid() + .expect("Candid decoding failed"); do_some_work(); let after_1st = counters(); - let inside_2nd: (u64, u64) = ic_cdk::call(ic_cdk::id(), "nested_composite_query_call", ()) - .await - .unwrap(); + let inside_2nd: (u64, u64) = + Call::unbounded_wait(canister_self(), "nested_composite_query_call") + .await + .expect("nested_composite_query_call failed") + .candid() + .expect("Candid decoding failed"); do_some_work(); let after_2nd = counters(); @@ -131,14 +137,18 @@ async fn for_composite_query() -> (u64, u64) { after_2nd } -/// Example usage: `dfx deploy && dfx canister call performance_counters example` -#[ic_cdk_macros::query(composite = true)] +/// Example usage: `icp canister call --query backend example` +#[ic_cdk::query(composite = true)] async fn example() -> (u64, u64) { do_some_work(); - call::<(), ()>(id(), "nested_call", ()).await.unwrap(); + Call::unbounded_wait(canister_self(), "nested_call") + .await + .expect("nested_call failed"); do_some_work(); - call::<(), ()>(id(), "nested_call", ()).await.unwrap(); + Call::unbounded_wait(canister_self(), "nested_call") + .await + .expect("nested_call failed"); do_some_work(); (performance_counter(0), performance_counter(1)) diff --git a/rust/performance_counters/dfx.json b/rust/performance_counters/dfx.json deleted file mode 100644 index 46f790c21..000000000 --- a/rust/performance_counters/dfx.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "canisters": { - "performance_counters": { - "candid": "performance_counters.did", - "package": "performance_counters", - "type": "rust" - } - }, - "version": 1 -} diff --git a/rust/performance_counters/icp.yaml b/rust/performance_counters/icp.yaml new file mode 100644 index 000000000..316aa4e9f --- /dev/null +++ b/rust/performance_counters/icp.yaml @@ -0,0 +1,9 @@ +networks: + - name: local + mode: managed +canisters: + - name: backend + recipe: + type: "@dfinity/rust@v3.3.0" + configuration: + package: backend diff --git a/rust/performance_counters/performance_counters.did b/rust/performance_counters/performance_counters.did deleted file mode 100644 index 716c7c7ce..000000000 --- a/rust/performance_counters/performance_counters.did +++ /dev/null @@ -1,5 +0,0 @@ -service : { - "for_update" : () -> (nat64, nat64); - "for_composite_query" : () -> (nat64, nat64) query; - "example" : () -> (nat64, nat64) query; -}; diff --git a/rust/performance_counters/rust-toolchain.toml b/rust/performance_counters/rust-toolchain.toml index f8bb13962..990104f05 100644 --- a/rust/performance_counters/rust-toolchain.toml +++ b/rust/performance_counters/rust-toolchain.toml @@ -1,4 +1,2 @@ [toolchain] -channel = "1.74" targets = ["wasm32-unknown-unknown"] -components = ["rustfmt", "clippy"]