From da35d7a2400d13c04d69e599d1ceab0899e0dfd7 Mon Sep 17 00:00:00 2001 From: zhanhang Date: Sat, 20 May 2023 19:35:53 +0800 Subject: [PATCH] add hilog for pulseaudio Signed-off-by: zhanhang Change-Id: I71cb2afb0a93a5accb08ba9e70291e792e8a4adb --- include/log/audio_log.h | 78 ++++++++++++++++++++++++++++++++ ohosbuild/src/BUILD.gn | 6 ++- ohosbuild/src/pulsecore/BUILD.gn | 5 ++ src/pulsecore/core.c | 4 ++ src/pulsecore/memblock.c | 3 ++ src/pulsecore/protocol-native.c | 8 +++- src/pulsecore/shm.c | 4 ++ 7 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 include/log/audio_log.h diff --git a/include/log/audio_log.h b/include/log/audio_log.h new file mode 100644 index 000000000..981f504f4 --- /dev/null +++ b/include/log/audio_log.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_AUDIO_LOG_H +#define OHOS_AUDIO_LOG_H + +#include + +#include "hilog/log.h" + +#undef LOG_DOMAIN +#undef LOG_TAG +#define LOG_DOMAIN 0xD002B00 +#define LOG_TAG "AudioFramework" + +#define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) + +#ifndef OHOS_DEBUG +#define DECORATOR_HILOG(op, fmt, args...) \ + do { \ + op(LOG_CORE, "[%{public}s] " fmt, FILENAME, ##args); \ + } while (0) +#else +#define DECORATOR_HILOG(op, fmt, args...) \ + do { \ + op(LOG_CORE, "{%s()-%s:%d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); \ + } while (0) +#endif + +#define AUDIO_DEBUG_LOG(fmt, ...) DECORATOR_HILOG(HILOG_DEBUG, fmt, ##__VA_ARGS__) +#define AUDIO_ERR_LOG(fmt, ...) DECORATOR_HILOG(HILOG_ERROR, fmt, ##__VA_ARGS__) +#define AUDIO_WARNING_LOG(fmt, ...) DECORATOR_HILOG(HILOG_WARN, fmt, ##__VA_ARGS__) +#define AUDIO_INFO_LOG(fmt, ...) DECORATOR_HILOG(HILOG_INFO, fmt, ##__VA_ARGS__) +#define AUDIO_FATAL_LOG(fmt, ...) DECORATOR_HILOG(HILOG_FATAL, fmt, ##__VA_ARGS__) + +#define AUDIO_OK 0 +#define AUDIO_INVALID_PARAM (-1) +#define AUDIO_INIT_FAIL (-2) +#define AUDIO_ERR (-3) +#define AUDIO_PERMISSION_DENIED (-4) + +#define CHECK_AND_RETURN_RET_LOG(cond, ret, fmt, ...) \ + do { \ + if (!(cond)) { \ + AUDIO_ERR_LOG(fmt, ##__VA_ARGS__); \ + return ret; \ + } \ + } while (0) + +#define CHECK_AND_RETURN_LOG(cond, fmt, ...) \ + do { \ + if (!(cond)) { \ + AUDIO_ERR_LOG(fmt, ##__VA_ARGS__); \ + return; \ + } \ + } while (0) + +#define CHECK_AND_BREAK_LOG(cond, fmt, ...) \ + do { \ + if (!(cond)) { \ + AUDIO_ERR_LOG(fmt, ##__VA_ARGS__); \ + break; \ + } \ + } while (0) + +#endif // OHOS_AUDIO_LOG_H diff --git a/ohosbuild/src/BUILD.gn b/ohosbuild/src/BUILD.gn index 279557e81..573379927 100644 --- a/ohosbuild/src/BUILD.gn +++ b/ohosbuild/src/BUILD.gn @@ -30,6 +30,7 @@ config("pulsecommon_config") { "$libsndfile_dir/include", "$pulseaudio_dir/src/pulse", "//base/startup/init/interfaces/innerkits/include", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", ] cflags = [ @@ -129,7 +130,10 @@ ohos_shared_library("pulsecommon") { "$libsndfile_build_path:sndfile", ] - external_deps = [ "init:libbegetutil" ] + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "init:libbegetutil", + ] subsystem_name = "multimedia" part_name = "audio_framework" diff --git a/ohosbuild/src/pulsecore/BUILD.gn b/ohosbuild/src/pulsecore/BUILD.gn index 60a472c88..01b79d415 100644 --- a/ohosbuild/src/pulsecore/BUILD.gn +++ b/ohosbuild/src/pulsecore/BUILD.gn @@ -30,6 +30,7 @@ config("pulsecore_config") { "//third_party/glib/glib", "//third_party/glib", "$libsndfile_dir/include", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", ] cflags = [ @@ -116,6 +117,8 @@ ohos_shared_library("pulsecore") { "$pulseaudio_build_path/src:pulsecommon", ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + subsystem_name = "multimedia" part_name = "audio_framework" } @@ -129,6 +132,7 @@ config("modules_internal_lib_config") { "$pulseaudio_dir/src", "$pulseaudio_dir", "$pulseaudio_build_path/src", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", ] cflags = [ @@ -180,6 +184,7 @@ ohos_shared_library("protocol-native") { "$pulseaudio_build_path/src/pulsecore:pulsecore", ] + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] subsystem_name = "multimedia" part_name = "audio_framework" } diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c index c28c5312b..44d48f715 100644 --- a/src/pulsecore/core.c +++ b/src/pulsecore/core.c @@ -39,6 +39,8 @@ #include #include +#include "log/audio_log.h" + #include "core.h" PA_DEFINE_PUBLIC_CLASS(pa_core, pa_msgobject); @@ -62,6 +64,7 @@ static int core_process_msg(pa_msgobject *o, int code, void *userdata, int64_t o static void core_free(pa_object *o); pa_core* pa_core_new(pa_mainloop_api *m, bool shared, bool enable_memfd, size_t shm_size) { + AUDIO_INFO_LOG("start pa_core_new, shared: %{public}d, enable_memfd: %{public}d", shared, enable_memfd); pa_core* c; pa_mempool *pool; pa_mem_type_t type; @@ -72,6 +75,7 @@ pa_core* pa_core_new(pa_mainloop_api *m, bool shared, bool enable_memfd, size_t if (shared) { type = (enable_memfd) ? PA_MEM_TYPE_SHARED_MEMFD : PA_MEM_TYPE_SHARED_POSIX; if (!(pool = pa_mempool_new(type, shm_size, false))) { + pa_log_warn("Failed to allocate %s memory pool. Falling back to a normal memory pool.", pa_mem_type_to_string(type)); shared = false; diff --git a/src/pulsecore/memblock.c b/src/pulsecore/memblock.c index fb83dac57..f20174035 100644 --- a/src/pulsecore/memblock.c +++ b/src/pulsecore/memblock.c @@ -48,6 +48,8 @@ #include #include +#include "log/audio_log.h" + #include "memblock.h" /* We can allocate 64*1024*1024 bytes at maximum. That's 64MB. Please @@ -826,6 +828,7 @@ static void memblock_replace_import(pa_memblock *b) { * TODO-1: Transform the global core mempool to a per-client one * TODO-2: Remove global mempools support */ pa_mempool *pa_mempool_new(pa_mem_type_t type, size_t size, bool per_client) { + AUDIO_INFO_LOG("pa_mempool_new:type %{public}d, size %{public}zu, per_client %{public}d,", type, size, per_client); pa_mempool *p; char t1[PA_BYTES_SNPRINT_MAX], t2[PA_BYTES_SNPRINT_MAX]; const size_t page_size = pa_page_size(); diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index e8559b239..4aac09db6 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -58,6 +58,8 @@ #include #include +#include "log/audio_log.h" + #include "protocol-native.h" /* #define PROTOCOL_NATIVE_DEBUG */ @@ -2468,7 +2470,7 @@ static void setup_srbchannel(pa_native_connection *c, pa_mem_type_t shm_type) { pa_memchunk mc; pa_tagstruct *t; int fdlist[2]; - + AUDIO_INFO_LOG("start setup_srbchannel, shm_type: %{public}d", shm_type); #ifndef HAVE_CREDS pa_log_debug("Disabling srbchannel, reason: No fd passing support"); return; @@ -2556,6 +2558,7 @@ static void command_enable_srbchannel(pa_pdispatch *pd, uint32_t command, uint32 } static void command_auth(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_tagstruct *t, void *userdata) { + AUDIO_INFO_LOG("start command_authd"); pa_native_connection *c = PA_NATIVE_CONNECTION(userdata); const void*cookie; bool memfd_on_remote = false, do_memfd = false; @@ -2696,6 +2699,9 @@ static void command_auth(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_ta } else shm_type = PA_MEM_TYPE_SHARED_POSIX; + AUDIO_INFO_LOG("Memfd possible: %s", pa_yes_no(pa_memfd_is_locally_supported())); + AUDIO_INFO_LOG("Negotiated SHM type: %s", pa_mem_type_to_string(shm_type)); + pa_log_debug("Memfd possible: %s", pa_yes_no(pa_memfd_is_locally_supported())); pa_log_debug("Negotiated SHM type: %s", pa_mem_type_to_string(shm_type)); } diff --git a/src/pulsecore/shm.c b/src/pulsecore/shm.c index bcccfe2e4..f67cb907b 100644 --- a/src/pulsecore/shm.c +++ b/src/pulsecore/shm.c @@ -54,6 +54,8 @@ #include #include +#include "log/audio_log.h" + #include "shm.h" #if defined(__linux__) && !defined(MADV_REMOVE) @@ -270,6 +272,8 @@ void pa_shm_free(pa_shm *m) { goto finish; } + AUDIO_INFO_LOG("mem type: %{public}d", m->type); + #if defined(HAVE_SHM_OPEN) || defined(HAVE_MEMFD) if (munmap(m->ptr, PA_PAGE_ALIGN(m->size)) < 0) pa_log("munmap() failed: %s", pa_cstrerror(errno)); -- Gitee