Bug 1495462 - Increment the capture path extension until we find a fresh path. r=jrmuizel
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 01 Oct 2018 16:25:28 -0400
changeset 494819 fdbc4d498652975660a6339b45a6e956e1411e82
parent 494818 174c7b3335961531bfe2815c936529f91fa3d05b
child 494820 6c85eac6803827b2301166dc95811f1b66df07dd
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1495462
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1495462 - Increment the capture path extension until we find a fresh path. r=jrmuizel When taking multiple captures, have them get generated into separate folders so that accidentally clobbering (or worse, partially clobbering) a previous capture isn't a problem.
gfx/webrender_bindings/WebRenderAPI.cpp
gfx/webrender_bindings/src/bindings.rs
--- a/gfx/webrender_bindings/WebRenderAPI.cpp
+++ b/gfx/webrender_bindings/WebRenderAPI.cpp
@@ -578,18 +578,16 @@ WebRenderAPI::WaitFlushed()
     task.Wait();
 }
 
 void
 WebRenderAPI::Capture()
 {
   uint8_t bits = 3; //TODO: get from JavaScript
   const char* path = "wr-capture"; //TODO: get from JavaScript
-  const char* border = "--------------------------\n";
-  printf("%s Capturing WR state to: %s\n%s", border, path, border);
   wr_api_capture(mDocHandle, path, bits);
 }
 
 
 void
 TransactionBuilder::Clear()
 {
   wr_resource_updates_clear(mTxn);
--- a/gfx/webrender_bindings/src/bindings.rs
+++ b/gfx/webrender_bindings/src/bindings.rs
@@ -1491,17 +1491,29 @@ pub extern "C" fn wr_api_capture(
     dh: &mut DocumentHandle,
     path: *const c_char,
     bits_raw: u32,
 ) {
     use std::fs::{File, create_dir_all};
     use std::io::Write;
 
     let cstr = unsafe { CStr::from_ptr(path) };
-    let path = PathBuf::from(&*cstr.to_string_lossy());
+    let mut path = PathBuf::from(&*cstr.to_string_lossy());
+
+    // Increment the extension until we find a fresh path
+    while path.is_dir() {
+        let count: u32 = path.extension()
+            .and_then(|x| x.to_str())
+            .and_then(|x| x.parse().ok())
+            .unwrap_or(0);
+        path.set_extension((count + 1).to_string());
+    }
+
+    let border = "--------------------------\n";
+    print!("{} Capturing WR state to: {:?}\n{}", &border, &path, &border);
 
     let _ = create_dir_all(&path);
     match File::create(path.join("wr.txt")) {
         Ok(mut file) => {
             let revision = include_bytes!("../revision.txt");
             file.write(revision).unwrap();
         }
         Err(e) => {