Commit 1c58f65e authored by HobeXD's avatar HobeXD Committed by Commit Bot

[Video Capture, Chrome OS]: add camera profiling tool

I add a tracing tool in ChromeOS, and this is the Chrome side code to
interact with the hal_adapter in ChromeOS through mojo. Also add the
tracing of the camera capture request and get result.

CQ-DEPEND=CL:1158095
BUG=b:109714458
TEST=Open about://tracing in Chrome, click Record, and choose CrosCamera.
Open any camera app, and close it. Click Stop button in Chrome, and there
will have some events show on the UI. In the process of camera service, and
if you open the camera in chrome the browser process will also have some
events.
TEST=Pass capture_unittests

Change-Id: I1ae67b8ca49d63679228eea5b579818b0b3d3686
Reviewed-on: https://chromium-review.googlesource.com/1158106
Commit-Queue: Jyun-jhe Chou <hobexd@google.com>
Reviewed-by: default avatarRicky Liang <jcliang@chromium.org>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589120}
parent 37ae5d1a
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/numerics/ranges.h" #include "base/numerics/ranges.h"
#include "base/posix/safe_strerror.h" #include "base/posix/safe_strerror.h"
#include "base/trace_event/trace_event.h"
#include "media/base/bind_to_current_loop.h" #include "media/base/bind_to_current_loop.h"
#include "media/capture/mojom/image_capture_types.h" #include "media/capture/mojom/image_capture_types.h"
#include "media/capture/video/blob_utils.h" #include "media/capture/video/blob_utils.h"
...@@ -619,6 +620,10 @@ void CameraDeviceDelegate::ProcessCaptureRequest( ...@@ -619,6 +620,10 @@ void CameraDeviceDelegate::ProcessCaptureRequest(
cros::mojom::Camera3CaptureRequestPtr request, cros::mojom::Camera3CaptureRequestPtr request,
base::OnceCallback<void(int32_t)> callback) { base::OnceCallback<void(int32_t)> callback) {
DCHECK(ipc_task_runner_->BelongsToCurrentThread()); DCHECK(ipc_task_runner_->BelongsToCurrentThread());
for (const auto& output_buffer : request->output_buffers) {
TRACE_EVENT2("camera", "Capture Request", "frame_number",
request->frame_number, "stream_id", output_buffer->stream_id);
}
if (device_context_->GetState() != CameraDeviceContext::State::kCapturing) { if (device_context_->GetState() != CameraDeviceContext::State::kCapturing) {
DCHECK_EQ(device_context_->GetState(), DCHECK_EQ(device_context_->GetState(),
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/trace_event/trace_event.h"
#include "mojo/public/cpp/platform/named_platform_channel.h" #include "mojo/public/cpp/platform/named_platform_channel.h"
#include "mojo/public/cpp/platform/platform_channel.h" #include "mojo/public/cpp/platform/platform_channel.h"
#include "mojo/public/cpp/platform/socket_utils_posix.h" #include "mojo/public/cpp/platform/socket_utils_posix.h"
...@@ -155,7 +156,11 @@ bool CameraHalDispatcherImpl::IsStarted() { ...@@ -155,7 +156,11 @@ bool CameraHalDispatcherImpl::IsStarted() {
CameraHalDispatcherImpl::CameraHalDispatcherImpl() CameraHalDispatcherImpl::CameraHalDispatcherImpl()
: proxy_thread_("CameraProxyThread"), : proxy_thread_("CameraProxyThread"),
blocking_io_thread_("CameraBlockingIOThread") {} blocking_io_thread_("CameraBlockingIOThread") {
// This event is for adding camera category to categories list.
TRACE_EVENT0("camera", "CameraHalDispatcherImpl");
base::trace_event::TraceLog::GetInstance()->AddEnabledStateObserver(this);
}
CameraHalDispatcherImpl::~CameraHalDispatcherImpl() { CameraHalDispatcherImpl::~CameraHalDispatcherImpl() {
VLOG(1) << "Stopping CameraHalDispatcherImpl..."; VLOG(1) << "Stopping CameraHalDispatcherImpl...";
...@@ -166,6 +171,7 @@ CameraHalDispatcherImpl::~CameraHalDispatcherImpl() { ...@@ -166,6 +171,7 @@ CameraHalDispatcherImpl::~CameraHalDispatcherImpl() {
proxy_thread_.Stop(); proxy_thread_.Stop();
} }
blocking_io_thread_.Stop(); blocking_io_thread_.Stop();
base::trace_event::TraceLog::GetInstance()->RemoveEnabledStateObserver(this);
VLOG(1) << "CameraHalDispatcherImpl stopped"; VLOG(1) << "CameraHalDispatcherImpl stopped";
} }
...@@ -212,6 +218,20 @@ void CameraHalDispatcherImpl::GetJpegEncodeAccelerator( ...@@ -212,6 +218,20 @@ void CameraHalDispatcherImpl::GetJpegEncodeAccelerator(
jea_factory_.Run(std::move(jea_request)); jea_factory_.Run(std::move(jea_request));
} }
void CameraHalDispatcherImpl::OnTraceLogEnabled() {
proxy_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&CameraHalDispatcherImpl::OnTraceLogEnabledOnProxyThread,
base::Unretained(this)));
}
void CameraHalDispatcherImpl::OnTraceLogDisabled() {
proxy_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&CameraHalDispatcherImpl::OnTraceLogDisabledOnProxyThread,
base::Unretained(this)));
}
void CameraHalDispatcherImpl::CreateSocket(base::WaitableEvent* started) { void CameraHalDispatcherImpl::CreateSocket(base::WaitableEvent* started) {
DCHECK(blocking_io_task_runner_->BelongsToCurrentThread()); DCHECK(blocking_io_task_runner_->BelongsToCurrentThread());
...@@ -381,4 +401,24 @@ void CameraHalDispatcherImpl::StopOnProxyThread() { ...@@ -381,4 +401,24 @@ void CameraHalDispatcherImpl::StopOnProxyThread() {
binding_set_.CloseAllBindings(); binding_set_.CloseAllBindings();
} }
void CameraHalDispatcherImpl::OnTraceLogEnabledOnProxyThread() {
DCHECK(proxy_task_runner_->BelongsToCurrentThread());
if (!camera_hal_server_) {
return;
}
bool camera_event_enabled = false;
TRACE_EVENT_CATEGORY_GROUP_ENABLED("camera", &camera_event_enabled);
if (camera_event_enabled) {
camera_hal_server_->SetTracingEnabled(true);
}
}
void CameraHalDispatcherImpl::OnTraceLogDisabledOnProxyThread() {
DCHECK(proxy_task_runner_->BelongsToCurrentThread());
if (!camera_hal_server_) {
return;
}
camera_hal_server_->SetTracingEnabled(false);
}
} // namespace media } // namespace media
...@@ -44,7 +44,8 @@ class CAPTURE_EXPORT CameraClientObserver { ...@@ -44,7 +44,8 @@ class CAPTURE_EXPORT CameraClientObserver {
// For general documentation about the CameraHalDispater Mojo interface see the // For general documentation about the CameraHalDispater Mojo interface see the
// comments in mojo/cros_camera_service.mojom. // comments in mojo/cros_camera_service.mojom.
class CAPTURE_EXPORT CameraHalDispatcherImpl final class CAPTURE_EXPORT CameraHalDispatcherImpl final
: public cros::mojom::CameraHalDispatcher { : public cros::mojom::CameraHalDispatcher,
public base::trace_event::TraceLog::EnabledStateObserver {
public: public:
static CameraHalDispatcherImpl* GetInstance(); static CameraHalDispatcherImpl* GetInstance();
...@@ -63,6 +64,10 @@ class CAPTURE_EXPORT CameraHalDispatcherImpl final ...@@ -63,6 +64,10 @@ class CAPTURE_EXPORT CameraHalDispatcherImpl final
void GetJpegEncodeAccelerator( void GetJpegEncodeAccelerator(
media::mojom::JpegEncodeAcceleratorRequest jea_request) final; media::mojom::JpegEncodeAcceleratorRequest jea_request) final;
// base::trace_event::TraceLog::EnabledStateObserver implementation.
void OnTraceLogEnabled() final;
void OnTraceLogDisabled() final;
private: private:
friend struct base::DefaultSingletonTraits<CameraHalDispatcherImpl>; friend struct base::DefaultSingletonTraits<CameraHalDispatcherImpl>;
// Allow the test to construct the class directly. // Allow the test to construct the class directly.
...@@ -95,6 +100,9 @@ class CAPTURE_EXPORT CameraHalDispatcherImpl final ...@@ -95,6 +100,9 @@ class CAPTURE_EXPORT CameraHalDispatcherImpl final
void StopOnProxyThread(); void StopOnProxyThread();
void OnTraceLogEnabledOnProxyThread();
void OnTraceLogDisabledOnProxyThread();
base::ScopedFD proxy_fd_; base::ScopedFD proxy_fd_;
base::ScopedFD cancel_pipe_; base::ScopedFD cancel_pipe_;
......
...@@ -34,6 +34,8 @@ class MockCameraHalServer : public cros::mojom::CameraHalServer { ...@@ -34,6 +34,8 @@ class MockCameraHalServer : public cros::mojom::CameraHalServer {
MOCK_METHOD1(DoCreateChannel, MOCK_METHOD1(DoCreateChannel,
void(cros::mojom::CameraModuleRequest& camera_module_request)); void(cros::mojom::CameraModuleRequest& camera_module_request));
MOCK_METHOD1(SetTracingEnabled, void(bool enabled));
cros::mojom::CameraHalServerPtrInfo GetInterfacePtrInfo() { cros::mojom::CameraHalServerPtrInfo GetInterfacePtrInfo() {
cros::mojom::CameraHalServerPtrInfo camera_hal_server_ptr_info; cros::mojom::CameraHalServerPtrInfo camera_hal_server_ptr_info;
cros::mojom::CameraHalServerRequest camera_hal_server_request = cros::mojom::CameraHalServerRequest camera_hal_server_request =
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Next min version: 3 // Next min version: 4
module cros.mojom; module cros.mojom;
...@@ -38,13 +38,17 @@ interface CameraHalDispatcher { ...@@ -38,13 +38,17 @@ interface CameraHalDispatcher {
// The CrOS camera HAL v3 Mojo server. // The CrOS camera HAL v3 Mojo server.
// //
// Next method ID: 1 // Next method ID: 2
interface CameraHalServer { interface CameraHalServer {
// A caller calls CreateChannel to create a new Mojo channel to the camera // A caller calls CreateChannel to create a new Mojo channel to the camera
// HAL v3 adapter. Upon successfully binding of |camera_module_request|, the // HAL v3 adapter. Upon successfully binding of |camera_module_request|, the
// caller will have a established Mojo channel to the camera HAL v3 adapter // caller will have a established Mojo channel to the camera HAL v3 adapter
// process. // process.
CreateChannel@0(CameraModule& camera_module_request); CreateChannel@0(CameraModule& camera_module_request);
// Enable or disable tracing.
[MinVersion=3]
SetTracingEnabled@1(bool enabled);
}; };
// The CrOS camera HAL v3 Mojo client. // The CrOS camera HAL v3 Mojo client.
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include "base/posix/safe_strerror.h" #include "base/posix/safe_strerror.h"
#include "base/trace_event/trace_event.h"
#include "media/capture/video/chromeos/camera_buffer_factory.h" #include "media/capture/video/chromeos/camera_buffer_factory.h"
#include "media/capture/video/chromeos/camera_device_context.h" #include "media/capture/video/chromeos/camera_device_context.h"
#include "media/capture/video/chromeos/camera_metadata_utils.h" #include "media/capture/video/chromeos/camera_metadata_utils.h"
...@@ -579,6 +580,7 @@ void StreamBufferManager::ProcessCaptureResult( ...@@ -579,6 +580,7 @@ void StreamBufferManager::ProcessCaptureResult(
} }
for (const auto& iter : stream_context_) { for (const auto& iter : stream_context_) {
TRACE_EVENT1("camera", "Capture Result", "frame_number", frame_number);
SubmitCaptureResultIfComplete(frame_number, iter.first); SubmitCaptureResultIfComplete(frame_number, iter.first);
} }
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/location.h" #include "base/location.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "base/trace_event/trace_event.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "media/base/bind_to_current_loop.h" #include "media/base/bind_to_current_loop.h"
#include "media/capture/video/chromeos/camera_device_context.h" #include "media/capture/video/chromeos/camera_device_context.h"
...@@ -61,7 +62,7 @@ void VideoCaptureDeviceChromeOSHalv3::AllocateAndStart( ...@@ -61,7 +62,7 @@ void VideoCaptureDeviceChromeOSHalv3::AllocateAndStart(
std::unique_ptr<Client> client) { std::unique_ptr<Client> client) {
DCHECK(capture_task_runner_->BelongsToCurrentThread()); DCHECK(capture_task_runner_->BelongsToCurrentThread());
DCHECK(!camera_device_delegate_); DCHECK(!camera_device_delegate_);
TRACE_EVENT0("camera", "Start Device");
if (!camera_device_ipc_thread_.Start()) { if (!camera_device_ipc_thread_.Start()) {
std::string error_msg = "Failed to start device thread"; std::string error_msg = "Failed to start device thread";
LOG(ERROR) << error_msg; LOG(ERROR) << error_msg;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment