更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
perf_output.c
浏览该文件的文档.
1/*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include "perf_output_pri.h"
33
37
38STATIC VOID OsPerfDefaultNotify(VOID)
39{
40 PRINT_INFO("perf buf waterline notify!\n");
41}
42
44{
45 UINT32 ret;
46 BOOL releaseFlag = FALSE;
47 if (buf == NULL) {
48 buf = LOS_MemAlloc(m_aucSysMem1, size);
49 if (buf == NULL) {
50 return LOS_NOK;
51 } else {
52 releaseFlag = TRUE;
53 }
54 }
55 ret = LOS_CirBufInit(&g_perfOutputCb.ringbuf, buf, size);
56 if (ret != LOS_OK) {
57 goto RELEASE;
58 }
59 g_perfOutputCb.waterMark = size / PERF_BUFFER_WATERMARK_ONE_N;
61 return ret;
62RELEASE:
63 if (releaseFlag) {
64 (VOID)LOS_MemFree(m_aucSysMem1, buf);
65 }
66 return ret;
67}
68
70{
71 if (g_perfBufFlushHook != NULL) {
73 }
74}
75
77{
79 return LOS_CirBufRead(&g_perfOutputCb.ringbuf, dest, size);
80}
81
83{
84 if (g_perfOutputCb.ringbuf.remain < size) {
85 PRINT_INFO("perf buf has no enough space for 0x%x\n", size);
86 return FALSE;
87 }
88 return TRUE;
89}
90
91STATIC VOID OsPerfOutputEnd(VOID)
92{
95 if (g_perfBufNotifyHook != NULL) {
97 }
98 }
99}
100
102{
103 if (!OsPerfOutputBegin(size)) {
104 return LOS_NOK;
105 }
106
108
110 return LOS_OK;
111}
112
114{
115 PRINT_EMG("dump perf data, addr: %p length: %#x\n", g_perfOutputCb.ringbuf.fifo, g_perfOutputCb.ringbuf.size);
116}
117
119{
120 g_perfBufNotifyHook = func;
121}
122
124{
125 g_perfBufFlushHook = func;
126}
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
Definition: los_memory.c:1123
UINT8 * m_aucSysMem1
系统动态内存池地址的起始地址 @note_thinking 能否不要用 0,1来命名核心变量 ???
Definition: los_memory.c:108
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
Definition: los_memory.c:1369
VOID(* PERF_BUF_NOTIFY_HOOK)(VOID)
Definition: los_perf.h:87
VOID(* PERF_BUF_FLUSH_HOOK)(VOID *addr, UINT32 size)
Definition: los_perf.h:94
UINT32 LOS_CirBufRead(CirBuf *cirbufCB, CHAR *buf, UINT32 size)
读取循环buf的数据
Definition: los_cir_buf.c:199
UINT32 LOS_CirBufWrite(CirBuf *cirbufCB, const CHAR *buf, UINT32 size)
写入数据到循环buf区
Definition: los_cir_buf.c:112
UINT32 LOS_CirBufInit(CirBuf *cirbufCB, CHAR *fifo, UINT32 size)
初始化循环buf
Definition: los_cir_buf.c:225
UINT32 LOS_CirBufUsedSize(CirBuf *cirbufCB)
返回循环buf已使用的大小
Definition: los_cir_buf.c:37
unsigned int UINT32
Definition: los_typedef.h:57
char CHAR
Definition: los_typedef.h:63
size_t BOOL
Definition: los_typedef.h:88
UINT32 OsPerfOutputInit(VOID *buf, UINT32 size)
Definition: perf_output.c:43
STATIC VOID OsPerfDefaultNotify(VOID)
Definition: perf_output.c:38
STATIC VOID OsPerfOutputEnd(VOID)
Definition: perf_output.c:91
UINT32 OsPerfOutputWrite(CHAR *data, UINT32 size)
Definition: perf_output.c:101
STATIC BOOL OsPerfOutputBegin(UINT32 size)
Definition: perf_output.c:82
VOID OsPerfOutputInfo(VOID)
Definition: perf_output.c:113
UINT32 OsPerfOutputRead(CHAR *dest, UINT32 size)
Definition: perf_output.c:76
STATIC PERF_BUF_FLUSH_HOOK g_perfBufFlushHook
Definition: perf_output.c:35
STATIC PerfOutputCB g_perfOutputCb
Definition: perf_output.c:36
STATIC PERF_BUF_NOTIFY_HOOK g_perfBufNotifyHook
Definition: perf_output.c:34
VOID OsPerfOutputFlush(VOID)
Definition: perf_output.c:69
VOID OsPerfFlushHookReg(const PERF_BUF_FLUSH_HOOK func)
Definition: perf_output.c:123
VOID OsPerfNotifyHookReg(const PERF_BUF_NOTIFY_HOOK func)
Definition: perf_output.c:118
UINT32 size
Definition: los_cir_buf.h:53
UINT32 remain
Definition: los_cir_buf.h:54
CHAR * fifo
Definition: los_cir_buf.h:57