aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-08-17 13:30:33 +0100
committerGitHub <[email protected]>2019-08-17 13:30:33 +0100
commitd15cf2c9600e0464b9bcd0273e7845efbf7bdeb5 (patch)
tree4d08163916538620cc356ed959e3674d49b3683b
parentc2dcabef2a3fab42bbdf1fa6f05e89a02dd6afa3 (diff)
parente751e4d8a366de45b4afe311eedfadcc0a47435c (diff)
Merge #1693
1693: Remove cpuprofile dependencies r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
-rw-r--r--Cargo.lock51
-rw-r--r--crates/ra_cli/Cargo.toml2
-rw-r--r--crates/ra_prof/Cargo.toml3
-rw-r--r--crates/ra_prof/src/google_cpu_profiler.rs39
-rw-r--r--crates/ra_prof/src/lib.rs32
5 files changed, 63 insertions, 64 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4b94aa8a3..f45085921 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -40,20 +40,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
40 40
41[[package]] 41[[package]]
42name = "backtrace" 42name = "backtrace"
43version = "0.2.3"
44source = "registry+https://github.com/rust-lang/crates.io-index"
45dependencies = [
46 "backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
47 "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)",
48 "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
49 "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
50 "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)",
51 "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
52 "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
53]
54
55[[package]]
56name = "backtrace"
57version = "0.3.34" 43version = "0.3.34"
58source = "registry+https://github.com/rust-lang/crates.io-index" 44source = "registry+https://github.com/rust-lang/crates.io-index"
59dependencies = [ 45dependencies = [
@@ -288,15 +274,6 @@ dependencies = [
288] 274]
289 275
290[[package]] 276[[package]]
291name = "cpuprofiler"
292version = "0.0.3"
293source = "registry+https://github.com/rust-lang/crates.io-index"
294dependencies = [
295 "error-chain 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
296 "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
297]
298
299[[package]]
300name = "crossbeam" 277name = "crossbeam"
301version = "0.7.2" 278version = "0.7.2"
302source = "registry+https://github.com/rust-lang/crates.io-index" 279source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -366,15 +343,6 @@ dependencies = [
366] 343]
367 344
368[[package]] 345[[package]]
369name = "dbghelp-sys"
370version = "0.2.0"
371source = "registry+https://github.com/rust-lang/crates.io-index"
372dependencies = [
373 "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
374 "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
375]
376
377[[package]]
378name = "derive-new" 346name = "derive-new"
379version = "0.5.7" 347version = "0.5.7"
380source = "registry+https://github.com/rust-lang/crates.io-index" 348source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -440,14 +408,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
440 408
441[[package]] 409[[package]]
442name = "error-chain" 410name = "error-chain"
443version = "0.5.0"
444source = "registry+https://github.com/rust-lang/crates.io-index"
445dependencies = [
446 "backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
447]
448
449[[package]]
450name = "error-chain"
451version = "0.12.1" 411version = "0.12.1"
452source = "registry+https://github.com/rust-lang/crates.io-index" 412source = "registry+https://github.com/rust-lang/crates.io-index"
453dependencies = [ 413dependencies = [
@@ -768,11 +728,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
768 728
769[[package]] 729[[package]]
770name = "lazy_static" 730name = "lazy_static"
771version = "0.2.11"
772source = "registry+https://github.com/rust-lang/crates.io-index"
773
774[[package]]
775name = "lazy_static"
776version = "1.3.0" 731version = "1.3.0"
777source = "registry+https://github.com/rust-lang/crates.io-index" 732source = "registry+https://github.com/rust-lang/crates.io-index"
778 733
@@ -1351,7 +1306,6 @@ name = "ra_prof"
1351version = "0.1.0" 1306version = "0.1.0"
1352dependencies = [ 1307dependencies = [
1353 "backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)", 1308 "backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)",
1354 "cpuprofiler 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
1355 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 1309 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
1356 "jemalloc-ctl 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 1310 "jemalloc-ctl 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
1357 "jemallocator 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 1311 "jemallocator 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2199,7 +2153,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2199"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba" 2153"checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba"
2200"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" 2154"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"
2201"checksum autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "22130e92352b948e7e82a49cdb0aa94f2211761117f29e052dd397c1ac33542b" 2155"checksum autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "22130e92352b948e7e82a49cdb0aa94f2211761117f29e052dd397c1ac33542b"
2202"checksum backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "346d7644f0b5f9bc73082d3b2236b69a05fd35cce0cfa3724e184e6a5c9e2a2f"
2203"checksum backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)" = "b5164d292487f037ece34ec0de2fcede2faa162f085dd96d2385ab81b12765ba" 2156"checksum backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)" = "b5164d292487f037ece34ec0de2fcede2faa162f085dd96d2385ab81b12765ba"
2204"checksum backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "82a830b4ef2d1124a711c71d263c5abdc710ef8e907bd508c88be475cebc422b" 2157"checksum backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "82a830b4ef2d1124a711c71d263c5abdc710ef8e907bd508c88be475cebc422b"
2205"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" 2158"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e"
@@ -2226,7 +2179,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2226"checksum clicolors-control 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "73abfd4c73d003a674ce5d2933fca6ce6c42480ea84a5ffe0a2dc39ed56300f9" 2179"checksum clicolors-control 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "73abfd4c73d003a674ce5d2933fca6ce6c42480ea84a5ffe0a2dc39ed56300f9"
2227"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" 2180"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f"
2228"checksum console 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8ca57c2c14b8a2bf3105bc9d15574aad80babf6a9c44b1058034cdf8bd169628" 2181"checksum console 0.7.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8ca57c2c14b8a2bf3105bc9d15574aad80babf6a9c44b1058034cdf8bd169628"
2229"checksum cpuprofiler 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "33f07976bb6821459632d7a18d97ccca005cb5c552f251f822c7c1781c1d7035"
2230"checksum crossbeam 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2d818a4990769aac0c7ff1360e233ef3a41adcb009ebb2036bf6915eb0f6b23c" 2182"checksum crossbeam 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2d818a4990769aac0c7ff1360e233ef3a41adcb009ebb2036bf6915eb0f6b23c"
2231"checksum crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c8ec7fcd21571dc78f96cc96243cab8d8f035247c3efd16c687be154c3fa9efa" 2183"checksum crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c8ec7fcd21571dc78f96cc96243cab8d8f035247c3efd16c687be154c3fa9efa"
2232"checksum crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "05e44b8cf3e1a625844d1750e1f7820da46044ff6d28f4d43e455ba3e5bb2c13" 2184"checksum crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "05e44b8cf3e1a625844d1750e1f7820da46044ff6d28f4d43e455ba3e5bb2c13"
@@ -2234,7 +2186,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2234"checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9" 2186"checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9"
2235"checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" 2187"checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b"
2236"checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" 2188"checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6"
2237"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850"
2238"checksum derive-new 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c3fd04571b29c91cfbe1e7c9a228e069ac8635f180ffb4ccd6a6907617ee8bb0" 2189"checksum derive-new 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c3fd04571b29c91cfbe1e7c9a228e069ac8635f180ffb4ccd6a6907617ee8bb0"
2239"checksum deunicode 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690" 2190"checksum deunicode 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690"
2240"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" 2191"checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
@@ -2246,7 +2197,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2246"checksum ena 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3dc01d68e08ca384955a3aeba9217102ca1aa85b6e168639bf27739f1d749d87" 2197"checksum ena 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3dc01d68e08ca384955a3aeba9217102ca1aa85b6e168639bf27739f1d749d87"
2247"checksum encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd" 2198"checksum encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd"
2248"checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9" 2199"checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9"
2249"checksum error-chain 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd5c82c815138e278b8dcdeffc49f27ea6ffb528403e9dea4194f2e3dd40b143"
2250"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" 2200"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
2251"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" 2201"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
2252"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" 2202"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
@@ -2284,7 +2234,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
2284"checksum join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4dc7a5290e8c2606ce2be49f456d50f69173cb96d1541e4f66e34ac8b331a98f" 2234"checksum join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4dc7a5290e8c2606ce2be49f456d50f69173cb96d1541e4f66e34ac8b331a98f"
2285"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" 2235"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
2286"checksum lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cc4fd87be4a815fd373e02773983940f0d75fb26fde8c098e9e45f7af03154c0" 2236"checksum lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cc4fd87be4a815fd373e02773983940f0d75fb26fde8c098e9e45f7af03154c0"
2287"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73"
2288"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" 2237"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14"
2289"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" 2238"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
2290"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" 2239"checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba"
diff --git a/crates/ra_cli/Cargo.toml b/crates/ra_cli/Cargo.toml
index 970cb1f82..9c2ebdad2 100644
--- a/crates/ra_cli/Cargo.toml
+++ b/crates/ra_cli/Cargo.toml
@@ -18,5 +18,5 @@ ra_db = { path = "../ra_db" }
18 18
19[dependencies.ra_prof] 19[dependencies.ra_prof]
20path = "../ra_prof" 20path = "../ra_prof"
21# features = [ "cpuprofiler" ] 21# features = [ "cpu_profiler" ]
22# features = [ "jemalloc" ] 22# features = [ "jemalloc" ]
diff --git a/crates/ra_prof/Cargo.toml b/crates/ra_prof/Cargo.toml
index 84dcc9813..d35adeeeb 100644
--- a/crates/ra_prof/Cargo.toml
+++ b/crates/ra_prof/Cargo.toml
@@ -9,10 +9,9 @@ publish = false
9once_cell = "0.2.0" 9once_cell = "0.2.0"
10itertools = "0.8.0" 10itertools = "0.8.0"
11backtrace = "0.3.28" 11backtrace = "0.3.28"
12cpuprofiler = { version = "0.0.3", optional = true }
13jemallocator = { version = "0.3.2", optional = true } 12jemallocator = { version = "0.3.2", optional = true }
14jemalloc-ctl = { version = "0.3.2", optional = true } 13jemalloc-ctl = { version = "0.3.2", optional = true }
15 14
16
17[features] 15[features]
18jemalloc = [ "jemallocator", "jemalloc-ctl" ] 16jemalloc = [ "jemallocator", "jemalloc-ctl" ]
17cpu_profiler = []
diff --git a/crates/ra_prof/src/google_cpu_profiler.rs b/crates/ra_prof/src/google_cpu_profiler.rs
new file mode 100644
index 000000000..db865c65b
--- /dev/null
+++ b/crates/ra_prof/src/google_cpu_profiler.rs
@@ -0,0 +1,39 @@
1//! https://github.com/gperftools/gperftools
2
3use std::{
4 ffi::CString,
5 os::raw::c_char,
6 path::Path,
7 sync::atomic::{AtomicUsize, Ordering},
8};
9
10#[link(name = "profiler")]
11#[allow(non_snake_case)]
12extern "C" {
13 fn ProfilerStart(fname: *const c_char) -> i32;
14 fn ProfilerStop();
15}
16
17static PROFILER_STATE: AtomicUsize = AtomicUsize::new(OFF);
18const OFF: usize = 0;
19const ON: usize = 1;
20const PENDING: usize = 2;
21
22pub fn start(path: &Path) {
23 if PROFILER_STATE.compare_and_swap(OFF, PENDING, Ordering::SeqCst) != OFF {
24 panic!("profiler already started");
25 }
26 let path = CString::new(path.display().to_string()).unwrap();
27 if unsafe { ProfilerStart(path.as_ptr()) } == 0 {
28 panic!("profiler failed to start")
29 }
30 assert!(PROFILER_STATE.compare_and_swap(PENDING, ON, Ordering::SeqCst) == PENDING);
31}
32
33pub fn stop() {
34 if PROFILER_STATE.compare_and_swap(ON, PENDING, Ordering::SeqCst) != ON {
35 panic!("profiler is not started")
36 }
37 unsafe { ProfilerStop() };
38 assert!(PROFILER_STATE.compare_and_swap(PENDING, OFF, Ordering::SeqCst) == PENDING);
39}
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs
index 6d44fef33..d32a289be 100644
--- a/crates/ra_prof/src/lib.rs
+++ b/crates/ra_prof/src/lib.rs
@@ -1,4 +1,6 @@
1mod memory_usage; 1mod memory_usage;
2#[cfg(feature = "cpu_profiler")]
3mod google_cpu_profiler;
2 4
3use std::{ 5use std::{
4 cell::RefCell, 6 cell::RefCell,
@@ -268,25 +270,35 @@ impl Drop for Scope {
268 } 270 }
269} 271}
270 272
271/// A wrapper around https://github.com/AtheMathmo/cpuprofiler 273/// A wrapper around google_cpu_profiler.
272/// 274///
273/// It can be used to capture sampling profiles of sections of code. 275/// Usage:
274/// It is not exactly out-of-the-box, as it relies on gperftools. 276/// 1. Install gpref_tools (https://github.com/gperftools/gperftools), probably packaged with your Linux distro.
275/// See the docs for the crate for more! 277/// 2. Build with `cpu_profiler` feature.
278/// 3. Tun the code, the *raw* output would be in the `./out.profile` file.
279/// 4. Install pprof for visualization (https://github.com/google/pprof).
280/// 5. Use something like `pprof -svg target/release/ra_cli ./out.profile` to see the results.
281///
282/// For example, here's how I run profiling on NixOS:
283///
284/// ```bash
285/// $ nix-shell -p gperftools --run \
286/// 'cargo run --release -p ra_cli -- parse < ~/projects/rustbench/parser.rs > /dev/null'
287/// ```
276#[derive(Debug)] 288#[derive(Debug)]
277pub struct CpuProfiler { 289pub struct CpuProfiler {
278 _private: (), 290 _private: (),
279} 291}
280 292
281pub fn cpu_profiler() -> CpuProfiler { 293pub fn cpu_profiler() -> CpuProfiler {
282 #[cfg(feature = "cpuprofiler")] 294 #[cfg(feature = "cpu_profiler")]
283 { 295 {
284 cpuprofiler::PROFILER.lock().unwrap().start("./out.profile").unwrap(); 296 google_cpu_profiler::start("./out.profile".as_ref())
285 } 297 }
286 298
287 #[cfg(not(feature = "cpuprofiler"))] 299 #[cfg(not(feature = "cpu_profiler"))]
288 { 300 {
289 eprintln!("cpuprofiler feature is disabled") 301 eprintln!("cpu_profiler feature is disabled")
290 } 302 }
291 303
292 CpuProfiler { _private: () } 304 CpuProfiler { _private: () }
@@ -294,9 +306,9 @@ pub fn cpu_profiler() -> CpuProfiler {
294 306
295impl Drop for CpuProfiler { 307impl Drop for CpuProfiler {
296 fn drop(&mut self) { 308 fn drop(&mut self) {
297 #[cfg(feature = "cpuprofiler")] 309 #[cfg(feature = "cpu_profiler")]
298 { 310 {
299 cpuprofiler::PROFILER.lock().unwrap().stop().unwrap(); 311 google_cpu_profiler::stop()
300 } 312 }
301 } 313 }
302} 314}