diff options
-rw-r--r-- | Cargo.lock | 51 | ||||
-rw-r--r-- | crates/ra_cli/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_prof/Cargo.toml | 3 | ||||
-rw-r--r-- | crates/ra_prof/src/google_cpu_profiler.rs | 39 | ||||
-rw-r--r-- | crates/ra_prof/src/lib.rs | 32 |
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]] |
42 | name = "backtrace" | 42 | name = "backtrace" |
43 | version = "0.2.3" | ||
44 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
45 | dependencies = [ | ||
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]] | ||
56 | name = "backtrace" | ||
57 | version = "0.3.34" | 43 | version = "0.3.34" |
58 | source = "registry+https://github.com/rust-lang/crates.io-index" | 44 | source = "registry+https://github.com/rust-lang/crates.io-index" |
59 | dependencies = [ | 45 | dependencies = [ |
@@ -288,15 +274,6 @@ dependencies = [ | |||
288 | ] | 274 | ] |
289 | 275 | ||
290 | [[package]] | 276 | [[package]] |
291 | name = "cpuprofiler" | ||
292 | version = "0.0.3" | ||
293 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
294 | dependencies = [ | ||
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]] | ||
300 | name = "crossbeam" | 277 | name = "crossbeam" |
301 | version = "0.7.2" | 278 | version = "0.7.2" |
302 | source = "registry+https://github.com/rust-lang/crates.io-index" | 279 | source = "registry+https://github.com/rust-lang/crates.io-index" |
@@ -366,15 +343,6 @@ dependencies = [ | |||
366 | ] | 343 | ] |
367 | 344 | ||
368 | [[package]] | 345 | [[package]] |
369 | name = "dbghelp-sys" | ||
370 | version = "0.2.0" | ||
371 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
372 | dependencies = [ | ||
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]] | ||
378 | name = "derive-new" | 346 | name = "derive-new" |
379 | version = "0.5.7" | 347 | version = "0.5.7" |
380 | source = "registry+https://github.com/rust-lang/crates.io-index" | 348 | source = "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]] |
442 | name = "error-chain" | 410 | name = "error-chain" |
443 | version = "0.5.0" | ||
444 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
445 | dependencies = [ | ||
446 | "backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", | ||
447 | ] | ||
448 | |||
449 | [[package]] | ||
450 | name = "error-chain" | ||
451 | version = "0.12.1" | 411 | version = "0.12.1" |
452 | source = "registry+https://github.com/rust-lang/crates.io-index" | 412 | source = "registry+https://github.com/rust-lang/crates.io-index" |
453 | dependencies = [ | 413 | dependencies = [ |
@@ -768,11 +728,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | |||
768 | 728 | ||
769 | [[package]] | 729 | [[package]] |
770 | name = "lazy_static" | 730 | name = "lazy_static" |
771 | version = "0.2.11" | ||
772 | source = "registry+https://github.com/rust-lang/crates.io-index" | ||
773 | |||
774 | [[package]] | ||
775 | name = "lazy_static" | ||
776 | version = "1.3.0" | 731 | version = "1.3.0" |
777 | source = "registry+https://github.com/rust-lang/crates.io-index" | 732 | source = "registry+https://github.com/rust-lang/crates.io-index" |
778 | 733 | ||
@@ -1351,7 +1306,6 @@ name = "ra_prof" | |||
1351 | version = "0.1.0" | 1306 | version = "0.1.0" |
1352 | dependencies = [ | 1307 | dependencies = [ |
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] |
20 | path = "../ra_prof" | 20 | path = "../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 | |||
9 | once_cell = "0.2.0" | 9 | once_cell = "0.2.0" |
10 | itertools = "0.8.0" | 10 | itertools = "0.8.0" |
11 | backtrace = "0.3.28" | 11 | backtrace = "0.3.28" |
12 | cpuprofiler = { version = "0.0.3", optional = true } | ||
13 | jemallocator = { version = "0.3.2", optional = true } | 12 | jemallocator = { version = "0.3.2", optional = true } |
14 | jemalloc-ctl = { version = "0.3.2", optional = true } | 13 | jemalloc-ctl = { version = "0.3.2", optional = true } |
15 | 14 | ||
16 | |||
17 | [features] | 15 | [features] |
18 | jemalloc = [ "jemallocator", "jemalloc-ctl" ] | 16 | jemalloc = [ "jemallocator", "jemalloc-ctl" ] |
17 | cpu_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 | |||
3 | use 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)] | ||
12 | extern "C" { | ||
13 | fn ProfilerStart(fname: *const c_char) -> i32; | ||
14 | fn ProfilerStop(); | ||
15 | } | ||
16 | |||
17 | static PROFILER_STATE: AtomicUsize = AtomicUsize::new(OFF); | ||
18 | const OFF: usize = 0; | ||
19 | const ON: usize = 1; | ||
20 | const PENDING: usize = 2; | ||
21 | |||
22 | pub 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 | |||
33 | pub 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 @@ | |||
1 | mod memory_usage; | 1 | mod memory_usage; |
2 | #[cfg(feature = "cpu_profiler")] | ||
3 | mod google_cpu_profiler; | ||
2 | 4 | ||
3 | use std::{ | 5 | use 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)] |
277 | pub struct CpuProfiler { | 289 | pub struct CpuProfiler { |
278 | _private: (), | 290 | _private: (), |
279 | } | 291 | } |
280 | 292 | ||
281 | pub fn cpu_profiler() -> CpuProfiler { | 293 | pub 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 | ||
295 | impl Drop for CpuProfiler { | 307 | impl 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 | } |