45#define PERF_FILE_MODE 0644
47static const char *
g_savePath =
"/storage/data/perf.data";
54static inline int GetTids(
const char *argv)
59static inline int GetPids(
const char *argv)
78#ifdef LOSCFG_PERF_HW_PMU
83#elif defined LOSCFG_PERF_TIMED_PMU
88#elif defined LOSCFG_PERF_SW_PMU
112 ssize_t totalToWrite = bufSize;
115 if (filePath == NULL || buf == NULL || bufSize == 0) {
119 fd = open(filePath, O_CREAT | O_RDWR | O_TRUNC, PERF_FILE_MODE);
121 printf(
"create file [%s] failed, fd: %d, %s!\n", filePath, fd, strerror(errno));
124 while (totalToWrite > 0) {
125 ssize_t writeThisTime = write(fd, buf, totalToWrite);
126 if (writeThisTime < 0) {
127 printf(
"failed to write file [%s], %s!\n", filePath, strerror(errno));
131 buf += writeThisTime;
132 totalToWrite -= writeThisTime;
133 totalWrite += writeThisTime;
138 return (totalWrite == bufSize) ? 0 : -1;
160 printf(
"perf record attr init failed\n");
166 printf(
"parse error\n");
172 printf(
"perf config failed\n");
179 printf(
"fork error\n");
182 }
else if (child == 0) {
187 waitpid(child, 0, 0);
190 buf = (
char *)
malloc(LOSCFG_PERF_BUFFER_SIZE);
192 printf(
"no memory for read perf 0x%x\n", LOSCFG_PERF_BUFFER_SIZE);
195 len =
PerfRead(fd, buf, LOSCFG_PERF_BUFFER_SIZE);
198 printf(
"save perf data success at %s\n",
g_savePath);
200 printf(
"save perf data failed at %s\n",
g_savePath);
void PerfStart(int fd, size_t sectionId)
void PerfPrintBuffer(const char *buf, ssize_t num)
int PerfConfig(int fd, PerfConfigAttr *attr)
ssize_t PerfRead(int fd, char *buf, size_t size)
@ PERF_COUNT_SW_TASK_SWITCH
@ PERF_COUNT_HW_CPU_CYCLES
void * malloc(size_t size)
动态分配内存块大小
void free(void *ptr)
释放ptr所指向的内存空间
int ParseIds(const char *argv, int *arr, unsigned int *len)
int ParseEvents(const char *argv, PerfEventConfig *eventsCfg, unsigned int *len)
int ParseOptions(int argc, char **argv, PerfOption *opt, SubCmd *cmd)
static int GetTids(const char *argv)
static int PerfRecordAttrInit(void)
static int GetEvents(const char *argv)
static PerfConfigAttr g_recordAttr
static int GetPids(const char *argv)
static const char * g_savePath
void PerfRecord(int fd, int argc, char **argv)
static PerfOption g_recordOpts[]
ssize_t PerfWriteFile(const char *filePath, const char *buf, ssize_t bufSize)
unsigned int processIdsNr
PerfEventConfig eventsCfg
unsigned int processIds[PERF_MAX_FILTER_TSKS]
unsigned int taskIds[PERF_MAX_FILTER_TSKS]
struct PerfEventConfig::@0 events[PERF_MAX_EVENT]
char * params[CMD_MAX_PARAMS]
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