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

浏览源代码.

函数

static int ParseOption (char **argv, int *index, PerfOption *opts)
 
int ParseOptions (int argc, char **argv, PerfOption *opts, SubCmd *cmd)
 
int ParseIds (const char *argv, int *arr, unsigned int *len)
 
static const PerfEventStrToEvent (const char *str)
 
int ParseEvents (const char *argv, PerfEventConfig *eventsCfg, unsigned int *len)
 

函数说明

◆ ParseEvents()

int ParseEvents ( const char *  argv,
PerfEventConfig eventsCfg,
unsigned int len 
)

在文件 option.c144 行定义.

145{
146 int ret;
147 unsigned int index = 0;
148 const PerfEvent *event = NULL;
149 char *sp = NULL;
150 char *this = NULL;
151 char *list = strdup(argv);
152
153 if (list == NULL) {
154 printf("no memory for ParseEvents\n");
155 return -1;
156 }
157
158 sp = strtok_r(list, ",", &this);
159 while (sp) {
160 event = StrToEvent(sp);
161 if (event == NULL) {
162 ret = -1;
163 goto EXIT;
164 }
165
166 if (index == 0) {
167 eventsCfg->type = event->type;
168 } else if (eventsCfg->type != event->type) {
169 printf("events type must be same\n");
170 ret = -1;
171 goto EXIT;
172 }
173 eventsCfg->events[index].eventId = event->event;
174 sp = strtok_r(NULL, ",", &this);
175 index++;
176 }
177 *len = index;
178 ret = 0;
179EXIT:
180 free(list);
181 return ret;
182}
macro EXC_SP_SET reg1 mrc 获取CPU信息 and mov mul reg0 计算当前CPU栈的偏移位置 ldr reg1 相减得到栈顶 mov sp
Definition: asm.h:57
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
static const PerfEvent * StrToEvent(const char *str)
Definition: option.c:132
unsigned int eventId
Definition: perf.h:123
unsigned int type
Definition: perf.h:121
struct PerfEventConfig::@0 events[PERF_MAX_EVENT]
函数调用图:
这是这个函数的调用关系图:

◆ ParseIds()

int ParseIds ( const char *  argv,
int arr,
unsigned int len 
)

在文件 option.c102 行定义.

103{
104 int res, ret;
105 unsigned int index = 0;
106 char *sp = NULL;
107 char *this = NULL;
108 char *list = strdup(argv);
109
110 if (list == NULL) {
111 printf("no memory for ParseIds\n");
112 return -1;
113 }
114
115 sp = strtok_r(list, ",", &this);
116 while (sp) {
117 res = strtoul(sp, NULL, 0);
118 if (res < 0) {
119 ret = -1;
120 goto EXIT;
121 }
122 arr[index++] = res;
123 sp = strtok_r(NULL, ",", &this);
124 }
125 *len = index;
126 ret = 0;
127EXIT:
128 free(list);
129 return ret;
130}
函数调用图:
这是这个函数的调用关系图:

◆ ParseOption()

static int ParseOption ( char **  argv,
int index,
PerfOption opts 
)
static

在文件 option.c37 行定义.

38{
39 int ret = 0;
40 const char *str = NULL;
41
42 while ((opts->name != NULL) && (*opts->name != 0)) {
43 if (strcmp(argv[*index], opts->name) == 0) {
44 switch (opts->type) {
46 *opts->value = strtoul(argv[++(*index)], NULL, 0);
47 break;
49 *opts->str = argv[++(*index)];
50 break;
52 str = argv[++(*index)];
53 if ((*opts->cb)(str) != 0) {
54 printf("parse error\n");
55 ret = -1;
56 }
57 break;
58 default:
59 printf("invalid option\n");
60 ret = -1;
61 break;
62 }
63 return ret;
64 }
65 opts++;
66 }
67
68 return -1;
69}
@ OPTION_TYPE_UINT
Definition: option.h:48
@ OPTION_TYPE_STRING
Definition: option.h:49
@ OPTION_TYPE_CALLBACK
Definition: option.h:50
const char ** str
Definition: option.h:56
unsigned int * value
Definition: option.h:57
CALL_BACK cb
Definition: option.h:58
int type
Definition: option.h:54
const char * name
Definition: option.h:55
这是这个函数的调用关系图:

◆ ParseOptions()

int ParseOptions ( int  argc,
char **  argv,
PerfOption opts,
SubCmd cmd 
)

在文件 option.c71 行定义.

72{
73 int i;
74 int index = 0;
75
76 while ((index < argc) && (argv[index] != NULL) && (*argv[index] == '-')) {
77 if (ParseOption(argv, &index, opts) != 0) {
78 return -1;
79 }
80 index++;
81 }
82
83 if ((index < argc) && (argv[index] != NULL)) {
84 cmd->path = argv[index];
85 cmd->params[0] = argv[index];
86 index++;
87 } else {
88 printf("no subcmd to execute\n");
89 return -1;
90 }
91
92 for (i = 1; (index < argc) && (i < CMD_MAX_PARAMS); index++, i++) {
93 cmd->params[i] = argv[index];
94 }
95 printf_debug("subcmd = %s\n", cmd->path);
96 for (int j = 0; j < i; j++) {
97 printf_debug("paras[%d]:%s\n", j, cmd->params[j]);
98 }
99 return 0;
100}
static int ParseOption(char **argv, int *index, PerfOption *opts)
Definition: option.c:37
const char * path
Definition: option.h:62
char * params[CMD_MAX_PARAMS]
Definition: option.h:63
函数调用图:
这是这个函数的调用关系图:

◆ StrToEvent()

static const PerfEvent * StrToEvent ( const char *  str)
inlinestatic

在文件 option.c132 行定义.

133{
134 const PerfEvent *evt = &g_events[0];
135
136 for (; evt->event != -1; evt++) {
137 if (strcmp(str, evt->name) == 0) {
138 return evt;
139 }
140 }
141 return NULL;
142}
const PerfEvent g_events[]
Definition: perf_list.c:42
int event
Definition: perf_list.h:44
const char * name
Definition: perf_list.h:43
这是这个函数的调用关系图: