40 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
49 if(time_dif_ms > 0 && cpu_count > 0)
50 process->
io_wait = process->
io_wait * 1000 / time_dif_ms / cpu_count;
61 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
68 unsigned long total_cpu_time = utime + stime;
75 if(time_dif_ms > 0 && cpu_count > 0)
90 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
103 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
107 char *
buffer, *tok, *last_tok;
108 char *delim =
" :\t\n";
116 tok = strtok(buffer, delim);
121 if(strcmp(last_tok,
"voluntary_ctxt_switches") == 0 || strcmp(last_tok,
"nonvoluntary_ctxt_switches") == 0)
128 fprintf(stderr,
"Could not parse ctx_switches info from /proc/%d/status", process->
pid);
136 tok = strtok(
NULL, delim);
148 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
152 char *
buffer, *tok, *last_tok;
153 char *delim =
" :\t\n";
162 tok = strtok(buffer, delim);
167 if(strcmp(last_tok,
"rchar") == 0 || strcmp(last_tok,
"wchar") == 0)
170 process->
io_bytes += strtoul(tok, &chk, 10);
174 fprintf(stderr,
"Could not parse io_bytes info from /proc/%d/io", process->
pid);
182 tok = strtok(
NULL, delim);
195 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
211 if(new_process ==
NULL)
213 fprintf(stderr,
"%s: Out of Memory \n", __func__);
239 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
245 if(new_process ==
NULL)
247 fprintf(stderr,
"%s: Out of Memory\n", __func__);
258 fprintf(stderr,
"%s: Out of Memory\n", __func__);
276 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
292 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
296 printf(
"[PID %d]\n", process->
pid);
297 printf(
" > PPID : %d\n", process->
ppid);
299 printf(
" > CPUTIME : %lu (busy ms/s)\n", process->
cpu_time);
300 printf(
" > RSS : %ld\n", process->
rss);
302 printf(
" > IOBYTES : %lu\n", process->
io_bytes);
310 if(target_str ==
NULL)
312 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
320 fprintf(stderr,
"%s: Invalid Parameter (PID)\n", __func__);
326 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
331 snprintf(filename,
BUFFER_SIZE,
"/proc/%d/%s", pid, subdir);
340 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
355 char *tok = strtok(buffer,
" \t\n");
356 unsigned int i = 1, found = 0;
366 tok = strtok(
NULL,
" \t\n");
369 unsigned long int ret = 0;
374 ret = strtoul(tok, &check, 10);
377 fprintf(stderr,
"dlt_kpi_read_process_stat_to_ulong(): Could not extract token\n");
382 fprintf(stderr,
"dlt_kpi_read_process_stat_to_ulong(): Index not found\n");
393 fprintf(stderr,
"%s: Invalid Parameter (PID)\n", __func__);
399 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
403 char *tmp_buffer =
NULL;
407 if(tmp_buffer !=
NULL)
413 char *tok = strtok(tmp_buffer,
" \t\n");
423 tok = strtok(
NULL,
" \t\n");
428 (*buffer) = malloc(strlen(tok) + 1);
429 strncpy(*buffer, tok, strlen(tok) + 1);
433 fprintf(stderr,
"dlt_kpi_read_process_stat_cmdline(): cmdline entry not found\n");
444 if(process ==
NULL || buffer ==
NULL)
446 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
457 if(process ==
NULL || buffer ==
NULL)
459 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
470 if(process ==
NULL || buffer ==
NULL)
472 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
476 snprintf(buffer, maxlen,
"%d", process->
pid);
483 if(process ==
NULL || buffer ==
NULL)
485 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
489 snprintf(buffer, maxlen,
"%d;%s", process->
pid, process->
command_line);
DltKpiProcess * dlt_kpi_create_process(int pid)
DltReturnValue dlt_kpi_read_file_compact(char *filename, char **target)
DltReturnValue dlt_kpi_process_update_io_bytes(DltKpiProcess *process)
unsigned long int last_cpu_time
unsigned long int last_io_wait
DltReturnValue dlt_kpi_read_process_stat_cmdline(pid_t pid, char **buffer)
DltReturnValue dlt_kpi_get_msg_process_update(DltKpiProcess *process, char *buffer, int maxlen)
DltReturnValue dlt_kpi_process_update_io_wait(DltKpiProcess *process, unsigned long int time_dif_ms)
DltReturnValue dlt_kpi_get_msg_process_stop(DltKpiProcess *process, char *buffer, int maxlen)
DltKpiProcess * dlt_kpi_clone_process(DltKpiProcess *original)
struct DltKpiProcess * next
unsigned char buffer[BUFFER_SIZE]
Buffer for dlt file transfer. The size is defined by BUFFER_SIZE.
int dlt_kpi_get_cpu_count()
DltReturnValue dlt_kpi_process_update_cpu_time(DltKpiProcess *process, unsigned long int time_dif_ms)
unsigned long int cpu_time
DltReturnValue dlt_kpi_print_process(DltKpiProcess *process)
DltReturnValue dlt_kpi_update_process(DltKpiProcess *process, unsigned long int time_dif_ms)
DltReturnValue dlt_kpi_free_process(DltKpiProcess *process)
unsigned long int io_wait
unsigned long int io_bytes
struct DltKpiProcess * prev
DltReturnValue dlt_kpi_read_process_file_to_str(pid_t pid, char **target_str, char *subdir)
DltReturnValue dlt_kpi_get_msg_process_new(DltKpiProcess *process, char *buffer, int maxlen)
DltReturnValue dlt_kpi_get_msg_process_commandline(DltKpiProcess *process, char *buffer, int maxlen)
DltReturnValue dlt_kpi_process_update_ctx_switches(DltKpiProcess *process)
DltReturnValue dlt_kpi_process_update_rss(DltKpiProcess *process)
unsigned long int dlt_kpi_read_process_stat_to_ulong(pid_t pid, unsigned int index)