Skip to content

Commit 4472f34

Browse files
authored
Migrate profiler trace-data to cairo-annotations trace data (#2583)
<!-- Reference any GitHub issues resolved by this PR --> Towards #2468 ## Introduced changes <!-- A brief description of the changes --> - Migrate profiler trace-data to cairo-annotations trace data ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md`
1 parent 9ea9d3a commit 4472f34

File tree

11 files changed

+85
-48
lines changed

11 files changed

+85
-48
lines changed

Cargo.lock

Lines changed: 41 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ cairo-lang-starknet-classes = "2.7.0"
5050
cairo-lang-parser = "2.7.0"
5151
cairo-lang-macro = "0.1.0"
5252
cairo-vm = "1.0.0-rc3"
53+
cairo-annotations = "0.1.0"
5354
starknet-types-core = { version = "0.1.6", features = ["hash", "prime-bigint"] }
5455
anyhow = "1.0.89"
5556
assert_fs = "1.1.2"
@@ -66,7 +67,6 @@ serde = { version = "1.0.209", features = ["derive"] }
6667
serde_json = "1.0.127"
6768
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "660a732" }
6869
starknet-crypto = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "660a732" }
69-
trace-data = { git = "https://github.com/software-mansion/cairo-profiler/", rev = "e61a4a7" }
7070
tempfile = "3.13.0"
7171
thiserror = "1.0.64"
7272
ctor = "0.2.8"

crates/cheatnet/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cairo-lang-utils.workspace = true
1919
cairo-lang-starknet.workspace = true
2020
cairo-lang-starknet-classes.workspace = true
2121
cairo-vm.workspace = true
22+
cairo-annotations.workspace = true
2223
regex.workspace = true
2324
indoc.workspace = true
2425
starknet.workspace = true
@@ -33,7 +34,6 @@ tokio.workspace = true
3334
num-bigint.workspace = true
3435
conversions.workspace = true
3536
scarb-metadata.workspace = true
36-
trace-data.workspace = true
3737
fs2.workspace = true
3838
flate2.workspace = true
3939
scarb-api = { path = "../scarb-api" }

crates/cheatnet/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use blockifier::{
1515
execution::contract_class::ContractClass,
1616
state::state_api::{StateReader, StateResult},
1717
};
18+
use cairo_annotations::trace_data::L1Resources;
1819
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
1920
use cairo_vm::vm::trace::trace_entry::RelocatedTraceEntry;
2021
use cairo_vm::Felt252;
@@ -32,7 +33,6 @@ use starknet_api::{
3233
use std::cell::{Ref, RefCell};
3334
use std::collections::HashMap;
3435
use std::rc::Rc;
35-
use trace_data::L1Resources;
3636

3737
// Specifies the duration of the cheat
3838
#[derive(CairoDeserialize, Copy, Clone, Debug, PartialEq, Eq)]

crates/forge-runner/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cairo-lang-sierra-type-size.workspace = true
1919
cairo-lang-sierra-gas.workspace = true
2020
cairo-lang-sierra-ap-change.workspace = true
2121
cairo-lang-test-plugin.workspace = true
22+
cairo-annotations.workspace = true
2223
starknet-types-core.workspace = true
2324
starknet_api.workspace = true
2425
starknet.workspace = true
@@ -43,7 +44,6 @@ semver.workspace = true
4344
console.workspace = true
4445
serde.workspace = true
4546
bimap.workspace = true
46-
trace-data.workspace = true
4747
flatten-serde-json.workspace = true
4848
rayon.workspace = true
4949
cheatnet = { path = "../cheatnet" }

crates/forge-runner/src/build_trace_data.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ use crate::build_trace_data::test_sierra_program_path::VersionedProgramPath;
99
use blockifier::execution::deprecated_syscalls::DeprecatedSyscallSelector;
1010
use blockifier::execution::entry_point::{CallEntryPoint, CallType};
1111
use blockifier::execution::syscalls::hint_processor::SyscallCounter;
12+
use cairo_annotations::trace_data::{
13+
CairoExecutionInfo, CallEntryPoint as ProfilerCallEntryPoint,
14+
CallTraceNode as ProfilerCallTraceNode, CallTraceV1 as ProfilerCallTrace,
15+
CallType as ProfilerCallType, CasmLevelInfo, ContractAddress,
16+
DeprecatedSyscallSelector as ProfilerDeprecatedSyscallSelector,
17+
EntryPointSelector as ProfilerEntryPointSelector, EntryPointType as ProfilerEntryPointType,
18+
ExecutionResources as ProfilerExecutionResources, TraceEntry as ProfilerTraceEntry,
19+
VersionedCallTrace as VersionedProfilerCallTrace, VmExecutionResources,
20+
};
1221
use cairo_vm::vm::runners::cairo_runner::ExecutionResources;
1322
use cairo_vm::vm::trace::trace_entry::RelocatedTraceEntry;
1423
use camino::Utf8PathBuf;
@@ -20,14 +29,6 @@ use conversions::IntoConv;
2029
use starknet::core::utils::get_selector_from_name;
2130
use starknet_api::core::{ClassHash, EntryPointSelector};
2231
use starknet_api::deprecated_contract_class::EntryPointType;
23-
use trace_data::{
24-
CairoExecutionInfo, CallEntryPoint as ProfilerCallEntryPoint, CallTrace as ProfilerCallTrace,
25-
CallTraceNode as ProfilerCallTraceNode, CallType as ProfilerCallType, CasmLevelInfo,
26-
ContractAddress, DeprecatedSyscallSelector as ProfilerDeprecatedSyscallSelector,
27-
EntryPointSelector as ProfilerEntryPointSelector, EntryPointType as ProfilerEntryPointType,
28-
ExecutionResources as ProfilerExecutionResources, TraceEntry as ProfilerTraceEntry,
29-
VmExecutionResources,
30-
};
3132

3233
pub mod test_sierra_program_path;
3334

@@ -173,7 +174,7 @@ pub fn build_profiler_call_entry_point(
173174
let function_name = get_function_name(&entry_point_selector, contracts_data);
174175

175176
ProfilerCallEntryPoint {
176-
class_hash: class_hash.map(|ch| trace_data::ClassHash(ch.to_string())),
177+
class_hash: class_hash.map(|ch| cairo_annotations::trace_data::ClassHash(ch.to_string())),
177178
entry_point_type: build_profiler_entry_point_type(entry_point_type),
178179
entry_point_selector: ProfilerEntryPointSelector(format!("{}", entry_point_selector.0)),
179180
contract_address: ContractAddress(format!("{}", storage_address.0.key())),
@@ -306,7 +307,10 @@ fn build_profiler_trace_entry(value: &RelocatedTraceEntry) -> ProfilerTraceEntry
306307
}
307308
}
308309

309-
pub fn save_trace_data(test_name: &String, trace_data: &ProfilerCallTrace) -> Result<PathBuf> {
310+
pub fn save_trace_data(
311+
test_name: &String,
312+
trace_data: &VersionedProfilerCallTrace,
313+
) -> Result<PathBuf> {
310314
let serialized_trace =
311315
serde_json::to_string(trace_data).expect("Failed to serialize call trace");
312316
let dir_to_save_trace = PathBuf::from(TRACE_DIR);

crates/forge-runner/src/test_case_summary.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::build_trace_data::test_sierra_program_path::VersionedProgramPath;
33
use crate::expected_result::{ExpectedPanicValue, ExpectedTestResult};
44
use crate::gas::check_available_gas;
55
use crate::package_tests::with_config_resolved::TestCaseWithResolvedConfig;
6+
use cairo_annotations::trace_data::VersionedCallTrace as VersionedProfilerCallTrace;
67
use cairo_lang_runner::short_string::as_cairo_short_string;
78
use cairo_lang_runner::{RunResult, RunResultValue};
89
use cairo_vm::Felt252;
@@ -15,7 +16,6 @@ use shared::utils::build_readable_text;
1516
use std::cell::RefCell;
1617
use std::option::Option;
1718
use std::rc::Rc;
18-
use trace_data::CallTrace as ProfilerCallTrace;
1919

2020
#[derive(Debug, PartialEq, Clone, Default)]
2121
pub struct GasStatistics {
@@ -78,7 +78,7 @@ pub struct Single;
7878
impl TestType for Single {
7979
type GasInfo = u128;
8080
type TestStatistics = ();
81-
type TraceData = ProfilerCallTrace;
81+
type TraceData = VersionedProfilerCallTrace;
8282
}
8383

8484
/// Summary of running a single test case
@@ -231,11 +231,11 @@ impl TestCaseSummary<Single> {
231231
test_statistics: (),
232232
gas_info: gas,
233233
used_resources,
234-
trace_data: build_profiler_call_trace(
234+
trace_data: VersionedProfilerCallTrace::V1(build_profiler_call_trace(
235235
call_trace,
236236
contracts_data,
237237
maybe_versioned_program_path,
238-
),
238+
)),
239239
};
240240
check_available_gas(&test_case.config.available_gas, summary)
241241
}
@@ -269,11 +269,11 @@ impl TestCaseSummary<Single> {
269269
test_statistics: (),
270270
gas_info: gas,
271271
used_resources,
272-
trace_data: build_profiler_call_trace(
272+
trace_data: VersionedProfilerCallTrace::V1(build_profiler_call_trace(
273273
call_trace,
274274
contracts_data,
275275
maybe_versioned_program_path,
276-
),
276+
)),
277277
},
278278
},
279279
},

crates/forge/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ cairo-lang-starknet.workspace = true
3232
cairo-lang-compiler.workspace = true
3333
cairo-lang-filesystem.workspace = true
3434
cairo-lang-test-plugin.workspace = true
35+
cairo-annotations.workspace = true
3536
starknet-types-core.workspace = true
3637
itertools.workspace = true
3738
regex.workspace = true
@@ -63,7 +64,6 @@ tokio-util.workspace = true
6364
futures.workspace = true
6465
num-integer.workspace = true
6566
url.workspace = true
66-
trace-data.workspace = true
6767
fs_extra.workspace = true
6868
project-root.workspace = true
6969
indoc.workspace = true

crates/forge/tests/e2e/build_trace_data.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
use super::common::runner::{setup_package, test_runner};
22
use crate::e2e::common::get_trace_from_trace_node;
3+
use cairo_annotations::trace_data::{
4+
CallTraceNode as ProfilerCallTraceNode, CallTraceV1 as ProfilerCallTrace,
5+
VersionedCallTrace as VersionedProfilerCallTrace,
6+
};
37
use cairo_lang_sierra::program::VersionedProgram;
48
use cairo_lang_starknet_classes::contract_class::ContractClass;
59
use forge_runner::build_trace_data::{TEST_CODE_CONTRACT_NAME, TEST_CODE_FUNCTION_NAME, TRACE_DIR};
610
use std::fs;
7-
use trace_data::{CallTrace as ProfilerCallTrace, CallTraceNode as ProfilerCallTraceNode};
811

912
#[test]
1013
fn simple_package_save_trace() {
@@ -34,7 +37,7 @@ fn simple_package_save_trace() {
3437
)
3538
.unwrap();
3639

37-
let call_trace: ProfilerCallTrace =
40+
let VersionedProfilerCallTrace::V1(call_trace) =
3841
serde_json::from_str(&trace_data).expect("Failed to parse call_trace");
3942

4043
assert!(call_trace.nested_calls.is_empty());
@@ -152,14 +155,14 @@ fn trace_has_deploy_with_no_constructor_phantom_nodes() {
152155
// 3 first calls are deploys with empty constructors
153156
matches!(
154157
call_trace.nested_calls[0],
155-
trace_data::CallTraceNode::DeployWithoutConstructor
158+
cairo_annotations::trace_data::CallTraceNode::DeployWithoutConstructor
156159
);
157160
matches!(
158161
call_trace.nested_calls[1],
159-
trace_data::CallTraceNode::DeployWithoutConstructor
162+
cairo_annotations::trace_data::CallTraceNode::DeployWithoutConstructor
160163
);
161164
matches!(
162165
call_trace.nested_calls[2],
163-
trace_data::CallTraceNode::DeployWithoutConstructor
166+
cairo_annotations::trace_data::CallTraceNode::DeployWithoutConstructor
164167
);
165168
}

crates/forge/tests/e2e/common/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use trace_data::{CallTrace as ProfilerCallTrace, CallTraceNode as ProfilerCallTraceNode};
1+
use cairo_annotations::trace_data::{
2+
CallTraceNode as ProfilerCallTraceNode, CallTraceV1 as ProfilerCallTrace,
3+
};
24

35
pub mod runner;
46

0 commit comments

Comments
 (0)