From 35a93cc40db670429917f45c5b2e26e670280c9d Mon Sep 17 00:00:00 2001 From: thatben Date: Mon, 13 Jan 2025 15:59:11 +0100 Subject: [PATCH] Adds duration to repostore logs for getBlock and putBlock --- .github/workflows/docker-dist-tests.yml | 2 +- codex/stores/repostore/store.nim | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-dist-tests.yml b/.github/workflows/docker-dist-tests.yml index 1cbc528a..22b23e52 100644 --- a/.github/workflows/docker-dist-tests.yml +++ b/.github/workflows/docker-dist-tests.yml @@ -30,7 +30,7 @@ jobs: name: Build and Push uses: ./.github/workflows/docker-reusable.yml with: - nimflags: '-d:disableMarchNative -d:codex_enable_api_debug_peers=true -d:codex_enable_proof_failures=true -d:codex_enable_log_counter=true -d:verify_circuit=true' + nimflags: '-d:disableMarchNative -d:codex_enable_api_debug_peers=true -d:codex_enable_proof_failures=true -d:codex_enable_log_counter=true -d:verify_circuit=true -d:codex_enable_repostore_timinglogs=true' nat_ip_auto: true tag_latest: ${{ github.ref_name == github.event.repository.default_branch || startsWith(github.ref, 'refs/tags/') }} tag_suffix: dist-tests diff --git a/codex/stores/repostore/store.nim b/codex/stores/repostore/store.nim index 63c59d2b..31841996 100644 --- a/codex/stores/repostore/store.nim +++ b/codex/stores/repostore/store.nim @@ -27,6 +27,12 @@ import ../../logutils import ../../merkletree import ../../utils +const + codex_enable_repostore_timinglogs* {.booldefine.} = false + +when codex_enable_repostore_timinglogs: + import std/monotimes + export blocktype, cid logScope: @@ -51,6 +57,9 @@ method getBlock*(self: RepoStore, cid: Cid): Future[?!Block] {.async.} = trace "Error getting key from provider", err = err.msg return failure(err) + when codex_enable_repostore_timinglogs: + let startTime = getMonoTime().ticks + without data =? await self.repoDs.get(key), err: if not (err of DatastoreKeyNotFound): trace "Error getting block from datastore", err = err.msg, key @@ -58,7 +67,12 @@ method getBlock*(self: RepoStore, cid: Cid): Future[?!Block] {.async.} = return failure(newException(BlockNotFoundError, err.msg)) - trace "Got block for cid", cid + when codex_enable_repostore_timinglogs: + let durationUs = (getMonoTime().ticks - startTime) div 1000 + trace "Got block for cid", cid, durationUs + else: + trace "Got block for cid", cid + return Block.new(cid, data, verify = true) method getBlockAndProof*(self: RepoStore, treeCid: Cid, index: Natural): Future[?!(Block, CodexProof)] {.async.} = @@ -176,6 +190,9 @@ method putBlock*( let expiry = self.clock.now() + (ttl |? self.blockTtl).seconds + when codex_enable_repostore_timinglogs: + let startTime = getMonoTime().ticks + without res =? await self.storeBlock(blk, expiry), err: return failure(err) @@ -195,6 +212,10 @@ method putBlock*( else: trace "Block already exists" + when codex_enable_repostore_timinglogs: + let durationUs = (getMonoTime().ticks - startTime) div 1000 + trace "putBlock", durationUs + return success() method delBlock*(self: RepoStore, cid: Cid): Future[?!void] {.async.} =