@@ -64,9 +64,7 @@ struct StackFrame {
64
64
}
65
65
66
66
fn total_duration ( traces : & [ trace:: Rec ] ) -> Duration {
67
- let mut sum : Duration = Duration :: new ( 0 , 0 ) ;
68
- for t in traces. iter ( ) { sum += t. dur_total ; }
69
- return sum
67
+ Duration :: new ( 0 , 0 ) + traces. iter ( ) . map ( |t| t. dur_total ) . sum ( )
70
68
}
71
69
72
70
// profiling thread; retains state (in local variables) and dump traces, upon request.
@@ -93,50 +91,48 @@ fn profile_queries_thread(r: Receiver<ProfileQueriesMsg>) {
93
91
ProfileQueriesMsg :: Dump ( params) => {
94
92
assert ! ( stack. is_empty( ) ) ;
95
93
assert ! ( frame. parse_st == ParseState :: Clear ) ;
96
- {
97
- // write log of all messages
98
- if params. dump_profq_msg_log {
99
- let mut log_file =
100
- File :: create ( format ! ( "{}.log.txt" , params. path) ) . unwrap ( ) ;
101
- for m in profq_msgs. iter ( ) {
102
- writeln ! ( & mut log_file, "{:?}" , m) . unwrap ( )
103
- } ;
104
- }
105
94
106
- // write HTML file, and counts file
107
- let html_path = format ! ( "{}.html" , params. path) ;
108
- let mut html_file = File :: create ( & html_path) . unwrap ( ) ;
95
+ // write log of all messages
96
+ if params. dump_profq_msg_log {
97
+ let mut log_file =
98
+ File :: create ( format ! ( "{}.log.txt" , params. path) ) . unwrap ( ) ;
99
+ for m in profq_msgs. iter ( ) {
100
+ writeln ! ( & mut log_file, "{:?}" , m) . unwrap ( )
101
+ } ;
102
+ }
109
103
110
- let counts_path = format ! ( "{}.counts.txt" , params. path) ;
111
- let mut counts_file = File :: create ( & counts_path) . unwrap ( ) ;
104
+ // write HTML file, and counts file
105
+ let html_path = format ! ( "{}.html" , params. path) ;
106
+ let mut html_file = File :: create ( & html_path) . unwrap ( ) ;
112
107
113
- writeln ! ( html_file,
114
- "<html>\n <head>\n <link rel=\" stylesheet\" type=\" text/css\" href=\" {}\" >" ,
115
- "profile_queries.css" ) . unwrap ( ) ;
116
- writeln ! ( html_file, "<style>" ) . unwrap ( ) ;
117
- trace:: write_style ( & mut html_file) ;
118
- writeln ! ( html_file, "</style>\n </head>\n <body>" ) . unwrap ( ) ;
119
- trace:: write_traces ( & mut html_file, & mut counts_file, & frame. traces ) ;
120
- writeln ! ( html_file, "</body>\n </html>" ) . unwrap ( ) ;
108
+ let counts_path = format ! ( "{}.counts.txt" , params. path) ;
109
+ let mut counts_file = File :: create ( & counts_path) . unwrap ( ) ;
121
110
122
- let ack_path = format ! ( "{}.ack" , params. path) ;
123
- let ack_file = File :: create ( & ack_path) . unwrap ( ) ;
124
- drop ( ack_file) ;
111
+ writeln ! ( html_file,
112
+ "<html>\n <head>\n <link rel=\" stylesheet\" type=\" text/css\" href=\" {}\" >" ,
113
+ "profile_queries.css" ) . unwrap ( ) ;
114
+ writeln ! ( html_file, "<style>" ) . unwrap ( ) ;
115
+ trace:: write_style ( & mut html_file) ;
116
+ writeln ! ( html_file, "</style>\n </head>\n <body>" ) . unwrap ( ) ;
117
+ trace:: write_traces ( & mut html_file, & mut counts_file, & frame. traces ) ;
118
+ writeln ! ( html_file, "</body>\n </html>" ) . unwrap ( ) ;
125
119
126
- // Tell main thread that we are done, e.g., so it can exit
127
- params. ack . send ( ( ) ) . unwrap ( ) ;
128
- }
129
- continue
120
+ let ack_path = format ! ( "{}.ack" , params. path) ;
121
+ let ack_file = File :: create ( & ack_path) . unwrap ( ) ;
122
+ drop ( ack_file) ;
123
+
124
+ // Tell main thread that we are done, e.g., so it can exit
125
+ params. ack . send ( ( ) ) . unwrap ( ) ;
130
126
}
131
127
// Actual query message:
132
128
msg => {
133
129
// Record msg in our log
134
130
profq_msgs. push ( msg. clone ( ) ) ;
135
131
// Respond to the message, knowing that we've already handled Halt and Dump, above.
136
132
match ( frame. parse_st . clone ( ) , msg) {
137
- ( _, ProfileQueriesMsg :: Halt ) => unreachable ! ( ) ,
138
- ( _ , ProfileQueriesMsg :: Dump ( _ ) ) => unreachable ! ( ) ,
139
-
133
+ ( _, ProfileQueriesMsg :: Halt ) | ( _ , ProfileQueriesMsg :: Dump ( _ ) ) => {
134
+ unreachable ! ( ) ;
135
+ } ,
140
136
// Parse State: Clear
141
137
( ParseState :: Clear ,
142
138
ProfileQueriesMsg :: QueryBegin ( span, querymsg) ) => {
@@ -163,8 +159,8 @@ fn profile_queries_thread(r: Receiver<ProfileQueriesMsg>) {
163
159
ParseState :: HaveQuery ( q, start) => {
164
160
let duration = start. elapsed ( ) ;
165
161
frame = StackFrame {
166
- parse_st : ParseState :: Clear ,
167
- traces : old_frame. traces
162
+ parse_st : ParseState :: Clear ,
163
+ traces : old_frame. traces
168
164
} ;
169
165
let dur_extent = total_duration ( & provider_extent) ;
170
166
let trace = Rec {
@@ -181,18 +177,16 @@ fn profile_queries_thread(r: Receiver<ProfileQueriesMsg>) {
181
177
}
182
178
}
183
179
} ,
184
-
185
-
186
180
( ParseState :: Clear ,
187
181
ProfileQueriesMsg :: TimeBegin ( msg) ) => {
188
182
let start = Instant :: now ( ) ;
189
183
frame. parse_st = ParseState :: HaveTimeBegin ( msg, start) ;
190
184
stack. push ( frame) ;
191
- frame = StackFrame { parse_st : ParseState :: Clear , traces : vec ! [ ] } ;
185
+ frame = StackFrame { parse_st : ParseState :: Clear , traces : vec ! [ ] } ;
186
+ } ,
187
+ ( _, ProfileQueriesMsg :: TimeBegin ( _) ) => {
188
+ panic ! ( "parse error; did not expect time begin here" ) ;
192
189
} ,
193
- ( _, ProfileQueriesMsg :: TimeBegin ( _) ) =>
194
- panic ! ( "parse error; did not expect time begin here" ) ,
195
-
196
190
( ParseState :: Clear ,
197
191
ProfileQueriesMsg :: TimeEnd ) => {
198
192
let provider_extent = frame. traces ;
@@ -204,8 +198,8 @@ fn profile_queries_thread(r: Receiver<ProfileQueriesMsg>) {
204
198
ParseState :: HaveTimeBegin ( msg, start) => {
205
199
let duration = start. elapsed ( ) ;
206
200
frame = StackFrame {
207
- parse_st : ParseState :: Clear ,
208
- traces : old_frame. traces
201
+ parse_st : ParseState :: Clear ,
202
+ traces : old_frame. traces
209
203
} ;
210
204
let dur_extent = total_duration ( & provider_extent) ;
211
205
let trace = Rec {
@@ -222,18 +216,19 @@ fn profile_queries_thread(r: Receiver<ProfileQueriesMsg>) {
222
216
}
223
217
}
224
218
} ,
225
- ( _, ProfileQueriesMsg :: TimeEnd ) => { panic ! ( "parse error" ) }
226
-
219
+ ( _, ProfileQueriesMsg :: TimeEnd ) => {
220
+ panic ! ( "parse error" )
221
+ } ,
227
222
( ParseState :: Clear ,
228
223
ProfileQueriesMsg :: TaskBegin ( key) ) => {
229
224
let start = Instant :: now ( ) ;
230
225
frame. parse_st = ParseState :: HaveTaskBegin ( key, start) ;
231
226
stack. push ( frame) ;
232
- frame = StackFrame { parse_st : ParseState :: Clear , traces : vec ! [ ] } ;
227
+ frame = StackFrame { parse_st : ParseState :: Clear , traces : vec ! [ ] } ;
228
+ } ,
229
+ ( _, ProfileQueriesMsg :: TaskBegin ( _) ) => {
230
+ panic ! ( "parse error; did not expect time begin here" ) ;
233
231
} ,
234
- ( _, ProfileQueriesMsg :: TaskBegin ( _) ) =>
235
- panic ! ( "parse error; did not expect time begin here" ) ,
236
-
237
232
( ParseState :: Clear ,
238
233
ProfileQueriesMsg :: TaskEnd ) => {
239
234
let provider_extent = frame. traces ;
@@ -245,8 +240,8 @@ fn profile_queries_thread(r: Receiver<ProfileQueriesMsg>) {
245
240
ParseState :: HaveTaskBegin ( key, start) => {
246
241
let duration = start. elapsed ( ) ;
247
242
frame = StackFrame {
248
- parse_st : ParseState :: Clear ,
249
- traces : old_frame. traces
243
+ parse_st : ParseState :: Clear ,
244
+ traces : old_frame. traces
250
245
} ;
251
246
let dur_extent = total_duration ( & provider_extent) ;
252
247
let trace = Rec {
@@ -263,8 +258,9 @@ fn profile_queries_thread(r: Receiver<ProfileQueriesMsg>) {
263
258
}
264
259
}
265
260
} ,
266
- ( _, ProfileQueriesMsg :: TaskEnd ) => { panic ! ( "parse error" ) }
267
-
261
+ ( _, ProfileQueriesMsg :: TaskEnd ) => {
262
+ panic ! ( "parse error" )
263
+ } ,
268
264
// Parse State: HaveQuery
269
265
( ParseState :: HaveQuery ( q, start) ,
270
266
ProfileQueriesMsg :: CacheHit ) => {
@@ -279,26 +275,25 @@ fn profile_queries_thread(r: Receiver<ProfileQueriesMsg>) {
279
275
frame. traces . push ( trace ) ;
280
276
frame. parse_st = ParseState :: Clear ;
281
277
} ,
282
- ( ParseState :: HaveQuery ( _, _) ,
278
+ ( ParseState :: HaveQuery ( _, _) ,
283
279
ProfileQueriesMsg :: ProviderBegin ) => {
284
280
stack. push ( frame) ;
285
- frame = StackFrame { parse_st : ParseState :: Clear , traces : vec ! [ ] } ;
281
+ frame = StackFrame { parse_st : ParseState :: Clear , traces : vec ! [ ] } ;
286
282
} ,
287
283
288
284
// Parse errors:
289
285
290
- ( ParseState :: HaveQuery ( q, _) ,
286
+ ( ParseState :: HaveQuery ( q, _) ,
291
287
ProfileQueriesMsg :: ProviderEnd ) => {
292
288
panic ! ( "parse error: unexpected ProviderEnd; \
293
289
expected something else to follow BeginQuery for {:?}", q)
294
290
} ,
295
- ( ParseState :: HaveQuery ( q1, _) ,
296
- ProfileQueriesMsg :: QueryBegin ( span2, querymsg2) ) => {
291
+ ( ParseState :: HaveQuery ( q1, _) ,
292
+ ProfileQueriesMsg :: QueryBegin ( span2, querymsg2) ) => {
297
293
panic ! ( "parse error: unexpected QueryBegin; \
298
294
earlier query is unfinished: {:?} and now {:?}",
299
- q1, Query { span: span2, msg: querymsg2} )
295
+ q1, Query { span: span2, msg: querymsg2} )
300
296
} ,
301
-
302
297
( ParseState :: HaveTimeBegin ( _, _) , _) => {
303
298
unreachable ! ( )
304
299
} ,
0 commit comments