From 5b49c903e02f6d667bf36510953f5a6bb61297d1 Mon Sep 17 00:00:00 2001 From: dydxwill <119354122+dydxwill@users.noreply.github.com> Date: Fri, 1 Dec 2023 12:15:41 -0500 Subject: [PATCH] [IND-520] Add more pnl stats (#826) --- .../src/helpers/pnl-ticks-helper.ts | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/indexer/services/roundtable/src/helpers/pnl-ticks-helper.ts b/indexer/services/roundtable/src/helpers/pnl-ticks-helper.ts index 6642e4732e..221bd22550 100644 --- a/indexer/services/roundtable/src/helpers/pnl-ticks-helper.ts +++ b/indexer/services/roundtable/src/helpers/pnl-ticks-helper.ts @@ -1,4 +1,4 @@ -import { logger } from '@dydxprotocol-indexer/base'; +import { logger, stats } from '@dydxprotocol-indexer/base'; import { AssetPositionTable, FundingIndexMap, @@ -36,6 +36,7 @@ export async function getPnlTicksCreateObjects( blockTime: IsoString, txId: number, ): Promise { + const startGetPnlTicksCreateObjects: number = Date.now(); const pnlTicksToBeCreatedAt: DateTime = DateTime.utc(); const [ mostRecentPnlTicks, @@ -47,6 +48,10 @@ export async function getPnlTicksCreateObjects( getMostRecentPnlTicksForEachAccount(), SubaccountTable.getSubaccountsWithTransfers(blockHeight, { readReplica: true, txId }), ]); + stats.timing( + `${config.SERVICE_NAME}_get_ticks_relevant_accounts`, + new Date().getTime() - startGetPnlTicksCreateObjects, + ); const accountToLastUpdatedBlockTime: _.Dictionary = _.mapValues( mostRecentPnlTicks, (pnlTick: PnlTicksCreateObject) => pnlTick.blockTime, @@ -66,17 +71,27 @@ export async function getPnlTicksCreateObjects( ), ...newSubaccountIds, ]; + stats.gauge( + `${config.SERVICE_NAME}_get_ticks_accounts_to_update`, + accountsToUpdate.length, + ); const idToSubaccount: _.Dictionary = _.keyBy( subaccountsWithTransfers, 'id', ); + const getFundingIndexStart: number = Date.now(); const blockHeightToFundingIndexMap: _.Dictionary = await getBlockHeightToFundingIndexMap( subaccountsWithTransfers, accountsToUpdate, txId, ); + stats.timing( + `${config.SERVICE_NAME}_get_ticks_funding_indices`, + new Date().getTime() - getFundingIndexStart, + ); + const getAccountInfoStart: number = Date.now(); const [ subaccountTotalTransfersMap, openPerpetualPositions, @@ -122,7 +137,12 @@ export async function getPnlTicksCreateObjects( OraclePriceTable.findLatestPrices(blockHeight), FundingIndexUpdatesTable.findFundingIndexMap(blockHeight), ]); + stats.timing( + `${config.SERVICE_NAME}_get_ticks_account_info`, + new Date().getTime() - getAccountInfoStart, + ); + const computePnlStart: number = Date.now(); const newTicksToCreate: PnlTicksCreateObject[] = accountsToUpdate.map( (account: string) => getNewPnlTick( account, @@ -139,6 +159,10 @@ export async function getPnlTicksCreateObjects( currentFundingIndexMap, ), ); + stats.timing( + `${config.SERVICE_NAME}_get_ticks_compute_pnl`, + new Date().getTime() - computePnlStart, + ); return newTicksToCreate; }