summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-09-15 17:14:37 +0200
committerFlorian Dold <florian@dold.me>2023-09-15 17:14:37 +0200
commit40d2aa0c11e61ea45005c4c212c6ab686162b4b0 (patch)
tree9282f8e1ea25c7c54ec53157d718fcbfcb8f5015
parent0ff189d229b348422239670223b4944b42596f63 (diff)
downloadwallet-core-40d2aa0c11e61ea45005c4c212c6ab686162b4b0.tar.gz
wallet-core-40d2aa0c11e61ea45005c4c212c6ab686162b4b0.tar.bz2
wallet-core-40d2aa0c11e61ea45005c4c212c6ab686162b4b0.zip
cli: allow DB stats tracking via environment variable
-rw-r--r--packages/taler-wallet-cli/src/index.ts38
-rw-r--r--packages/taler-wallet-core/src/host-impl.node.ts5
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,
};