Bug 1476405: Part 6 - Register AudioIPC threads with the profiler. r=kinetik
☠☠ backed out by 77b07565d021 ☠ ☠
authorKris Maglione <maglione.k@gmail.com>
Wed, 18 Jul 2018 23:29:16 -0700
changeset 483795 e0a021b27d2c66d46ba973d66d1360678411da26
parent 483794 771288dbf8529d45786b42a21dc66b180bb674ca
child 483796 ad1674e9152da31151ab9f9f099f83ca4ff2d832
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1476405
milestone63.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 1476405: Part 6 - Register AudioIPC threads with the profiler. r=kinetik Presumably the Rust portion of this will have to land externally first and then be imported, but I have no idea how or where to submit it. MozReview-Commit-ID: 2gzQbRKxaZ9
dom/media/CubebUtils.cpp
media/audioipc/client/src/context.rs
media/audioipc/client/src/lib.rs
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -54,16 +54,17 @@
 #endif
 
 extern "C" {
 
 struct AudioIpcInitParams {
   int mServerConnection;
   size_t mPoolSize;
   size_t mStackSize;
+  void (*mThreadCreateCallback)(const char*);
 };
 
 // These functions are provided by audioipc-server crate
 extern void* audioipc_server_start();
 extern mozilla::ipc::FileDescriptor::PlatformHandleType audioipc_server_new_client(void*);
 extern void audioipc_server_stop(void*);
 // These functions are provided by audioipc-client crate
 extern int audioipc_client_init(cubeb**, const char*, const AudioIpcInitParams*);
@@ -425,16 +426,19 @@ cubeb* GetCubebContextUnlocked()
     } else {
       MOZ_DIAGNOSTIC_ASSERT(sIPCConnection);
     }
 
     AudioIpcInitParams initParams;
     initParams.mPoolSize = sAudioIPCPoolSize;
     initParams.mStackSize = sAudioIPCStackSize;
     initParams.mServerConnection = sIPCConnection->ClonePlatformHandle().release();
+    initParams.mThreadCreateCallback = [](const char* aName) {
+      PROFILER_REGISTER_THREAD(aName);
+    };
 
     MOZ_LOG(gCubebLog, LogLevel::Debug, ("%s: %d", PREF_AUDIOIPC_POOL_SIZE, (int) initParams.mPoolSize));
     MOZ_LOG(gCubebLog, LogLevel::Debug, ("%s: %d", PREF_AUDIOIPC_STACK_SIZE, (int) initParams.mStackSize));
 
     rv = audioipc_client_init(&sCubebContext, sBrandName, &initParams);
   } else {
     rv = cubeb_init(&sCubebContext, sBrandName, sCubebBackendName.get());
   }
--- a/media/audioipc/client/src/context.rs
+++ b/media/audioipc/client/src/context.rs
@@ -15,16 +15,17 @@ use futures::Future;
 use futures_cpupool::{self, CpuPool};
 use libc;
 use std::{fmt, io, mem, ptr};
 use std::ffi::{CStr, CString};
 use std::os::raw::c_void;
 use std::os::unix::io::FromRawFd;
 use std::os::unix::net;
 use std::sync::mpsc;
+use std::thread;
 use stream;
 use tokio_core::reactor::{Handle, Remote};
 use tokio_uds::UnixStream;
 
 struct CubebClient;
 
 impl rpc::Client for CubebClient {
     type Request = ServerMessage;
@@ -94,41 +95,55 @@ impl ContextOps for ClientContext {
             let _ = tx_rpc.send(rpc);
             Some(())
         }
 
         assert_not_in_callback();
 
         let (tx_rpc, rx_rpc) = mpsc::channel();
 
+        let params = CPUPOOL_INIT_PARAMS.with(|p| {
+            p.replace(None).unwrap()
+        });
+
+        let thread_create_callback = params.thread_create_callback;
+
+        let register_thread = move || {
+            if let Some(func) = thread_create_callback {
+                let thr = thread::current();
+                let name = CString::new(thr.name().unwrap()).unwrap();
+                func(name.as_ptr());
+            }
+        };
+
         let core = t!(core::spawn_thread("AudioIPC Client RPC", move || {
             let handle = core::handle();
 
+            register_thread();
+
             open_server_stream()
                 .ok()
                 .and_then(|stream| UnixStream::from_stream(stream, &handle).ok())
                 .and_then(|stream| bind_and_send_client(stream, &handle, &tx_rpc))
                 .ok_or_else(|| {
                     io::Error::new(
                         io::ErrorKind::Other,
                         "Failed to open stream and create rpc.",
                     )
                 })
         }));
 
         let rpc = t!(rx_rpc.recv());
 
-        let cpupool = CPUPOOL_INIT_PARAMS.with(|p| {
-            let params = p.replace(None).unwrap();
-            futures_cpupool::Builder::new()
+        let cpupool = futures_cpupool::Builder::new()
                 .name_prefix("AudioIPC")
+                .after_start(register_thread)
                 .pool_size(params.pool_size)
                 .stack_size(params.stack_size)
-                .create()
-        });
+                .create();
 
         let ctx = Box::new(ClientContext {
             _ops: &CLIENT_OPS as *const _,
             rpc: rpc,
             core: core,
             cpu_pool: cpupool,
         });
         Ok(unsafe { Context::from_ptr(Box::into_raw(ctx) as *mut _) })
--- a/media/audioipc/client/src/lib.rs
+++ b/media/audioipc/client/src/lib.rs
@@ -32,29 +32,32 @@ thread_local!(static IN_CALLBACK: std::c
 thread_local!(static CPUPOOL_INIT_PARAMS: InitParamsTls = std::cell::RefCell::new(None));
 
 #[repr(C)]
 #[derive(Clone, Copy, Debug)]
 pub struct AudioIpcInitParams {
     pub server_connection: c_int,
     pub pool_size: usize,
     pub stack_size: usize,
+    pub thread_create_callback: Option<extern "C" fn(*const ::std::os::raw::c_char)>,
 }
 
 #[derive(Clone, Copy, Debug)]
 struct CpuPoolInitParams {
     pub pool_size: usize,
     pub stack_size: usize,
+    pub thread_create_callback: Option<extern "C" fn(*const ::std::os::raw::c_char)>,
 }
 
 impl CpuPoolInitParams {
     pub fn init_with(params: &AudioIpcInitParams) -> Self {
         CpuPoolInitParams {
             pool_size: params.pool_size,
             stack_size: params.stack_size,
+            thread_create_callback: params.thread_create_callback,
         }
     }
 }
 
 fn set_in_callback(in_callback: bool) {
     IN_CALLBACK.with(|b| {
         assert_eq!(*b.borrow(), !in_callback);
         *b.borrow_mut() = in_callback;