Skip to content

Commit fd3ad13

Browse files
authored
Merge pull request #4175 from jayz22/metrics
Soroban metrics improvement Reviewed-by: graydon
2 parents cb2a373 + fed81d0 commit fd3ad13

8 files changed

+274
-138
lines changed

docs/metrics.md

+51-41
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ loadgen.soroban.setup_invoke | meter | loadgenerator: soroban s
7878
loadgen.soroban.setup_upgrade | meter | loadgenerator: soroban setup upgrades TXs submitted
7979
loadgen.soroban.upload | meter | loadgenerator: soroban upload TXs submitted
8080
loadgen.step.count | meter | loadgenerator: generated some transactions
81-
loadgen.step.submit | timer | loadgenerator: time spent submiting transactions per step
81+
loadgen.step.submit | timer | loadgenerator: time spent submitting transactions per step
8282
loadgen.txn.attempted | meter | loadgenerator: transaction submitted
8383
loadgen.txn.bytes | meter | loadgenerator: size of transactions submitted
8484
loadgen.txn.rejected | meter | loadgenerator: transaction rejected
@@ -162,43 +162,53 @@ state-archival.eviction.bytes-scanned | counter | number of bytes that evi
162162
state-archival.eviction.entries-evicted | counter | number of entries that have been evicted
163163
state-archival.eviction.incomplete-scan | counter | number of buckets that were too large to be fully scanned for eviction
164164
state-archival.eviction.period | counter | number of ledgers to complete an eviction scan
165-
soroban.host-fn-op.read-entry | meter | number of entries read
166-
soroban.host-fn-op.write-entry | meter | number of entries written
167-
soroban.host-fn-op.read-key-byte | meter | number of key bytes in read entries
168-
soroban.host-fn-op.write-key-byte | meter | number of key bytes in written entries
169-
soroban.host-fn-op.read-ledger-byte | meter | number of data + code bytes in read entries
170-
soroban.host-fn-op.read-data-byte | meter | number of data bytes in read entries
171-
soroban.host-fn-op.read-code-byte | meter | number of code bytes in read entries
172-
soroban.host-fn-op.write-ledger-byte | meter | number of data + code bytes in written entries
173-
soroban.host-fn-op.write-data-byte | meter | number of data bytes in written entries
174-
soroban.host-fn-op.write-code-byte | meter | number of code bytes in written entries
175-
soroban.host-fn-op.emit-event | meter | number of events emitted
176-
soroban.host-fn-op.emit-event-byte | meter | number of event bytes emitted
177-
soroban.host-fn-op.cpu-insn | meter | metered cpu instructions
178-
soroban.host-fn-op.mem-byte | meter | metered memory bytes
179-
soroban.host-fn-op.invoke-time-nsecs | meter | time [nsecs] spent in `invoke_host_function`
180-
soroban.host-fn-op.cpu-insn-excl-vm | meter | metered cpu instructions excluding VM instantation
181-
soroban.host-fn-op.invoke-time-nsecs-excl-vm | meter | time [nsecs] spent in `invoke_host_function` excluding VM instantation
182-
soroban.host-fn-op.max-rw-key-byte | meter | bytes of the largest key in entries read/written
183-
soroban.host-fn-op.max-rw-data-byte | meter | bytes of the largest data entry read/written
184-
soroban.host-fn-op.max-rw-code-byte | meter | bytes of the largest code entry read/written
185-
soroban.host-fn-op.max-emit-event-byte | meter | bytes of the largest event emitted
186-
soroban.host-fn-op.success | meter | if `InvokeHostFunctionOp` results in a success
187-
soroban.host-fn-op.failure | meter | if `InvokeHostFunctionOp` results in a failure
188-
soroban.host-fn-op.exec | timer | time spent in `InvokeHostFunctionOp`
189-
soroban.config.contract-max-size-bytes | meter | soroban config setting `contract_max_size_bytes`
190-
soroban.config.ledger-max-instructions | meter | soroban config setting `ledger_max_instructions`
191-
soroban.config.tx-max-instructions | meter | soroban config setting `tx_max_instructions`
192-
soroban.config.tx-memory-limit | meter | soroban config setting `tx_memory_limit`
193-
soroban.config.ledger-max-read-ledger-entries | meter | soroban config setting `ledger_max_read_ledger_entries`
194-
soroban.config.ledger-max-read-bytes | meter | soroban config setting `ledger_max_read_bytes`
195-
soroban.config.ledger-max-write-ledger-entries | meter | soroban config setting `ledger_max_write_ledger_entries`
196-
soroban.config.ledger-max-write-bytes | meter | soroban config setting `ledger_max_write_bytes`
197-
soroban.config.tx-max-read-ledger-entries | meter | soroban config setting `tx_max_read_ledger_entries`
198-
soroban.config.tx-max-read-bytes | meter | soroban config setting `tx_max_read_bytes`
199-
soroban.config.tx-max-write-ledger-entries | meter | soroban config setting `tx_max_write_ledger_entries`
200-
soroban.config.tx-max-write-bytes | meter | soroban config setting `tx_max_write_bytes`
201-
soroban.config.bucket-list-target-size-bytes | meter | soroban config setting `bucket_list_target_size_bytes`
202-
soroban.config.tx-max-contract-events-size-bytes | meter | soroban config setting `tx_max_contract_events_size_bytes`
203-
soroban.config.contract-data-key-size-bytes | meter | soroban config setting `contract_data_key_size_bytes`
204-
soroban.config.contract-data-entry-size-bytes | meter | soroban config setting `contract_data_entry_size_bytes`
165+
soroban.host-fn-op.read-entry | meter | number of entries accessed (read or modified) during the `InvokeHostFunctionOp`
166+
soroban.host-fn-op.write-entry | meter | number of entries modified during the `InvokeHostFunctionOp`
167+
soroban.host-fn-op.read-key-byte | meter | number of `LedgerKey` bytes in entries accessed (read or modified) during the `InvokeHostFunctionOp`
168+
soroban.host-fn-op.write-key-byte | meter | number of `LedgerKey` bytes in entries modified during the `InvokeHostFunctionOp`
169+
soroban.host-fn-op.read-ledger-byte | meter | number of `LedgerEntry` bytes accessed (read or modified) during the `InvokeHostFunctionOp`
170+
soroban.host-fn-op.read-data-byte | meter | number of `ContractDataEntry` bytes accessed (read or modified) during the `InvokeHostFunctionOp`
171+
soroban.host-fn-op.read-code-byte | meter | number of `ContractCodeEntry` bytes accessed (read or modified) during the `InvokeHostFunctionOp`
172+
soroban.host-fn-op.write-ledger-byte | meter | number of `LedgerEntry` bytes modified during the `InvokeHostFunctionOp`
173+
soroban.host-fn-op.write-data-byte | meter | number of `ContractDataEntry` bytes modified during the `InvokeHostFunctionOp`
174+
soroban.host-fn-op.write-code-byte | meter | number of `ContractCodeEntry` bytes modified during the `InvokeHostFunctionOp`
175+
soroban.host-fn-op.emit-event | meter | number of events emitted during the `InvokeHostFunctionOp`
176+
soroban.host-fn-op.emit-event-byte | meter | number of event bytes emitted during the `InvokeHostFunctionOp`
177+
soroban.host-fn-op.cpu-insn | meter | number of metered cpu instructions during the `InvokeHostFunctionOp`
178+
soroban.host-fn-op.mem-byte | meter | number of metered memory bytes during the `InvokeHostFunctionOp`
179+
soroban.host-fn-op.invoke-time-nsecs | timer | time spent on the soroban host invocation. Note: this is **not** the total time of the operation, which is tracked under "soroban.host-fn-op.exec".
180+
soroban.host-fn-op.cpu-insn-excl-vm | meter | number of metered cpu instructions excluding VM instantiation during the `InvokeHostFunctionOp`
181+
soroban.host-fn-op.invoke-time-nsecs-excl-vm | timer | time spent in soroban host invocation excluding VM instantiation
182+
soroban.host-fn-op.invoke-time-fsecs-cpu-insn-ratio | histogram | ratio between soroban host invocation time (femto-seconds) and metered cpu instructions
183+
soroban.host-fn-op.invoke-time-fsecs-cpu-insn-ratio-excl-vm | histogram | ratio between soroban host invocation time (femto-seconds) and metered cpu instructions, excluding VM instantiation
184+
soroban.host-fn-op.max-rw-key-byte | meter | size of the largest `LedgerKey` (in bytes) among all entires accessed (read or modified) during the `InvokeHostFunctionOp`
185+
soroban.host-fn-op.max-rw-data-byte | meter | size of the largest `ContractDataEntry` (in bytes) among all entires accessed (read or modified) during the `InvokeHostFunctionOp`
186+
soroban.host-fn-op.max-rw-code-byte | meter | size of the largest `ContractCodeEntry` (in bytes) among all entires accessed (read or modified) during the `InvokeHostFunctionOp`
187+
soroban.host-fn-op.max-emit-event-byte | meter | size of the largest event emitted during the `InvokeHostFunctionOp`
188+
soroban.host-fn-op.success | meter | number of successful `InvokeHostFunctionOp` operations
189+
soroban.host-fn-op.failure | meter | number of failed `InvokeHostFunctionOp` operations
190+
soroban.host-fn-op.exec | timer | total time spent during the `InvokeHostFunctionOp`
191+
soroban.restore-fprint-op.read-ledger-byte | meter | number of `LedgerEntry` bytes accessed (read or modified) during the `RestoreFootprintOp`
192+
soroban.restore-fprint-op.write-ledger-byte | meter | number of `LedgerEntry` bytes modified during the `RestoreFootprintOp`
193+
soroban.ext-fprint-ttl-op.read-ledger-byte | meter | number of `LedgerEntry` bytes accessed (read or modified) during the `ExtendFootprintTTLOp`
194+
soroban.ledger.cpu-insn | histogram | metered cpu instructions per ledger
195+
soroban.ledger.read-entry | histogram | number of entries accessed (read or modified) per ledger
196+
soroban.ledger.read-ledger-byte | histogram | number of `LedgerEntry` bytes accessed (read or modified) per ledger
197+
soroban.ledger.write-entry | histogram | number of entries modified per ledger
198+
soroban.ledger.write-ledger-byte | histogram | number of `LedgerEntry` bytes modified per ledger
199+
soroban.config.contract-max-rw-key-byte | counter | soroban config setting `contract_data_key_size_bytes`
200+
soroban.config.contract-max-rw-data-byte | counter | soroban config setting `contract_data_entry_size_bytes`
201+
soroban.config.contract-max-rw-code-byte | counter | soroban config setting `contract_max_size_bytes`
202+
soroban.config.tx-max-cpu-insn | counter | soroban config setting `tx_max_instructions`
203+
soroban.config.tx-max-mem-byte | counter | soroban config setting `tx_memory_limit`
204+
soroban.config.tx-max-read-entry | counter | soroban config setting `tx_max_read_ledger_entries`
205+
soroban.config.tx-max-read-ledger-byte | counter | soroban config setting `tx_max_read_bytes`
206+
soroban.config.tx-max-write-entry | counter | soroban config setting `tx_max_write_ledger_entries`
207+
soroban.config.tx-max-write-ledger-byte | counter | soroban config setting `tx_max_write_bytes`
208+
soroban.config.tx-max-emit-event-byte | counter | soroban config setting `tx_max_contract_events_size_bytes`
209+
soroban.config.ledger-max-cpu-insn | counter | soroban config setting `ledger_max_instructions`
210+
soroban.config.ledger-max-read-entry | counter | soroban config setting `ledger_max_read_ledger_entries`
211+
soroban.config.ledger-max-read-ledger-byte | counter | soroban config setting `ledger_max_read_bytes`
212+
soroban.config.ledger-max-write-entry | counter | soroban config setting `ledger_max_write_ledger_entries`
213+
soroban.config.ledger-max-write-ledger-byte | counter | soroban config setting `ledger_max_write_bytes`
214+
soroban.config.bucket-list-target-size-byte | counter | soroban config setting `bucket_list_target_size_bytes`

src/ledger/LedgerManager.h

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace stellar
1414

1515
class LedgerCloseData;
1616
class Database;
17+
class SorobanLedgerMetrics;
1718

1819
/**
1920
* LedgerManager maintains, in memory, a logical pair of ledgers:
@@ -187,6 +188,8 @@ class LedgerManager
187188

188189
virtual void manuallyAdvanceLedgerHeader(LedgerHeader const& header) = 0;
189190

191+
virtual SorobanLedgerMetrics& getSorobanMetrics() = 0;
192+
190193
virtual ~LedgerManager()
191194
{
192195
}

src/ledger/LedgerManagerImpl.cpp

+98-48
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,58 @@ const uint32_t LedgerManager::GENESIS_LEDGER_BASE_RESERVE = 100000000;
9494
const uint32_t LedgerManager::GENESIS_LEDGER_MAX_TX_SIZE = 100;
9595
const int64_t LedgerManager::GENESIS_LEDGER_TOTAL_COINS = 1000000000000000000;
9696

97+
void
98+
SorobanLedgerMetrics::accumulateLedgerCpuInsn(uint64_t cpuInsn)
99+
{
100+
mLedgerCpuInsn += cpuInsn;
101+
}
102+
void
103+
SorobanLedgerMetrics::accumulateLedgerReadEntry(uint64_t readEntry)
104+
{
105+
mLedgerReadEntry += readEntry;
106+
}
107+
void
108+
SorobanLedgerMetrics::accumulateLedgerReadByte(uint64_t readByte)
109+
{
110+
mLedgerReadByte += readByte;
111+
}
112+
void
113+
SorobanLedgerMetrics::accumulateLedgerWriteEntry(uint64_t writeEntry)
114+
{
115+
mLedgerWriteEntry += writeEntry;
116+
}
117+
void
118+
SorobanLedgerMetrics::accumulateLedgerWriteByte(uint64_t writeByte)
119+
{
120+
mLedgerWriteByte += writeByte;
121+
}
122+
123+
void
124+
SorobanLedgerMetrics::publishAndResetMetrics()
125+
{
126+
mMetrics.NewHistogram({"soroban", "ledger", "cpu-insn"})
127+
.Update(mLedgerCpuInsn);
128+
mMetrics.NewHistogram({"soroban", "ledger", "read-entry"})
129+
.Update(mLedgerReadEntry);
130+
mMetrics.NewHistogram({"soroban", "ledger", "read-ledger-byte"})
131+
.Update(mLedgerReadByte);
132+
mMetrics.NewHistogram({"soroban", "ledger", "write-entry"})
133+
.Update(mLedgerWriteEntry);
134+
mMetrics.NewHistogram({"soroban", "ledger", "write-ledger-byte"})
135+
.Update(mLedgerWriteByte);
136+
mLedgerCpuInsn = 0;
137+
mLedgerReadEntry = 0;
138+
mLedgerReadByte = 0;
139+
mLedgerWriteEntry = 0;
140+
mLedgerWriteByte = 0;
141+
}
142+
143+
medida::MetricsRegistry&
144+
SorobanLedgerMetrics::registry() const
145+
{
146+
return mMetrics;
147+
}
148+
97149
std::unique_ptr<LedgerManager>
98150
LedgerManager::create(Application& app)
99151
{
@@ -128,6 +180,7 @@ LedgerManager::ledgerAbbrev(LedgerHeaderHistoryEntry const& he)
128180

129181
LedgerManagerImpl::LedgerManagerImpl(Application& app)
130182
: mApp(app)
183+
, mSorobanLedgerMetrics(app.getMetrics())
131184
, mTransactionApply(
132185
app.getMetrics().NewTimer({"ledger", "transaction", "apply"}))
133186
, mTransactionCount(
@@ -554,12 +607,19 @@ LedgerManagerImpl::getMutableSorobanNetworkConfig()
554607
}
555608
#endif
556609

610+
SorobanLedgerMetrics&
611+
LedgerManagerImpl::getSorobanMetrics()
612+
{
613+
return mSorobanLedgerMetrics;
614+
}
615+
557616
void
558-
LedgerManagerImpl::publishSorobanNetworkConfigMetrics()
617+
LedgerManagerImpl::publishSorobanMetrics()
559618
{
560619
releaseAssert(mSorobanNetworkConfig);
561-
medida::MetricsRegistry& metrics = mApp.getMetrics();
620+
medida::MetricsRegistry& registry = mSorobanLedgerMetrics.registry();
562621

622+
// first publish the network config limits
563623
auto contractMaxSizeBytes = mSorobanNetworkConfig->maxContractSizeBytes();
564624
auto ledgerMaxInstructions = mSorobanNetworkConfig->ledgerMaxInstructions();
565625
auto txMaxInstructions = mSorobanNetworkConfig->txMaxInstructions();
@@ -585,51 +645,41 @@ LedgerManagerImpl::publishSorobanNetworkConfigMetrics()
585645
auto contractDataEntrySizeBytes =
586646
mSorobanNetworkConfig->maxContractDataEntrySizeBytes();
587647

588-
metrics.NewMeter({"soroban", "config", "contract-max-size-bytes"}, "byte")
589-
.Mark(contractMaxSizeBytes);
590-
metrics.NewMeter({"soroban", "config", "ledger-max-instructions"}, "insn")
591-
.Mark(ledgerMaxInstructions);
592-
metrics.NewMeter({"soroban", "config", "tx-max-instructions"}, "insn")
593-
.Mark(txMaxInstructions);
594-
metrics.NewMeter({"soroban", "config", "tx-memory-limit"}, "byte")
595-
.Mark(txMemoryLimit);
596-
metrics
597-
.NewMeter({"soroban", "config", "ledger-max-read-ledger-entries"},
598-
"entry")
599-
.Mark(ledgerMaxReadLedgerEntries);
600-
metrics.NewMeter({"soroban", "config", "ledger-max-read-bytes"}, "byte")
601-
.Mark(ledgerMaxReadBytes);
602-
metrics
603-
.NewMeter({"soroban", "config", "ledger-max-write-ledger-entries"},
604-
"entry")
605-
.Mark(ledgerMaxWriteLedgerEntries);
606-
metrics.NewMeter({"soroban", "config", "ledger-max-write-bytes"}, "byte")
607-
.Mark(ledgerMaxWriteBytes);
608-
metrics
609-
.NewMeter({"soroban", "config", "tx-max-read-ledger-entries"}, "entry")
610-
.Mark(txMaxReadLedgerEntries);
611-
metrics.NewMeter({"soroban", "config", "tx-max-read-bytes"}, "byte")
612-
.Mark(txMaxReadBytes);
613-
metrics
614-
.NewMeter({"soroban", "config", "tx-max-write-ledger-entries"}, "entry")
615-
.Mark(txMaxWriteLedgerEntries);
616-
metrics.NewMeter({"soroban", "config", "tx-max-write-bytes"}, "byte")
617-
.Mark(txMaxWriteBytes);
618-
metrics
619-
.NewMeter({"soroban", "config", "bucket-list-target-size-bytes"},
620-
"byte")
621-
.Mark(bucketListTargetSizeBytes);
622-
metrics
623-
.NewMeter({"soroban", "config", "tx-max-contract-events-size-bytes"},
624-
"byte")
625-
.Mark(txMaxContractEventsSizeBytes);
626-
metrics
627-
.NewMeter({"soroban", "config", "contract-data-key-size-bytes"}, "byte")
628-
.Mark(contractDataKeySizeBytes);
629-
metrics
630-
.NewMeter({"soroban", "config", "contract-data-entry-size-bytes"},
631-
"byte")
632-
.Mark(contractDataEntrySizeBytes);
648+
registry.NewCounter({"soroban", "config", "contract-max-rw-key-byte"})
649+
.set_count(contractDataKeySizeBytes);
650+
registry.NewCounter({"soroban", "config", "contract-max-rw-data-byte"})
651+
.set_count(contractDataEntrySizeBytes);
652+
registry.NewCounter({"soroban", "config", "contract-max-rw-code-byte"})
653+
.set_count(contractMaxSizeBytes);
654+
registry.NewCounter({"soroban", "config", "tx-max-cpu-insn"})
655+
.set_count(txMaxInstructions);
656+
registry.NewCounter({"soroban", "config", "tx-max-mem-byte"})
657+
.set_count(txMemoryLimit);
658+
registry.NewCounter({"soroban", "config", "tx-max-read-entry"})
659+
.set_count(txMaxReadLedgerEntries);
660+
registry.NewCounter({"soroban", "config", "tx-max-read-ledger-byte"})
661+
.set_count(txMaxReadBytes);
662+
registry.NewCounter({"soroban", "config", "tx-max-write-entry"})
663+
.set_count(txMaxWriteLedgerEntries);
664+
registry.NewCounter({"soroban", "config", "tx-max-write-ledger-byte"})
665+
.set_count(txMaxWriteBytes);
666+
registry.NewCounter({"soroban", "config", "tx-max-emit-event-byte"})
667+
.set_count(txMaxContractEventsSizeBytes);
668+
registry.NewCounter({"soroban", "config", "ledger-max-cpu-insn"})
669+
.set_count(ledgerMaxInstructions);
670+
registry.NewCounter({"soroban", "config", "ledger-max-read-entry"})
671+
.set_count(ledgerMaxReadLedgerEntries);
672+
registry.NewCounter({"soroban", "config", "ledger-max-read-ledger-byte"})
673+
.set_count(ledgerMaxReadBytes);
674+
registry.NewCounter({"soroban", "config", "ledger-max-write-entry"})
675+
.set_count(ledgerMaxWriteLedgerEntries);
676+
registry.NewCounter({"soroban", "config", "ledger-max-write-ledger-byte"})
677+
.set_count(ledgerMaxWriteBytes);
678+
registry.NewCounter({"soroban", "config", "bucket-list-target-size-byte"})
679+
.set_count(bucketListTargetSizeBytes);
680+
681+
// then publish the actual ledger usage
682+
mSorobanLedgerMetrics.publishAndResetMetrics();
633683
}
634684

635685
// called by txherder
@@ -1306,7 +1356,7 @@ LedgerManagerImpl::updateNetworkConfig(AbstractLedgerTxn& rootLtx)
13061356
mSorobanNetworkConfig->loadFromLedger(
13071357
rootLtx, mApp.getConfig().CURRENT_LEDGER_PROTOCOL_VERSION,
13081358
ledgerVersion);
1309-
publishSorobanNetworkConfigMetrics();
1359+
publishSorobanMetrics();
13101360
}
13111361
else
13121362
{

0 commit comments

Comments
 (0)