SlideShare a Scribd company logo
Performance Analysis
The Rust edition
Performance Profiling in Rust
Performance Profiling in Rust
Performance Profiling in Rust
Performance Analysis
Questions:
Performance Analysis
Questions:
Who ate my CPU?
Performance Analysis
Questions:
Who ate my CPU? Who ate my RAM?
CPU
Performance Profiling in Rust
CPU profiling
$ cargo install flamegraph
$ cargo flamegraph --dev
CPU profiling
$ cargo install flamegraph
$ cargo flamegraph --dev
dtrace: system integrity protection is on, some features will not be
available
dtrace: failed to initialize dtrace: DTrace requires additional
privileges
failed to sample program
Performance Profiling in Rust
Just use linux
$ docker run --rm rust:1.51
# apt-get install linux-perf
...
# cargo flamegraph
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
/usr/bin/perf: line 13: exec: perf_5.10: not found
E: linux-perf-5.10 is not installed.
failed to sample program
Performance Profiling in Rust
Match the kernel version
$ docker run --rm rust:1.51-bullseye
# apt-get install linux-perf
...
# cargo flamegraph --dev
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
….
Performance Profiling in Rust
Profiling a running program
$ cargo install inferno
$ perf record -p "$(pgrep profexample)" -F 997 -g
…^C
[ perf record: Captured and wrote 5.535 MB perf.data (81144 samples) ]
$ perf script | inferno-collapse-perf > stacks.folded
$ inferno-flamegraph < stacks.folded > flamegraph.svg
$ open flamegraph.svg
...
Performance Profiling in Rust
Small digression
● Frame pointers:
push rbp
mov rbp, rsp
Small digression (2)
● On x86-64 the default is to omit frame pointers
● X86-64 ABI says:
● The conventional use of %rbp as a frame pointer for the stack frame may be avoided by using %rsp (the stack
pointer) to index into the stack frame. This technique saves two instructions in the prologue and epilogue and
makes one additional general-purpose register (%rbp) available.
● Gcc since 4.6 omits frame pointers by default on x84-6
● Rust omits frame pointers also on dev builds
● DWARF info is used to figure out the layout of the stack frame for
each function. You don’t need full debug info for backtraces:
[profile.release]
debug = 1
Profiling a running program
$ cargo install inferno
$ perf record -p "$(pgrep profexample)" -F 997 -g --call-graph dwarf
…^C
[ perf record: Captured and wrote 461.199 MB perf.data (57251 samples) ]
$ perf script | inferno-collapse-perf > stacks.folded
$ inferno-flamegraph < stacks.folded > flamegraph.svg
$ open flamegraph.svg
...
Performance Profiling in Rust
Questions:
What are those unknown functions called by “factorial”?
Questions:
● What if I want to run this on k8s where I don’t control my kernel version?
● What if I want to run this on mac without pulling my hair out?
● What if I don’t have a shell on prod?
Questions:
● What if I want to run this on k8s where I don’t control my kernel version?
● What if I want to run this on mac without pulling my hair out?
● What if I don’t have a shell on prod?
Performance Profiling in Rust
Go
package main
import (
"net/http"
_ "net/http/pprof"
)
func main() {
// ...
http.ListenAndServe("localhost:6060", nil)
}
$ go tool pprof --http localhost:4080
'http://localhost:6060/debug/pprof/profile'
Fetching profile over HTTP from http://localhost:6060/debug/pprof/profile
Saved profile in /Users/mkm/pprof/pprof.samples.cpu.001.pb.gz
Serving web UI on http://localhost:4080
Performance Profiling in Rust
Performance Profiling in Rust
Performance Profiling in Rust
● https://github.com/google/pprof
○ Multiple languages, not only Go
● https://github.com/google/perf_data_converter
Rust?
Enter: tikv/pprof-rs !!
[dependencies]
+pprof = { version = "0.4", features = ["flamegraph"] }
tikv/pprof-rs
fn main() {
+ let guard = pprof::ProfilerGuard::new(997).unwrap();
+
for _ in 0..6 {
thread::spawn(worker);
}
thread::sleep(time::Duration::from_secs(10));
+
+ if let Ok(report) = guard.report().build() {
+ let file = File::create("flamegraph.svg").unwrap();
+ report.flamegraph(file).unwrap();
+ };
}
Performance Profiling in Rust
Performance Profiling in Rust
Performance Profiling in Rust
$ kubectl -n iox port-forward deploy/iox-router-1000 8080:8080
$ firefox 'http://localhost:8080/debug/pprof/profile?seconds=30'
Performance Profiling in Rust
$ kubectl -n iox port-forward deploy/iox-router-1000 8080:8080
$ go tool --http localhost:4080 
pprof 'http://localhost:8080/debug/pprof/profile?seconds=30'
Performance Profiling in Rust
Performance Profiling in Rust
Performance Profiling in Rust
Compatible with https://speedscope.app
How does that work
https://github.com/influxdata/influxdb_iox/blob/main/src/influxdb_ioxd/http.rs#L364
How does that work
$ curl 'http://localhost:8080/debug/pprof/profile?seconds=1' | pq --msgtype perftools.profiles.Profile | jq
{
"sample_type": [
{
"type": 1164,
"unit": 1165
}
],
"sample": [
{
"location_id": [
1,
2,
...
"value": [
1
],
...
"string_table": [
"",
"flatbuffers::builder::FlatBufferBuilder::create_string",
"_ZN81_$LT$core..str..iter..Chars$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17hfd848827f3ee829eE",
"_ZN4core3ptr19swap_nonoverlapping17h364e10b3426efe72E",
"_ZN6server15Server$LT$M$GT$19write_sharded_entry28_$u7b$$u7b$closure$u7d$$u7d$17h4746f0c3132c7a41E",
"_ZN5alloc4sync12Arc$LT$T$GT$9drop_slow17h20a22a0cdaab7f27E",
"_ZN22influxdb_line_protocol7tag_key17hf795357f1c28005dE",
How does that work
$ curl -s -H "accept: text/html" 'http://localhost:8080/debug/pprof/profile?seconds=1' | head
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" width="1200" height="2262" onload="init(evt)" viewBox="0 0
1200 2262" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:fg="http://github.com/jonhoo/inferno"><!--Flame graph stack visualization. See https://github.com/brendangregg/FlameGraph for
latest version, and http://www.brendangregg.com/flamegraphs.html for examples.--><!--NOTES: --><defs><linearGradient id="background"
y1="0" y2="1" x1="0" x2="0"><stop stop-color="#eeeeee" offset="5%"/><stop stop-color="#eeeeb0"
offset="95%"/></linearGradient></defs><style type="text/css">
text { font-family:"Verdana"; font-size:12px; fill:rgb(0,0,0); }
#title { text-anchor:middle; font-size:17px; }
#search { opacity:0.1; cursor:pointer; }
#search:hover, #search.show { opacity:1; }
#subtitle { text-anchor:middle; font-color:rgb(160,160,160); }
#unzoom { cursor:pointer; }
#frames > *:hover { stroke:black; stroke-width:0.5; cursor:pointer; }
.hide { display:none; }
.parent { opacity:0.5; }
...
Backtraces and async
https://github.com/rust-lang/rust/issues/73524
HEAP
Attempt 1
[dependencies]
tikv-jemallocator = {version = "0.4.0", features = ["profiling"] }
#[global_allocator]
static GLOBAL: Jemalloc = Jemalloc;
$ cargo build &&
_RJEM_MALLOC_CONF="prof:true,prof_final:true,prof_prefix:jeprof.out"
./target/debug/profexample
Performance Profiling in Rust
Attempt 2: implement it like pprof-rs
use super::Profiler;
use libc::{c_int, c_void, size_t};
#[link(name = "jemalloc")]
extern "C" {
#[link_name = "_rjem_malloc"]
pub fn sys_malloc(size: size_t) -> *mut c_void;
#[link_name = "_rjem_free"]
pub fn sys_free(ptr: *mut c_void);
#[link_name = "_rjem_realloc"]
pub fn sys_realloc(ptr: *mut c_void, size: size_t) -> *mut c_void;
}
#[no_mangle]
pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
Profiler::track_allocated(size as isize);
sys_malloc(size)
}
//! The standard API includes: the [`malloc`], [`calloc`], [`realloc`], and
//! [`free`], which conform to to ISO/IEC 9899:1990 (“ISO C90”),
//! [`posix_memalign`] which conforms to conforms to POSIX.1-2016, and
//! [`aligned_alloc`].
Performance Profiling in Rust
Performance Profiling in Rust
Performance Profiling in Rust
Questions
Performance Profiling in Rust
Performance Profiling in Rust
Performance Profiling in Rust
Performance Profiling in Rust

More Related Content

PDF
Distributed Locking in Kubernetes
ODP
Introduction to Nginx
PDF
High Availability PostgreSQL with Zalando Patroni
PDF
Building Event Streaming Architectures on Scylla and Kafka
PDF
Introduction to Kubernetes Workshop
PDF
Infrastructure & System Monitoring using Prometheus
PDF
Introduction to docker
Distributed Locking in Kubernetes
Introduction to Nginx
High Availability PostgreSQL with Zalando Patroni
Building Event Streaming Architectures on Scylla and Kafka
Introduction to Kubernetes Workshop
Infrastructure & System Monitoring using Prometheus
Introduction to docker

What's hot (20)

PDF
Ansible Introduction
PDF
Automation with ansible
PDF
Introduction to Redis
PDF
How to write a Dockerfile
PDF
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
PDF
An Introduction to Kubernetes
PDF
Introduction to docker and docker compose
PPTX
Terraform Basics
PPTX
Prometheus design and philosophy
PDF
Best Practices for ETL with Apache NiFi on Kubernetes - Albert Lewandowski, G...
PPTX
Kafka at Peak Performance
PDF
MySQL Router REST API
PDF
Kubernetes - A Comprehensive Overview
PDF
Consumer offset management in Kafka
PDF
MoP(MQTT on Pulsar) - a Powerful Tool for Apache Pulsar in IoT - Pulsar Summi...
PDF
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
PDF
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
PDF
Apache BookKeeper: A High Performance and Low Latency Storage Service
PPTX
Using Wildcards with rsyslog's File Monitor imfile
ODP
OpenGurukul : Database : PostgreSQL
Ansible Introduction
Automation with ansible
Introduction to Redis
How to write a Dockerfile
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latenc...
An Introduction to Kubernetes
Introduction to docker and docker compose
Terraform Basics
Prometheus design and philosophy
Best Practices for ETL with Apache NiFi on Kubernetes - Albert Lewandowski, G...
Kafka at Peak Performance
MySQL Router REST API
Kubernetes - A Comprehensive Overview
Consumer offset management in Kafka
MoP(MQTT on Pulsar) - a Powerful Tool for Apache Pulsar in IoT - Pulsar Summi...
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
Apache kafka 모니터링을 위한 Metrics 이해 및 최적화 방안
Apache BookKeeper: A High Performance and Low Latency Storage Service
Using Wildcards with rsyslog's File Monitor imfile
OpenGurukul : Database : PostgreSQL
Ad

Similar to Performance Profiling in Rust (20)

PDF
Bangpypers april-meetup-2012
PPTX
Toolbox of a Ruby Team
PPT
Systemtap
PDF
Deep learning - the conf br 2018
PDF
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
PDF
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
PPTX
2012 coscup - Build your PHP application on Heroku
PDF
Filip palian mateuszkocielski. simplest ownage human observed… routers
PDF
Simplest-Ownage-Human-Observed… - Routers
PDF
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
KEY
Railsconf2011 deployment tips_for_slideshare
PDF
Lean Php Presentation
PDF
Containers for sysadmins
PPTX
Control your deployments with Capistrano
PDF
Continuous Delivery: The Next Frontier
PPTX
Deployment with Fabric
PDF
infra-as-code
PPTX
Nodejs Performance Debug
PDF
Red Hat OpenStack 17 저자직강+스터디그룹_4주차
PPTX
Infrastructure as code - Python Saati #36
Bangpypers april-meetup-2012
Toolbox of a Ruby Team
Systemtap
Deep learning - the conf br 2018
파이썬 개발환경 구성하기의 끝판왕 - Docker Compose
2017-03-11 02 Денис Нелюбин. Docker & Ansible - лучшие друзья DevOps
2012 coscup - Build your PHP application on Heroku
Filip palian mateuszkocielski. simplest ownage human observed… routers
Simplest-Ownage-Human-Observed… - Routers
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
Railsconf2011 deployment tips_for_slideshare
Lean Php Presentation
Containers for sysadmins
Control your deployments with Capistrano
Continuous Delivery: The Next Frontier
Deployment with Fabric
infra-as-code
Nodejs Performance Debug
Red Hat OpenStack 17 저자직강+스터디그룹_4주차
Infrastructure as code - Python Saati #36
Ad

More from InfluxData (20)

PPTX
Announcing InfluxDB Clustered
PDF
Best Practices for Leveraging the Apache Arrow Ecosystem
PDF
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...
PDF
Power Your Predictive Analytics with InfluxDB
PDF
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
PDF
Build an Edge-to-Cloud Solution with the MING Stack
PDF
Meet the Founders: An Open Discussion About Rewriting Using Rust
PDF
Introducing InfluxDB Cloud Dedicated
PDF
Gain Better Observability with OpenTelemetry and InfluxDB
PPTX
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
PDF
How Delft University's Engineering Students Make Their EV Formula-Style Race ...
PPTX
Introducing InfluxDB’s New Time Series Database Storage Engine
PDF
Start Automating InfluxDB Deployments at the Edge with balena
PDF
Understanding InfluxDB’s New Storage Engine
PDF
Streamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDB
PPTX
Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...
PDF
Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022
PDF
Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022
PDF
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
PDF
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022
Announcing InfluxDB Clustered
Best Practices for Leveraging the Apache Arrow Ecosystem
How Bevi Uses InfluxDB and Grafana to Improve Predictive Maintenance and Redu...
Power Your Predictive Analytics with InfluxDB
How Teréga Replaces Legacy Data Historians with InfluxDB, AWS and IO-Base
Build an Edge-to-Cloud Solution with the MING Stack
Meet the Founders: An Open Discussion About Rewriting Using Rust
Introducing InfluxDB Cloud Dedicated
Gain Better Observability with OpenTelemetry and InfluxDB
How a Heat Treating Plant Ensures Tight Process Control and Exceptional Quali...
How Delft University's Engineering Students Make Their EV Formula-Style Race ...
Introducing InfluxDB’s New Time Series Database Storage Engine
Start Automating InfluxDB Deployments at the Edge with balena
Understanding InfluxDB’s New Storage Engine
Streamline and Scale Out Data Pipelines with Kubernetes, Telegraf, and InfluxDB
Ward Bowman [PTC] | ThingWorx Long-Term Data Storage with InfluxDB | InfluxDa...
Scott Anderson [InfluxData] | New & Upcoming Flux Features | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Closing Thoughts | InfluxDays 2022
Steinkamp, Clifford [InfluxData] | Welcome to InfluxDays 2022 - Day 2 | Influ...
Steinkamp, Clifford [InfluxData] | Closing Thoughts Day 1 | InfluxDays 2022

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
KodekX | Application Modernization Development
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation theory and applications.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
cuic standard and advanced reporting.pdf
The AUB Centre for AI in Media Proposal.docx
MYSQL Presentation for SQL database connectivity
KodekX | Application Modernization Development
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Digital-Transformation-Roadmap-for-Companies.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Spectroscopy.pptx food analysis technology
Encapsulation theory and applications.pdf
Approach and Philosophy of On baking technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Building Integrated photovoltaic BIPV_UPV.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Advanced methodologies resolving dimensionality complications for autism neur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Chapter 3 Spatial Domain Image Processing.pdf
Network Security Unit 5.pdf for BCA BBA.

Performance Profiling in Rust

  • 7. Performance Analysis Questions: Who ate my CPU? Who ate my RAM?
  • 8. CPU
  • 10. CPU profiling $ cargo install flamegraph $ cargo flamegraph --dev
  • 11. CPU profiling $ cargo install flamegraph $ cargo flamegraph --dev dtrace: system integrity protection is on, some features will not be available dtrace: failed to initialize dtrace: DTrace requires additional privileges failed to sample program
  • 13. Just use linux $ docker run --rm rust:1.51 # apt-get install linux-perf ... # cargo flamegraph Finished dev [unoptimized + debuginfo] target(s) in 0.03s /usr/bin/perf: line 13: exec: perf_5.10: not found E: linux-perf-5.10 is not installed. failed to sample program
  • 15. Match the kernel version $ docker run --rm rust:1.51-bullseye # apt-get install linux-perf ... # cargo flamegraph --dev Finished dev [unoptimized + debuginfo] target(s) in 0.03s ….
  • 17. Profiling a running program $ cargo install inferno $ perf record -p "$(pgrep profexample)" -F 997 -g …^C [ perf record: Captured and wrote 5.535 MB perf.data (81144 samples) ] $ perf script | inferno-collapse-perf > stacks.folded $ inferno-flamegraph < stacks.folded > flamegraph.svg $ open flamegraph.svg ...
  • 19. Small digression ● Frame pointers: push rbp mov rbp, rsp
  • 20. Small digression (2) ● On x86-64 the default is to omit frame pointers ● X86-64 ABI says: ● The conventional use of %rbp as a frame pointer for the stack frame may be avoided by using %rsp (the stack pointer) to index into the stack frame. This technique saves two instructions in the prologue and epilogue and makes one additional general-purpose register (%rbp) available. ● Gcc since 4.6 omits frame pointers by default on x84-6 ● Rust omits frame pointers also on dev builds ● DWARF info is used to figure out the layout of the stack frame for each function. You don’t need full debug info for backtraces: [profile.release] debug = 1
  • 21. Profiling a running program $ cargo install inferno $ perf record -p "$(pgrep profexample)" -F 997 -g --call-graph dwarf …^C [ perf record: Captured and wrote 461.199 MB perf.data (57251 samples) ] $ perf script | inferno-collapse-perf > stacks.folded $ inferno-flamegraph < stacks.folded > flamegraph.svg $ open flamegraph.svg ...
  • 23. Questions: What are those unknown functions called by “factorial”?
  • 24. Questions: ● What if I want to run this on k8s where I don’t control my kernel version? ● What if I want to run this on mac without pulling my hair out? ● What if I don’t have a shell on prod?
  • 25. Questions: ● What if I want to run this on k8s where I don’t control my kernel version? ● What if I want to run this on mac without pulling my hair out? ● What if I don’t have a shell on prod?
  • 27. Go package main import ( "net/http" _ "net/http/pprof" ) func main() { // ... http.ListenAndServe("localhost:6060", nil) }
  • 28. $ go tool pprof --http localhost:4080 'http://localhost:6060/debug/pprof/profile' Fetching profile over HTTP from http://localhost:6060/debug/pprof/profile Saved profile in /Users/mkm/pprof/pprof.samples.cpu.001.pb.gz Serving web UI on http://localhost:4080
  • 32. ● https://github.com/google/pprof ○ Multiple languages, not only Go ● https://github.com/google/perf_data_converter
  • 33. Rust? Enter: tikv/pprof-rs !! [dependencies] +pprof = { version = "0.4", features = ["flamegraph"] }
  • 34. tikv/pprof-rs fn main() { + let guard = pprof::ProfilerGuard::new(997).unwrap(); + for _ in 0..6 { thread::spawn(worker); } thread::sleep(time::Duration::from_secs(10)); + + if let Ok(report) = guard.report().build() { + let file = File::create("flamegraph.svg").unwrap(); + report.flamegraph(file).unwrap(); + }; }
  • 38. $ kubectl -n iox port-forward deploy/iox-router-1000 8080:8080 $ firefox 'http://localhost:8080/debug/pprof/profile?seconds=30'
  • 40. $ kubectl -n iox port-forward deploy/iox-router-1000 8080:8080 $ go tool --http localhost:4080 pprof 'http://localhost:8080/debug/pprof/profile?seconds=30'
  • 45. How does that work https://github.com/influxdata/influxdb_iox/blob/main/src/influxdb_ioxd/http.rs#L364
  • 46. How does that work $ curl 'http://localhost:8080/debug/pprof/profile?seconds=1' | pq --msgtype perftools.profiles.Profile | jq { "sample_type": [ { "type": 1164, "unit": 1165 } ], "sample": [ { "location_id": [ 1, 2, ... "value": [ 1 ], ... "string_table": [ "", "flatbuffers::builder::FlatBufferBuilder::create_string", "_ZN81_$LT$core..str..iter..Chars$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17hfd848827f3ee829eE", "_ZN4core3ptr19swap_nonoverlapping17h364e10b3426efe72E", "_ZN6server15Server$LT$M$GT$19write_sharded_entry28_$u7b$$u7b$closure$u7d$$u7d$17h4746f0c3132c7a41E", "_ZN5alloc4sync12Arc$LT$T$GT$9drop_slow17h20a22a0cdaab7f27E", "_ZN22influxdb_line_protocol7tag_key17hf795357f1c28005dE",
  • 47. How does that work $ curl -s -H "accept: text/html" 'http://localhost:8080/debug/pprof/profile?seconds=1' | head <?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" width="1200" height="2262" onload="init(evt)" viewBox="0 0 1200 2262" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fg="http://github.com/jonhoo/inferno"><!--Flame graph stack visualization. See https://github.com/brendangregg/FlameGraph for latest version, and http://www.brendangregg.com/flamegraphs.html for examples.--><!--NOTES: --><defs><linearGradient id="background" y1="0" y2="1" x1="0" x2="0"><stop stop-color="#eeeeee" offset="5%"/><stop stop-color="#eeeeb0" offset="95%"/></linearGradient></defs><style type="text/css"> text { font-family:"Verdana"; font-size:12px; fill:rgb(0,0,0); } #title { text-anchor:middle; font-size:17px; } #search { opacity:0.1; cursor:pointer; } #search:hover, #search.show { opacity:1; } #subtitle { text-anchor:middle; font-color:rgb(160,160,160); } #unzoom { cursor:pointer; } #frames > *:hover { stroke:black; stroke-width:0.5; cursor:pointer; } .hide { display:none; } .parent { opacity:0.5; } ...
  • 49. HEAP
  • 50. Attempt 1 [dependencies] tikv-jemallocator = {version = "0.4.0", features = ["profiling"] } #[global_allocator] static GLOBAL: Jemalloc = Jemalloc; $ cargo build && _RJEM_MALLOC_CONF="prof:true,prof_final:true,prof_prefix:jeprof.out" ./target/debug/profexample
  • 52. Attempt 2: implement it like pprof-rs use super::Profiler; use libc::{c_int, c_void, size_t}; #[link(name = "jemalloc")] extern "C" { #[link_name = "_rjem_malloc"] pub fn sys_malloc(size: size_t) -> *mut c_void; #[link_name = "_rjem_free"] pub fn sys_free(ptr: *mut c_void); #[link_name = "_rjem_realloc"] pub fn sys_realloc(ptr: *mut c_void, size: size_t) -> *mut c_void; } #[no_mangle] pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void { Profiler::track_allocated(size as isize); sys_malloc(size) }
  • 53. //! The standard API includes: the [`malloc`], [`calloc`], [`realloc`], and //! [`free`], which conform to to ISO/IEC 9899:1990 (“ISO C90”), //! [`posix_memalign`] which conforms to conforms to POSIX.1-2016, and //! [`aligned_alloc`].