@@ -163,6 +163,7 @@ static int on_stop_cb_default(void *opt, uint8_t *buf)
163
163
164
164
/* The default profiling interval equals to 10 ms. */
165
165
#define SYSPROF_DEFAULT_INTERVAL 10
166
+ #define SYSPROF_DEFAULT_MODE "C"
166
167
#define SYSPROF_DEFAULT_OUTPUT "sysprof.bin"
167
168
168
169
static int set_output_path (const char * path , struct luam_Sysprof_Options * opt ) {
@@ -185,13 +186,16 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt, in
185
186
const char * mode = NULL ;
186
187
187
188
cTValue * mode_opt = lj_tab_getstr (options , lj_str_newlit (L , "mode" ));
188
- if (!mode_opt || !tvisstr (mode_opt )) {
189
- return PROFILE_ERRUSE ;
189
+ if (mode_opt ) {
190
+ if (!tvisstr (mode_opt ))
191
+ return PROFILE_ERRBADMODE ;
192
+ mode = strVdata (mode_opt );
193
+ if (mode [1 ] != '\0' )
194
+ return PROFILE_ERRBADMODE ;
190
195
}
191
196
192
- mode = strVdata (mode_opt );
193
- if (mode [1 ] != '\0' )
194
- return PROFILE_ERRUSE ;
197
+ if (!mode )
198
+ mode = SYSPROF_DEFAULT_MODE ;
195
199
196
200
switch (* mode ) {
197
201
case 'D' :
@@ -204,7 +208,7 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt, in
204
208
opt -> mode = LUAM_SYSPROF_CALLGRAPH ;
205
209
break ;
206
210
default :
207
- return PROFILE_ERRUSE ;
211
+ return PROFILE_ERRBADMODE ;
208
212
}
209
213
}
210
214
@@ -215,7 +219,7 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt, in
215
219
if (interval && tvisnumber (interval )) {
216
220
int32_t signed_interval = numberVint (interval );
217
221
if (signed_interval < 1 )
218
- return PROFILE_ERRUSE ;
222
+ return PROFILE_ERRBADINTERVAL ;
219
223
opt -> interval = signed_interval ;
220
224
}
221
225
}
@@ -231,7 +235,7 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt, in
231
235
if (!pathtv )
232
236
path = SYSPROF_DEFAULT_OUTPUT ;
233
237
else if (!tvisstr (pathtv ))
234
- return PROFILE_ERRUSE ;
238
+ return PROFILE_ERRBADPATH ;
235
239
else
236
240
path = strVdata (pathtv );
237
241
@@ -253,11 +257,12 @@ static int parse_sysprof_opts(lua_State *L, struct luam_Sysprof_Options *opt, in
253
257
254
258
static int parse_options (lua_State * L , struct luam_Sysprof_Options * opt )
255
259
{
256
- if (lua_gettop (L ) != 1 )
257
- return PROFILE_ERRUSE ;
260
+ if (lua_gettop (L ) != 1 ) {
261
+ lua_createtable (L , 0 , 0 );
262
+ }
258
263
259
264
if (!lua_istable (L , 1 ))
260
- return PROFILE_ERRUSE ;
265
+ return PROFILE_ERRBADTABLE ;
261
266
262
267
return parse_sysprof_opts (L , opt , 1 );
263
268
}
@@ -270,6 +275,26 @@ static int sysprof_error(lua_State *L, int status)
270
275
lua_pushstring (L , err2msg (LJ_ERR_PROF_MISUSE ));
271
276
lua_pushinteger (L , EINVAL );
272
277
return 3 ;
278
+ case PROFILE_ERRBADMODE :
279
+ lua_pushnil (L );
280
+ lua_pushstring (L , err2msg (LJ_ERR_PROF_BADMODE ));
281
+ lua_pushinteger (L , EINVAL );
282
+ return 3 ;
283
+ case PROFILE_ERRBADINTERVAL :
284
+ lua_pushnil (L );
285
+ lua_pushstring (L , err2msg (LJ_ERR_PROF_BADINTERVAL ));
286
+ lua_pushinteger (L , EINVAL );
287
+ return 3 ;
288
+ case PROFILE_ERRBADPATH :
289
+ lua_pushnil (L );
290
+ lua_pushstring (L , err2msg (LJ_ERR_PROF_BADPATH ));
291
+ lua_pushinteger (L , EINVAL );
292
+ return 3 ;
293
+ case PROFILE_ERRBADTABLE :
294
+ lua_pushnil (L );
295
+ lua_pushstring (L , err2msg (LJ_ERR_PROF_BADTABLE ));
296
+ lua_pushinteger (L , EINVAL );
297
+ return 3 ;
273
298
#if LJ_HASSYSPROF
274
299
case PROFILE_ERRRUN :
275
300
lua_pushnil (L );
0 commit comments