This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to tag v0.13.2-rc1
in repository https://gitbox.apache.org/repos/asf/fory.git

commit a017de11789f0a14b970c4fd4e0964e532c1866c
Author: Shawn Yang <[email protected]>
AuthorDate: Mon Nov 3 20:52:25 2025 +0800

    perf(rust): support criterion profiler to generate flamegraph (#2882)
    
    ## Why?
    
    <!-- Describe the purpose of this PR. -->
    
    ## What does this PR do?
    
    support criterion profiler to generate flamegraph
    
    ## Related issues
    
    <!--
    Is there any related issue? If this PR closes them you say say
    fix/closes:
    
    - #xxxx0
    - #xxxx1
    - Fixes #xxxx2
    -->
    
    ## Does this PR introduce any user-facing change?
    
    <!--
    If any user-facing interface changes, please [open an
    issue](https://github.com/apache/fory/issues/new/choose) describing the
    need to do so and update the document if necessary.
    
    Delete section if not applicable.
    -->
    
    - [ ] Does this PR introduce any public API change?
    - [ ] Does this PR introduce any binary protocol compatibility change?
    
    ## Benchmark
    
    <!--
    When the PR has an impact on performance (if you don't know whether the
    PR will have an impact on performance, you can submit the PR first, and
    if it will have impact on performance, the code reviewer will explain
    it), be sure to attach a benchmark data here.
    
    Delete section if not applicable.
    -->
---
 rust/benches/Cargo.toml                     |  5 +++++
 rust/benches/README.md                      |  9 +++++++++
 rust/benches/benches/serialization_bench.rs | 22 ++++++++++++++++++++--
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/rust/benches/Cargo.toml b/rust/benches/Cargo.toml
index e5d83c703..3a23c12f6 100644
--- a/rust/benches/Cargo.toml
+++ b/rust/benches/Cargo.toml
@@ -41,6 +41,11 @@ prost-types = "0.12"
 rand = "0.8"
 criterion = "0.5"
 clap = { version = "4.0", features = ["derive"] }
+pprof = { version = "=0.14.0", features = ["flamegraph", "criterion"], 
optional = true }
+
+[features]
+default = []
+profiling = ["pprof"]
 
 [build-dependencies]
 prost-build = "0.12"
diff --git a/rust/benches/README.md b/rust/benches/README.md
index ffa6d77e9..d0de365b0 100644
--- a/rust/benches/README.md
+++ b/rust/benches/README.md
@@ -145,10 +145,19 @@ python benchmark_report.py --log-file cargo_bench.log 
--output-dir=report_output
 
 ## How to generate flamegraph
 
+Basic command:
+
 ```bash
 cargo flamegraph --bin fory_profiler -- --operation deserialize --serializer 
fory -t e-commerce-data
 ```
 
+Using criterion to generate flamegraph for any benchmark:
+
+```bash
+cargo bench --bench serialization_bench --features profiling -- 
simple_struct/fory_serialize/small --profile-time=10
+ls 
../target/criterion/simple_struct/fory_serialize/small/profile/flamegraph.svg
+```
+
 detailed command:
 
 ```bash
diff --git a/rust/benches/benches/serialization_bench.rs 
b/rust/benches/benches/serialization_bench.rs
index e46876935..89d6714c8 100644
--- a/rust/benches/benches/serialization_bench.rs
+++ b/rust/benches/benches/serialization_bench.rs
@@ -15,8 +15,26 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use criterion::{criterion_group, criterion_main};
+use criterion::{criterion_group, criterion_main, Criterion};
 use fory_benchmarks::run_serialization_benchmarks;
 
-criterion_group!(benches, run_serialization_benchmarks);
+#[cfg(feature = "profiling")]
+use pprof::criterion::{Output, PProfProfiler};
+
+fn config() -> Criterion {
+    #[cfg(feature = "profiling")]
+    {
+        Criterion::default().with_profiler(PProfProfiler::new(100, 
Output::Flamegraph(None)))
+    }
+    #[cfg(not(feature = "profiling"))]
+    {
+        Criterion::default()
+    }
+}
+
+criterion_group! {
+    name = benches;
+    config = config();
+    targets = run_serialization_benchmarks
+}
 criterion_main!(benches);


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to