File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1
1
//! Chrome trace output.
2
2
3
3
use std:: fs:: File ;
4
+ use std:: future:: Future ;
4
5
use std:: io:: { BufWriter , Write } ;
5
6
use std:: time:: Instant ;
6
7
@@ -56,6 +57,14 @@ impl Trace {
56
57
result
57
58
}
58
59
60
+ async fn async_scope < T > ( & mut self , name : & str , f : impl Future < Output = T > ) -> T {
61
+ let start = Instant :: now ( ) ;
62
+ let result = f. await ;
63
+ let end = Instant :: now ( ) ;
64
+ self . write_complete ( name, 0 , start, end) ;
65
+ result
66
+ }
67
+
59
68
/*
60
69
These functions were useful when developing, but are currently unused.
61
70
@@ -121,6 +130,18 @@ pub fn scope<T>(name: &'static str, f: impl FnOnce() -> T) -> T {
121
130
}
122
131
}
123
132
133
+ #[ inline]
134
+ #[ allow( static_mut_refs) ]
135
+ pub async fn async_scope < T > ( name : & ' static str , f : impl Future < Output = T > ) -> T {
136
+ // Safety: accessing global mut, not threadsafe.
137
+ unsafe {
138
+ match & mut TRACE {
139
+ None => f. await ,
140
+ Some ( t) => t. async_scope ( name, f) . await ,
141
+ }
142
+ }
143
+ }
144
+
124
145
pub fn close ( ) {
125
146
if_enabled ( |t| t. close ( ) ) ;
126
147
}
You can’t perform that action at this time.
0 commit comments