This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +37
-21
lines changed Expand file tree Collapse file tree 4 files changed +37
-21
lines changed Original file line number Diff line number Diff line change @@ -172,27 +172,6 @@ pub(crate) fn compile_fn(
172
172
cx. profiler . generic_activity ( "define function" ) . run ( || {
173
173
context. want_disasm = cx. should_write_ir ;
174
174
module. define_function ( codegened_func. func_id , context) . unwrap ( ) ;
175
-
176
- if cx. profiler . enabled ( ) {
177
- let mut recording_args = false ;
178
- cx. profiler
179
- . generic_activity_with_arg_recorder (
180
- "define function (clif pass timings)" ,
181
- |recorder| {
182
- let pass_times = cranelift_codegen:: timing:: take_current ( ) ;
183
- // Replace newlines with | as measureme doesn't allow control characters like
184
- // newlines inside strings.
185
- recorder. record_arg ( format ! ( "{}" , pass_times) . replace ( '\n' , " | " ) ) ;
186
- recording_args = true ;
187
- } ,
188
- )
189
- . run ( || {
190
- if recording_args {
191
- // Wait a tiny bit to ensure chrome's profiler doesn't hide the event
192
- std:: thread:: sleep ( std:: time:: Duration :: from_nanos ( 2 ) )
193
- }
194
- } ) ;
195
- }
196
175
} ) ;
197
176
198
177
if cx. should_write_ir {
Original file line number Diff line number Diff line change @@ -324,6 +324,10 @@ fn module_codegen(
324
324
OngoingModuleCodegen :: Async ( std:: thread:: spawn ( move || {
325
325
cx. profiler . clone ( ) . verbose_generic_activity_with_arg ( "compile functions" , & * cgu_name) . run (
326
326
|| {
327
+ cranelift_codegen:: timing:: set_thread_profiler ( Box :: new ( super :: MeasuremeProfiler (
328
+ cx. profiler . clone ( ) ,
329
+ ) ) ) ;
330
+
327
331
let mut cached_context = Context :: new ( ) ;
328
332
for codegened_func in codegened_functions {
329
333
crate :: base:: compile_fn (
Original file line number Diff line number Diff line change @@ -224,6 +224,10 @@ pub(crate) fn codegen_and_compile_fn<'tcx>(
224
224
module : & mut dyn Module ,
225
225
instance : Instance < ' tcx > ,
226
226
) {
227
+ cranelift_codegen:: timing:: set_thread_profiler ( Box :: new ( super :: MeasuremeProfiler (
228
+ cx. profiler . clone ( ) ,
229
+ ) ) ) ;
230
+
227
231
tcx. prof . generic_activity ( "codegen and compile fn" ) . run ( || {
228
232
let _inst_guard =
229
233
crate :: PrintOnPanic ( || format ! ( "{:?} {}" , instance, tcx. symbol_name( instance) . name) ) ;
Original file line number Diff line number Diff line change 4
4
//! [`codegen_fn`]: crate::base::codegen_fn
5
5
//! [`codegen_static`]: crate::constant::codegen_static
6
6
7
+ use rustc_data_structures:: profiling:: SelfProfilerRef ;
7
8
use rustc_middle:: mir:: mono:: { Linkage as RLinkage , MonoItem , Visibility } ;
8
9
9
10
use crate :: prelude:: * ;
@@ -39,3 +40,31 @@ fn predefine_mono_items<'tcx>(
39
40
}
40
41
} ) ;
41
42
}
43
+
44
+ struct MeasuremeProfiler ( SelfProfilerRef ) ;
45
+
46
+ struct TimingGuard {
47
+ profiler : std:: mem:: ManuallyDrop < SelfProfilerRef > ,
48
+ inner : Option < rustc_data_structures:: profiling:: TimingGuard < ' static > > ,
49
+ }
50
+
51
+ impl Drop for TimingGuard {
52
+ fn drop ( & mut self ) {
53
+ self . inner . take ( ) ;
54
+ unsafe {
55
+ std:: mem:: ManuallyDrop :: drop ( & mut self . profiler ) ;
56
+ }
57
+ }
58
+ }
59
+
60
+ impl cranelift_codegen:: timing:: Profiler for MeasuremeProfiler {
61
+ fn start_pass ( & self , pass : cranelift_codegen:: timing:: Pass ) -> Box < dyn std:: any:: Any > {
62
+ let mut timing_guard =
63
+ TimingGuard { profiler : std:: mem:: ManuallyDrop :: new ( self . 0 . clone ( ) ) , inner : None } ;
64
+ timing_guard. inner = Some (
65
+ unsafe { & * ( & * timing_guard. profiler as & SelfProfilerRef as * const SelfProfilerRef ) }
66
+ . generic_activity ( pass. description ( ) ) ,
67
+ ) ;
68
+ Box :: new ( timing_guard)
69
+ }
70
+ }
You can’t perform that action at this time.
0 commit comments