Introduce flame_guard in rustpython-stdlib too (#6722) · RustPython/RustPython@49e6931 · GitHub
Skip to content

Commit 49e6931

Browse files
authored
Introduce flame_guard in rustpython-stdlib too (#6722)
1 parent 9eeea92 commit 49e6931

6 files changed

Lines changed: 18 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 1 addition & 0 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

crates/stdlib/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ssl-rustls-fips = ["ssl-rustls", "aws-lc-rs/fips"]
2222
ssl-openssl = ["ssl", "openssl", "openssl-sys", "foreign-types-shared", "openssl-probe"]
2323
ssl-vendor = ["ssl-openssl", "openssl/vendored"]
2424
tkinter = ["dep:tk-sys", "dep:tcl-sys", "dep:widestring"]
25+
flame-it = ["flame"]
2526

2627
[dependencies]
2728
# rustpython crates
@@ -33,6 +34,7 @@ ahash = { workspace = true }
3334
ascii = { workspace = true }
3435
cfg-if = { workspace = true }
3536
crossbeam-utils = { workspace = true }
37+
flame = { workspace = true, optional = true }
3638
hex = { workspace = true }
3739
itertools = { workspace = true }
3840
indexmap = { workspace = true }

crates/stdlib/src/json.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ mod _json {
7474
scan_once: PyObjectRef,
7575
vm: &VirtualMachine,
7676
) -> PyResult<PyIterReturn> {
77+
flame_guard!("JsonScanner::parse");
7778
let c = match s.chars().next() {
7879
Some(c) => c,
7980
None => {
@@ -153,6 +154,7 @@ mod _json {
153154
}
154155

155156
fn parse_number(&self, s: &str, vm: &VirtualMachine) -> Option<(PyResult, usize)> {
157+
flame_guard!("JsonScanner::parse_number");
156158
let mut has_neg = false;
157159
let mut has_decimal = false;
158160
let mut has_exponent = false;
@@ -213,6 +215,7 @@ mod _json {
213215
}
214216

215217
fn encode_string(s: &str, ascii_only: bool) -> String {
218+
flame_guard!("_json::encode_string");
216219
let mut buf = Vec::<u8>::with_capacity(s.len() + 2);
217220
machinery::write_json_string(s, ascii_only, &mut buf)
218221
// SAFETY: writing to a vec can't fail
@@ -253,6 +256,7 @@ mod _json {
253256
strict: OptionalArg<bool>,
254257
vm: &VirtualMachine,
255258
) -> PyResult<(Wtf8Buf, usize)> {
259+
flame_guard!("_json::scanstring");
256260
machinery::scanstring(s.as_wtf8(), end, strict.unwrap_or(true))
257261
.map_err(|e| py_decode_error(e, s, vm))
258262
}

crates/stdlib/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
extern crate rustpython_derive;
99
extern crate alloc;
1010

11+
#[macro_use]
12+
pub(crate) mod macros;
13+
1114
pub mod array;
1215
mod binascii;
1316
mod bisect;

crates/stdlib/src/macros.rs

Lines changed: 7 additions & 0 deletions

0 commit comments

Comments
 (0)