更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
perf_record.h 文件参考

浏览源代码.

函数

void PerfRecord (int fd, int argc, char **argv)
 

函数说明

◆ PerfRecord()

void PerfRecord ( int  fd,
int  argc,
char **  argv 
)

在文件 perf_record.c146 行定义.

147{
148 int ret;
149 int child;
150 char *buf;
151 ssize_t len;
152 SubCmd cmd = {0};
153
154 if (argc < 3) { /* perf record argc is at least 3 */
155 return;
156 }
157
158 ret = PerfRecordAttrInit();
159 if (ret != 0) {
160 printf("perf record attr init failed\n");
161 return;
162 }
163
164 ret = ParseOptions(argc - 2, &argv[2], g_recordOpts, &cmd); /* parse option and cmd begin at index 2 */
165 if (ret != 0) {
166 printf("parse error\n");
167 return;
168 }
169
170 ret = PerfConfig(fd, &g_recordAttr);
171 if (ret != 0) {
172 printf("perf config failed\n");
173 return;
174 }
175
176 PerfStart(fd, 0);
177 child = fork();
178 if (child < 0) {
179 printf("fork error\n");
180 PerfStop(fd);
181 return;
182 } else if (child == 0) {
183 (void)execve(cmd.path, cmd.params, NULL);
184 exit(0);
185 }
186
187 waitpid(child, 0, 0);
188 PerfStop(fd);
189
190 buf = (char *)malloc(LOSCFG_PERF_BUFFER_SIZE);
191 if (buf == NULL) {
192 printf("no memory for read perf 0x%x\n", LOSCFG_PERF_BUFFER_SIZE);
193 return;
194 }
195 len = PerfRead(fd, buf, LOSCFG_PERF_BUFFER_SIZE);
196 ret = PerfWriteFile(g_savePath, buf, len);
197 if (ret == 0) {
198 printf("save perf data success at %s\n", g_savePath);
199 } else {
200 printf("save perf data failed at %s\n", g_savePath);
201 }
202 free(buf);
203}
void PerfStart(int fd, size_t sectionId)
Definition: perf.c:106
int PerfConfig(int fd, PerfConfigAttr *attr)
Definition: perf.c:116
ssize_t PerfRead(int fd, char *buf, size_t size)
Definition: perf.c:126
void PerfStop(int fd)
Definition: perf.c:111
INT64 ssize_t
Definition: los_typedef.h:79
void * malloc(size_t size)
动态分配内存块大小
Definition: malloc.c:81
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
int ParseOptions(int argc, char **argv, PerfOption *opt, SubCmd *cmd)
Definition: option.c:71
static int PerfRecordAttrInit(void)
Definition: perf_record.c:74
static PerfConfigAttr g_recordAttr
Definition: perf_record.c:46
static const char * g_savePath
Definition: perf_record.c:47
static PerfOption g_recordOpts[]
Definition: perf_record.c:64
ssize_t PerfWriteFile(const char *filePath, const char *buf, ssize_t bufSize)
Definition: perf_record.c:108
void exit(int status)
Definition: stdlib.c:60
Definition: option.h:61
const char * path
Definition: option.h:62
char * params[CMD_MAX_PARAMS]
Definition: option.h:63
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
函数调用图:
这是这个函数的调用关系图: