gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] branch master updated: cli: allow DB stats tracking


From: gnunet
Subject: [taler-wallet-core] branch master updated: cli: allow DB stats tracking via environment variable
Date: Fri, 15 Sep 2023 17:14:40 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository wallet-core.

The following commit(s) were added to refs/heads/master by this push:
     new 40d2aa0c1 cli: allow DB stats tracking via environment variable
40d2aa0c1 is described below

commit 40d2aa0c11e61ea45005c4c212c6ab686162b4b0
Author: Florian Dold <florian@dold.me>
AuthorDate: Fri Sep 15 17:14:37 2023 +0200

    cli: allow DB stats tracking via environment variable
---
 packages/taler-wallet-cli/src/index.ts           | 38 +++++++++++++++---------
 packages/taler-wallet-core/src/host-impl.node.ts |  5 +++-
 2 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/packages/taler-wallet-cli/src/index.ts 
b/packages/taler-wallet-cli/src/index.ts
index 3fc86d0b5..b37d4974b 100644
--- a/packages/taler-wallet-cli/src/index.ts
+++ b/packages/taler-wallet-cli/src/index.ts
@@ -53,6 +53,7 @@ import {
 import { createPlatformHttpLib } from "@gnu-taler/taler-util/http";
 import { JsonMessage, runRpcServer } from "@gnu-taler/taler-util/twrpc";
 import {
+  AccessStats,
   createNativeWalletHost,
   createNativeWalletHost2,
   Wallet,
@@ -237,16 +238,21 @@ export interface WalletContext {
   ): Promise<T>;
 }
 
+interface CreateWalletResult {
+  wallet: Wallet;
+  getStats: () => AccessStats;
+}
+
 async function createLocalWallet(
   walletCliArgs: WalletCliArgsType,
   notificationHandler?: (n: WalletNotification) => void,
-): Promise<Wallet> {
+): Promise<CreateWalletResult> {
   const dbPath = walletCliArgs.wallet.walletDbFile ?? defaultWalletDbPath;
   const myHttpLib = createPlatformHttpLib({
     enableThrottling: walletCliArgs.wallet.noThrottle ? false : true,
     requireTls: walletCliArgs.wallet.noHttp,
   });
-  const wallet = await createNativeWalletHost({
+  const wh = await createNativeWalletHost2({
     persistentStoragePath: dbPath !== ":memory:" ? dbPath : undefined,
     httpLib: myHttpLib,
     notifyHandler: (n) => {
@@ -269,10 +275,10 @@ async function createLocalWallet(
 
   applyVerbose(walletCliArgs.wallet.verbose);
   try {
-    await wallet.handleCoreApiRequest("initWallet", "native-init", {
+    await wh.wallet.handleCoreApiRequest("initWallet", "native-init", {
       skipDefaults: walletCliArgs.wallet.skipDefaults,
     });
-    return wallet;
+    return { wallet: wh.wallet, getStats: wh.getDbStats };
   } catch (e) {
     const ed = getErrorDetailFromException(e);
     console.error("Operation failed: " + summarizeTalerErrorDetail(ed));
@@ -307,16 +313,20 @@ async function withWallet<T>(
     w.close();
     return res;
   } else {
-    const w = await createLocalWallet(walletCliArgs, waiter.notify);
+    const wh = await createLocalWallet(walletCliArgs, waiter.notify);
     const ctx: WalletContext = {
-      client: w.client,
+      client: wh.wallet.client,
       waitForNotificationCond: waiter.waitForNotificationCond,
       makeCoreApiRequest(operation, payload) {
-        return w.handleCoreApiRequest(operation, "my-req", payload);
+        return wh.wallet.handleCoreApiRequest(operation, "my-req", payload);
       },
     };
     const result = await f(ctx);
-    w.stop();
+    wh.wallet.stop();
+    if (process.env.TALER_WALLET_DBSTATS) {
+      console.log("database stats:");
+      console.log(j2s(wh.getStats()));
+    }
     return result;
   }
 }
@@ -330,7 +340,8 @@ async function withLocalWallet<T>(
   walletCliArgs: WalletCliArgsType,
   f: (w: { client: WalletCoreApiClient; ws: Wallet }) => Promise<T>,
 ): Promise<T> {
-  const w = await createLocalWallet(walletCliArgs);
+  const wh = await createLocalWallet(walletCliArgs);
+  const w = wh.wallet;
   const res = await f({ client: w.client, ws: w });
   w.stop();
   return res;
@@ -1030,8 +1041,7 @@ peerCli
       const resp = await wallet.client.call(
         WalletApiOperation.ConfirmPeerPullDebit,
         {
-          peerPullDebitId:
-            args.confirmIncomingPayPull.peerPullDebitId,
+          peerPullDebitId: args.confirmIncomingPayPull.peerPullDebitId,
         },
       );
       console.log(JSON.stringify(resp, undefined, 2));
@@ -1046,8 +1056,7 @@ peerCli
       const resp = await wallet.client.call(
         WalletApiOperation.ConfirmPeerPushCredit,
         {
-          peerPushCreditId:
-            args.confirmIncomingPayPush.peerPushCreditId,
+          peerPushCreditId: args.confirmIncomingPayPush.peerPushCreditId,
         },
       );
       console.log(JSON.stringify(resp, undefined, 2));
@@ -1174,7 +1183,8 @@ advancedCli
   })
   .action(async (args) => {
     logger.info(`serving at ${args.serve.unixPath}`);
-    const w = await createLocalWallet(args);
+    const wh = await createLocalWallet(args);
+    const w = wh.wallet;
     w.runTaskLoop()
       .then((res) => {
         logger.warn("task loop exited unexpectedly");
diff --git a/packages/taler-wallet-core/src/host-impl.node.ts 
b/packages/taler-wallet-core/src/host-impl.node.ts
index a6dae58a1..33162ec50 100644
--- a/packages/taler-wallet-core/src/host-impl.node.ts
+++ b/packages/taler-wallet-core/src/host-impl.node.ts
@@ -108,10 +108,13 @@ async function makeSqliteDb(
     filename: args.persistentStoragePath ?? ":memory:",
   });
   myBackend.enableTracing = false;
+  if (process.env.TALER_WALLET_DBSTATS) {
+    myBackend.trackStats = true;
+  }
   const myBridgeIdbFactory = new BridgeIDBFactory(myBackend);
   return {
     getStats() {
-      throw Error("not implemented");
+      return myBackend.accessStats;
     },
     idbFactory: myBridgeIdbFactory,
   };

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]