servo: Merge #11119 - Make --profile-trace-path work without -p (from mbrubeck:trace-path); r=jdm
authorMatt Brubeck <mbrubeck@limpet.net>
Tue, 10 May 2016 16:00:45 -0700
changeset 338761 6b339a7f5114400f3eb9fe290856a93a9ad7e3b6
parent 338760 4403e83bbb8e763bb0f0e8509051a286eb73ec41
child 338762 05d2c33b8667e2e1bcad44660a10d097ef86dfd2
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
servo: Merge #11119 - Make --profile-trace-path work without -p (from mbrubeck:trace-path); r=jdm Currently `--profile-trace-path` has no effect if `-p` isn't also passed, because the time profiler doesn't start. Source-Repo: https://github.com/servo/servo Source-Revision: 8fab68d6a9543248b1e798dfe53036e33654e8cd
servo/components/profile/time.rs
--- a/servo/components/profile/time.rs
+++ b/servo/components/profile/time.rs
@@ -130,49 +130,50 @@ pub struct Profiler {
     buckets: ProfilerBuckets,
     pub last_msg: Option<ProfilerMsg>,
     trace: Option<TraceDump>,
 }
 
 impl Profiler {
     pub fn create(period: Option<f64>, file_path: Option<String>) -> ProfilerChan {
         let (chan, port) = ipc::channel().unwrap();
-        match period {
-            Some(period) => {
-                let chan = chan.clone();
-                spawn_named("Time profiler timer".to_owned(), move || {
-                    loop {
-                        thread::sleep(duration_from_seconds(period));
-                        if chan.send(ProfilerMsg::Print).is_err() {
-                            break;
-                        }
+        if let Some(period) = period {
+            let chan = chan.clone();
+            spawn_named("Time profiler timer".to_owned(), move || {
+                loop {
+                    thread::sleep(duration_from_seconds(period));
+                    if chan.send(ProfilerMsg::Print).is_err() {
+                        break;
                     }
-                });
-                // Spawn the time profiler.
-                spawn_named("Time profiler".to_owned(), move || {
-                    let trace = file_path.as_ref()
-                        .map(path::Path::new)
-                        .map(fs::File::create)
-                        .map(|res| TraceDump::new(res.unwrap()));
-                    let mut profiler = Profiler::new(port, trace);
-                    profiler.start();
-                });
-            }
-            None => {
-                // No-op to handle messages when the time profiler is inactive.
-                spawn_named("Time profiler".to_owned(), move || {
-                    loop {
-                        match port.recv() {
-                            Err(_) | Ok(ProfilerMsg::Exit) => break,
-                            _ => {}
-                        }
+                }
+            });
+        }
+
+        if period.is_some() || file_path.is_some() {
+            // Spawn the time profiler.
+            spawn_named("Time profiler".to_owned(), move || {
+                let trace = file_path.as_ref()
+                    .map(path::Path::new)
+                    .map(fs::File::create)
+                    .map(|res| TraceDump::new(res.unwrap()));
+                let mut profiler = Profiler::new(port, trace);
+                profiler.start();
+            });
+        } else {
+            // No-op to handle messages when the time profiler is inactive.
+            spawn_named("Time profiler".to_owned(), move || {
+                loop {
+                    match port.recv() {
+                        Err(_) | Ok(ProfilerMsg::Exit) => break,
+                        _ => {}
                     }
-                });
-            }
+                }
+            });
         }
+
         heartbeats::init();
         let profiler_chan = ProfilerChan(chan);
 
         // only spawn the application-level profiler thread if its heartbeat is enabled
         let run_ap_thread = || {
             heartbeats::is_heartbeat_enabled(&ProfilerCategory::ApplicationHeartbeat)
         };
         if run_ap_thread() {