From 3a9dc057771798a6f46b9984e8a874eb021d0c92 Mon Sep 17 00:00:00 2001 From: Jay Geng Date: Wed, 3 Apr 2024 17:03:48 -0400 Subject: [PATCH] make budget pretty again --- soroban-env-host/src/budget.rs | 21 +++-- soroban-env-host/src/test/budget_metering.rs | 94 +++++++++---------- soroban-env-host/src/test/hostile.rs | 96 ++++++++++---------- 3 files changed, 109 insertions(+), 102 deletions(-) diff --git a/soroban-env-host/src/budget.rs b/soroban-env-host/src/budget.rs index 3c7a92239..95160a87d 100644 --- a/soroban-env-host/src/budget.rs +++ b/soroban-env-host/src/budget.rs @@ -806,7 +806,7 @@ impl Debug for BudgetImpl { let i = ct as usize; writeln!( f, - "{:<25}{:<15}{:<15}{:<15}{:<15}{:<20}{:<20}{:<20}{:<20}", + "{:<35}{:<15}{:<15}{:<15}{:<15}{:<20}{:<20}{:<20}{:<20}", format!("{:?}", ct), self.tracker.cost_tracker[i].iterations, format!("{:?}", self.tracker.cost_tracker[i].inputs), @@ -818,7 +818,7 @@ impl Debug for BudgetImpl { format!("{}", self.mem_bytes.cost_models[i].lin_term), )?; } - writeln!(f, "{:=<165}", "")?; + writeln!(f, "{:=<175}", "")?; writeln!( f, "Internal details (diagnostics info, does not affect fees) " @@ -838,14 +838,14 @@ impl Debug for BudgetImpl { "Shadow mem limit: {}; used: {}", self.mem_bytes.shadow_limit, self.mem_bytes.shadow_total_count )?; - writeln!(f, "{:=<165}", "")?; + writeln!(f, "{:=<175}", "")?; Ok(()) } } impl Display for BudgetImpl { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "{:=<55}", "")?; + writeln!(f, "{:=<65}", "")?; writeln!( f, "Cpu limit: {}; used: {}", @@ -859,24 +859,31 @@ impl Display for BudgetImpl { writeln!(f, "{:=<55}", "")?; writeln!( f, - "{:<25}{:<15}{:<15}", + "{:<35}{:<15}{:<15}", "CostType", "cpu_insns", "mem_bytes", )?; for ct in ContractCostType::variants() { let i = ct as usize; writeln!( f, - "{:<25}{:<15}{:<15}", + "{:<35}{:<15}{:<15}", format!("{:?}", ct), self.tracker.cost_tracker[i].cpu, self.tracker.cost_tracker[i].mem, )?; } - writeln!(f, "{:=<55}", "")?; + writeln!(f, "{:=<65}", "")?; Ok(()) } } +#[test] +fn print() { + let budget = Budget::default(); + println!("{budget}"); + println!("{budget:?}"); +} + #[allow(unused)] #[cfg(test)] impl BudgetImpl { diff --git a/soroban-env-host/src/test/budget_metering.rs b/soroban-env-host/src/test/budget_metering.rs index 1b6cb78a0..cc645c034 100644 --- a/soroban-env-host/src/test/budget_metering.rs +++ b/soroban-env-host/src/test/budget_metering.rs @@ -477,57 +477,57 @@ fn total_amount_charged_from_random_inputs() -> Result<(), HostError> { Mem limit: 41943040; used: 302115 ===================================================================================================================================================================== CostType iterations input cpu_insns mem_bytes const_term_cpu lin_term_cpu const_term_mem lin_term_mem - WasmInsnExec 246 None 984 0 4 0 0 0 - MemAlloc 1 Some(152) 453 168 434 16 16 128 - MemCpy 1 Some(65) 50 0 42 16 0 0 - MemCmp 1 Some(74) 53 0 44 16 0 0 - DispatchHostFunction 176 None 54560 0 310 0 0 0 - VisitObject 97 None 5917 0 61 0 0 0 - ValSer 1 Some(49) 241 389 230 29 242 384 - ValDeser 1 Some(103) 62271 309 59052 4001 0 384 - ComputeSha256Hash 1 Some(193) 14310 0 3738 7012 0 0 - ComputeEd25519PubKey 226 None 9097178 0 40253 0 0 0 - VerifyEd25519Sig 1 Some(227) 384738 0 377524 4068 0 0 - VmInstantiation 1 Some(147) 503770 135880 451626 45405 130065 5064 - VmCachedInstantiation 1 Some(147) 41870 70869 41142 634 69472 1217 - InvokeVmFunction 47 None 91556 658 1948 0 14 0 - ComputeKeccak256Hash 1 Some(1) 3812 0 3766 5969 0 0 - DecodeEcdsaCurve256Sig 1 None 710 0 710 0 0 0 - RecoverEcdsaSecp256k1Key 1 None 2315295 181 2315295 0 181 0 - Int256AddSub 1 None 4404 99 4404 0 99 0 - Int256Mul 1 None 4947 99 4947 0 99 0 - Int256Div 1 None 4911 99 4911 0 99 0 - Int256Pow 1 None 4286 99 4286 0 99 0 - Int256Shift 1 None 913 99 913 0 99 0 - ChaCha20DrawBytes 1 Some(1) 1061 0 1058 501 0 0 - ParseWasmInstructions 1 Some(1) 73275 17614 73077 25410 17564 6457 - ParseWasmFunctions 1 Some(1) 4224 370 0 540752 0 47464 - ParseWasmGlobals 1 Some(1) 1377 104 0 176363 0 13420 - ParseWasmTableEntries 1 Some(1) 234 49 0 29989 0 6285 - ParseWasmTypes 1 Some(1) 8292 505 0 1061449 0 64670 - ParseWasmDataSegments 1 Some(1) 1854 227 0 237336 0 29074 - ParseWasmElemSegments 1 Some(1) 2566 375 0 328476 0 48095 - ParseWasmImports 1 Some(1) 5483 806 0 701845 0 103229 - ParseWasmExports 1 Some(1) 3354 284 0 429383 0 36394 - ParseWasmDataSegmentBytes1 Some(1) 0 2 0 28 0 257 - InstantiateWasmInstructions1 None 43030 70704 43030 0 70704 0 - InstantiateWasmFunctions 1 Some(1) 59 114 0 7556 0 14613 - InstantiateWasmGlobals 1 Some(1) 83 53 0 10711 0 6833 - InstantiateWasmTableEntries1 Some(1) 25 8 0 3300 0 1025 - InstantiateWasmTypes 1 None 0 0 0 0 0 0 - InstantiateWasmDataSegments1 Some(1) 179 1012 0 23038 0 129632 - InstantiateWasmElemSegments1 Some(1) 331 106 0 42488 0 13665 - InstantiateWasmImports 1 Some(1) 6476 762 0 828974 0 97637 - InstantiateWasmExports 1 Some(1) 2321 71 0 297100 0 9176 - InstantiateWasmDataSegmentBytes1 Some(1) 0 0 0 14 0 126 - Sec1DecodePointUncompressed1 None 1882 0 1882 0 0 0 - VerifyEcdsaSecp256r1Sig 1 None 3000906 0 3000906 0 0 0 - ===================================================================================================================================================================== + WasmInsnExec 246 None 984 0 4 0 0 0 + MemAlloc 1 Some(152) 453 168 434 16 16 128 + MemCpy 1 Some(65) 50 0 42 16 0 0 + MemCmp 1 Some(74) 53 0 44 16 0 0 + DispatchHostFunction 176 None 54560 0 310 0 0 0 + VisitObject 97 None 5917 0 61 0 0 0 + ValSer 1 Some(49) 241 389 230 29 242 384 + ValDeser 1 Some(103) 62271 309 59052 4001 0 384 + ComputeSha256Hash 1 Some(193) 14310 0 3738 7012 0 0 + ComputeEd25519PubKey 226 None 9097178 0 40253 0 0 0 + VerifyEd25519Sig 1 Some(227) 384738 0 377524 4068 0 0 + VmInstantiation 1 Some(147) 503770 135880 451626 45405 130065 5064 + VmCachedInstantiation 1 Some(147) 41870 70869 41142 634 69472 1217 + InvokeVmFunction 47 None 91556 658 1948 0 14 0 + ComputeKeccak256Hash 1 Some(1) 3812 0 3766 5969 0 0 + DecodeEcdsaCurve256Sig 1 None 710 0 710 0 0 0 + RecoverEcdsaSecp256k1Key 1 None 2315295 181 2315295 0 181 0 + Int256AddSub 1 None 4404 99 4404 0 99 0 + Int256Mul 1 None 4947 99 4947 0 99 0 + Int256Div 1 None 4911 99 4911 0 99 0 + Int256Pow 1 None 4286 99 4286 0 99 0 + Int256Shift 1 None 913 99 913 0 99 0 + ChaCha20DrawBytes 1 Some(1) 1061 0 1058 501 0 0 + ParseWasmInstructions 1 Some(1) 73275 17614 73077 25410 17564 6457 + ParseWasmFunctions 1 Some(1) 4224 370 0 540752 0 47464 + ParseWasmGlobals 1 Some(1) 1377 104 0 176363 0 13420 + ParseWasmTableEntries 1 Some(1) 234 49 0 29989 0 6285 + ParseWasmTypes 1 Some(1) 8292 505 0 1061449 0 64670 + ParseWasmDataSegments 1 Some(1) 1854 227 0 237336 0 29074 + ParseWasmElemSegments 1 Some(1) 2566 375 0 328476 0 48095 + ParseWasmImports 1 Some(1) 5483 806 0 701845 0 103229 + ParseWasmExports 1 Some(1) 3354 284 0 429383 0 36394 + ParseWasmDataSegmentBytes 1 Some(1) 0 2 0 28 0 257 + InstantiateWasmInstructions 1 None 43030 70704 43030 0 70704 0 + InstantiateWasmFunctions 1 Some(1) 59 114 0 7556 0 14613 + InstantiateWasmGlobals 1 Some(1) 83 53 0 10711 0 6833 + InstantiateWasmTableEntries 1 Some(1) 25 8 0 3300 0 1025 + InstantiateWasmTypes 1 None 0 0 0 0 0 0 + InstantiateWasmDataSegments 1 Some(1) 179 1012 0 23038 0 129632 + InstantiateWasmElemSegments 1 Some(1) 331 106 0 42488 0 13665 + InstantiateWasmImports 1 Some(1) 6476 762 0 828974 0 97637 + InstantiateWasmExports 1 Some(1) 2321 71 0 297100 0 9176 + InstantiateWasmDataSegmentBytes 1 Some(1) 0 0 0 14 0 126 + Sec1DecodePointUncompressed 1 None 1882 0 1882 0 0 0 + VerifyEcdsaSecp256r1Sig 1 None 3000906 0 3000906 0 0 0 + =============================================================================================================================================================================== Internal details (diagnostics info, does not affect fees) Total # times meter was called: 45 Shadow cpu limit: 100000000; used: 15754241 Shadow mem limit: 41943040; used: 302115 - ===================================================================================================================================================================== + =============================================================================================================================================================================== "#]]; expected.assert_eq(&actual); diff --git a/soroban-env-host/src/test/hostile.rs b/soroban-env-host/src/test/hostile.rs index acd0a387a..7ce7c96e3 100644 --- a/soroban-env-host/src/test/hostile.rs +++ b/soroban-env-host/src/test/hostile.rs @@ -532,57 +532,57 @@ fn excessive_logging() -> Result<(), HostError> { #[cfg(feature = "next")] let expected_budget = expect![[r#" - ======================================================= + ================================================================= Cpu limit: 2000000; used: 212908 Mem limit: 500000; used: 166460 ======================================================= - CostType cpu_insns mem_bytes - WasmInsnExec 300 0 - MemAlloc 15292 67040 - MemCpy 2331 0 - MemCmp 416 0 - DispatchHostFunction 310 0 - VisitObject 244 0 - ValSer 0 0 - ValDeser 0 0 - ComputeSha256Hash 3738 0 - ComputeEd25519PubKey 0 0 - VerifyEd25519Sig 0 0 - VmInstantiation 0 0 - VmCachedInstantiation 0 0 - InvokeVmFunction 1948 14 - ComputeKeccak256Hash 0 0 - DecodeEcdsaCurve256Sig 0 0 - RecoverEcdsaSecp256k1Key 0 0 - Int256AddSub 0 0 - Int256Mul 0 0 - Int256Div 0 0 - Int256Pow 0 0 - Int256Shift 0 0 - ChaCha20DrawBytes 0 0 - ParseWasmInstructions 74665 17967 - ParseWasmFunctions 4224 370 - ParseWasmGlobals 1377 104 - ParseWasmTableEntries 29989 6285 - ParseWasmTypes 8292 505 - ParseWasmDataSegments 0 0 - ParseWasmElemSegments 0 0 - ParseWasmImports 5483 806 - ParseWasmExports 6709 568 - ParseWasmDataSegmentBytes0 0 - InstantiateWasmInstructions43030 70704 - InstantiateWasmFunctions 59 114 - InstantiateWasmGlobals 83 53 - InstantiateWasmTableEntries3300 1025 - InstantiateWasmTypes 0 0 - InstantiateWasmDataSegments0 0 - InstantiateWasmElemSegments0 0 - InstantiateWasmImports 6476 762 - InstantiateWasmExports 4642 143 - InstantiateWasmDataSegmentBytes0 0 - Sec1DecodePointUncompressed0 0 - VerifyEcdsaSecp256r1Sig 0 0 - ======================================================= + CostType cpu_insns mem_bytes + WasmInsnExec 300 0 + MemAlloc 15292 67040 + MemCpy 2331 0 + MemCmp 416 0 + DispatchHostFunction 310 0 + VisitObject 244 0 + ValSer 0 0 + ValDeser 0 0 + ComputeSha256Hash 3738 0 + ComputeEd25519PubKey 0 0 + VerifyEd25519Sig 0 0 + VmInstantiation 0 0 + VmCachedInstantiation 0 0 + InvokeVmFunction 1948 14 + ComputeKeccak256Hash 0 0 + DecodeEcdsaCurve256Sig 0 0 + RecoverEcdsaSecp256k1Key 0 0 + Int256AddSub 0 0 + Int256Mul 0 0 + Int256Div 0 0 + Int256Pow 0 0 + Int256Shift 0 0 + ChaCha20DrawBytes 0 0 + ParseWasmInstructions 74665 17967 + ParseWasmFunctions 4224 370 + ParseWasmGlobals 1377 104 + ParseWasmTableEntries 29989 6285 + ParseWasmTypes 8292 505 + ParseWasmDataSegments 0 0 + ParseWasmElemSegments 0 0 + ParseWasmImports 5483 806 + ParseWasmExports 6709 568 + ParseWasmDataSegmentBytes 0 0 + InstantiateWasmInstructions 43030 70704 + InstantiateWasmFunctions 59 114 + InstantiateWasmGlobals 83 53 + InstantiateWasmTableEntries 3300 1025 + InstantiateWasmTypes 0 0 + InstantiateWasmDataSegments 0 0 + InstantiateWasmElemSegments 0 0 + InstantiateWasmImports 6476 762 + InstantiateWasmExports 4642 143 + InstantiateWasmDataSegmentBytes 0 0 + Sec1DecodePointUncompressed 0 0 + VerifyEcdsaSecp256r1Sig 0 0 + ================================================================= "#]];