MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / w_profiling_proc

Function w_profiling_proc

mi/mi_core.c:487–563  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485}
486
487static mi_response_t *w_profiling_proc(const mi_params_t *params,
488 struct mi_handler *async_hdl)
489{
490 int id;
491 int pid;
492 int level;
493 int have_id;
494 int have_pid;
495 int have_level;
496 int target_idx = -1;
497 int i;
498 mi_response_t *resp;
499 mi_item_t *resp_obj;
500 mi_item_t *procs_arr;
501
502 have_id = (try_get_mi_int_param(params, "id", &id) == 0);
503 have_pid = (try_get_mi_int_param(params, "pid", &pid) == 0);
504 have_level = (try_get_mi_int_param(params, "level", &level) == 0);
505
506 if (have_id && have_pid)
507 return init_mi_error_extra(JSONRPC_INVAL_PARAMS_CODE,
508 MI_SSTR(JSONRPC_INVAL_PARAMS_MSG),
509 MI_SSTR("Only one of 'id' or 'pid' is allowed"));
510
511 if (have_id) {
512 if (id < 0 || id >= counted_max_processes)
513 return init_mi_error_extra(JSONRPC_INVAL_PARAMS_CODE,
514 MI_SSTR(JSONRPC_INVAL_PARAMS_MSG),
515 MI_SSTR("Bad process ID"));
516 target_idx = id;
517 } else if (have_pid) {
518 target_idx = get_process_ID_by_PID(pid);
519 if (target_idx < 0)
520 return init_mi_error_extra(JSONRPC_INVAL_PARAMS_CODE,
521 MI_SSTR(JSONRPC_INVAL_PARAMS_MSG), MI_SSTR("Bad PID"));
522 }
523
524 if (have_level) {
525 if (level < LEVEL_OFF)
526 level = LEVEL_OFF;
527 else if (level > LEVEL_FULL)
528 level = LEVEL_FULL;
529
530 if (target_idx >= 0) {
531 pt[target_idx].profiling_proc_level = level;
532 } else {
533 for (i = 0; i < counted_max_processes; i++)
534 pt[i].profiling_proc_level = level;
535 }
536 return init_mi_result_ok();
537 }
538
539 resp = init_mi_result_object(&resp_obj);
540 if (!resp)
541 return 0;
542
543 procs_arr = add_mi_array(resp_obj, MI_SSTR("Processes"));
544 if (!procs_arr) {

Callers

nothing calls this directly

Calls 7

try_get_mi_int_paramFunction · 0.85
init_mi_error_extraFunction · 0.85
get_process_ID_by_PIDFunction · 0.85
init_mi_result_objectFunction · 0.85
add_mi_arrayFunction · 0.85
free_mi_responseFunction · 0.85

Tested by

no test coverage detected