1
- use std:: path:: Path ;
1
+ use std:: path:: { Path , PathBuf } ;
2
2
use std:: process:: Command ;
3
3
4
4
/// Uses the `llvm-bolt` binary to instrument the binary/library at the given `path` with BOLT.
5
5
/// When the instrumented artifact is executed, it will generate BOLT profiles into
6
6
/// `/tmp/prof.fdata.<pid>.fdata`.
7
- pub fn instrument_with_bolt_inplace ( path : & Path ) {
7
+ /// Returns a path to the instrumented artifact, created in a temporary directory.
8
+ pub fn instrument_with_bolt ( path : & Path ) -> PathBuf {
8
9
let dir = std:: env:: temp_dir ( ) ;
9
- let instrumented_path = dir. join ( "instrumented.so" ) ;
10
+ let instrumented_path = dir. join ( path . file_name ( ) . unwrap ( ) ) ;
10
11
11
12
let status = Command :: new ( "llvm-bolt" )
12
13
. arg ( "-instrument" )
@@ -21,19 +22,19 @@ pub fn instrument_with_bolt_inplace(path: &Path) {
21
22
if !status. success ( ) {
22
23
panic ! ( "Could not instrument {} with BOLT, exit code {:?}" , path. display( ) , status. code( ) ) ;
23
24
}
24
-
25
- std:: fs:: copy ( & instrumented_path, path) . expect ( "Cannot copy instrumented artifact" ) ;
26
- std:: fs:: remove_file ( instrumented_path) . expect ( "Cannot delete instrumented artifact" ) ;
25
+ instrumented_path
27
26
}
28
27
29
28
/// Uses the `llvm-bolt` binary to optimize the binary/library at the given `path` with BOLT,
30
29
/// using merged profiles from `profile_path`.
31
30
///
32
31
/// The recorded profiles have to be merged using the `merge-fdata` tool from LLVM and the merged
33
32
/// profile path should be then passed to this function.
34
- pub fn optimize_library_with_bolt_inplace ( path : & Path , profile_path : & Path ) {
33
+ ///
34
+ /// Returns a path to the optimized artifact, created in a temporary directory.
35
+ pub fn optimize_with_bolt ( path : & Path , profile_path : & Path ) -> PathBuf {
35
36
let dir = std:: env:: temp_dir ( ) ;
36
- let optimized_path = dir. join ( "optimized.so" ) ;
37
+ let optimized_path = dir. join ( path . file_name ( ) . unwrap ( ) ) ;
37
38
38
39
let status = Command :: new ( "llvm-bolt" )
39
40
. arg ( & path)
@@ -65,7 +66,5 @@ pub fn optimize_library_with_bolt_inplace(path: &Path, profile_path: &Path) {
65
66
if !status. success ( ) {
66
67
panic ! ( "Could not optimize {} with BOLT, exit code {:?}" , path. display( ) , status. code( ) ) ;
67
68
}
68
-
69
- std:: fs:: copy ( & optimized_path, path) . expect ( "Cannot copy optimized artifact" ) ;
70
- std:: fs:: remove_file ( optimized_path) . expect ( "Cannot delete optimized artifact" ) ;
69
+ optimized_path
71
70
}
0 commit comments