59 return (time->tv_sec) * 1000 + (time->tv_nsec / 1000000);
64 clock_gettime(CLOCK_REALTIME, &
_tmp_time);
68 int main(
int argc,
char **argv)
70 printf(
"Launching dlt-kpi...\n");
74 fprintf(stderr,
"Initialization error!\n");
82 fprintf(stderr,
"Error occurred initializing process lists\n");
88 fprintf(stderr,
"Error occurred initializing mutex\n");
95 pthread_t process_thread;
97 pthread_t check_thread;
101 fprintf(stderr,
"Could not create thread\n");
106 fprintf(stderr,
"Could not create thread\n");
111 fprintf(stderr,
"Could not create thread\n");
115 pthread_join(process_thread,
NULL);
116 pthread_join(irq_thread,
NULL);
117 pthread_join(check_thread,
NULL);
133 struct sigaction action;
134 memset(&action, 0,
sizeof(
struct sigaction));
137 sigaction(SIGTERM, &action,
NULL);
143 fprintf(stderr,
"dlt-kpi is now terminating due to signal %d...\n", sig);
145 fprintf(stderr,
"dlt-kpi is now terminating due to an error...\n");
189 static unsigned long int old_millis, sleep_millis, dif_millis;
206 usleep(sleep_millis * 1000);
216 if(list ==
NULL || process_callback ==
NULL || title ==
NULL)
218 fprintf(stderr,
"%s: Invalid Parameter (NULL)\n", __func__);
237 fprintf(stderr,
"%s: dlt_user_log_write_start() returned error.\n", __func__);
243 fprintf(stderr,
"%s: dlt_user_log_write_string() returned error.\n", __func__);
257 fprintf(stderr,
"%s: dlt_user_log_write_finish() returned error.\n",__func__);
263 fprintf(stderr,
"%s: dlt_user_log_write_start() returned error.\n",__func__);
269 fprintf(stderr,
"%s: dlt_user_log_write_string() returned error.\n",__func__);
273 else if(delete_elements)
287 fprintf(stderr,
"%s: dlt_user_log_write_finish() returned error.\n",__func__);
301 static struct dirent *current_dir;
302 static pid_t current_dir_pid;
306 fprintf(stderr,
"dlt_kpi_update_process_list(): Nullpointer parameter");
310 DIR *proc_dir = opendir(
"/proc");
313 dlt_log(LOG_ERR,
"Could not open /proc/ !\n");
317 current_dir = readdir(proc_dir);
320 int debug_process_count = 0;
324 fprintf(stderr,
"Can't lock mutex\n");
330 if(current_dir ==
NULL)
345 current_dir_pid = strtol(current_dir->d_name, &strchk, 10);
346 if(*strchk !=
'\0' || current_dir_pid <= 0)
349 current_dir = readdir(proc_dir);
354 if(list->
cursor ==
NULL || current_dir_pid < list->cursor->pid)
357 if(new_process ==
NULL)
359 fprintf(stderr,
"Error: Could not create process (out of memory?)\n");
369 current_dir = readdir(proc_dir);
370 debug_process_count++;
372 else if(current_dir_pid > list->
cursor->
pid)
380 else if(current_dir_pid == list->
cursor->
pid)
389 fprintf(stderr,
"dlt_kpi_update_process_list: Can't add process to list updateProcessList\n");
396 current_dir = readdir(proc_dir);
397 debug_process_count++;
403 fprintf(stderr,
"Can't unlock mutex\n");
419 if(closedir(proc_dir) < 0)
420 fprintf(stderr,
"Could not close /proc/ directory\n");
435 static unsigned long int old_millis, sleep_millis, dif_millis;
452 usleep(sleep_millis * 1000);
470 static unsigned long int old_millis, sleep_millis, dif_millis;
487 usleep(sleep_millis * 1000);
499 fprintf(stderr,
"Can't lock mutex\n");
507 fprintf(stderr,
"Can't unlock mutex\n");
void dlt_kpi_stop_loops(int sig)
DltReturnValue dlt_kpi_log_list(DltKpiProcessList *list, DltReturnValue(*process_callback)(DltKpiProcess *, char *, int), char *title, int delete_elements)
static DltKpiProcessList * new_process_list
DltReturnValue dlt_kpi_update_process_list(DltKpiProcessList *list, unsigned long int time_dif_ms)
DltReturnValue dlt_kpi_init(int argc, char **argv, DltKpiConfig *config)
DltKpiProcess * dlt_kpi_create_process(int pid)
DltReturnValue dlt_user_log_write_string(DltContextData *log, const char *text)
#define DLT_UNREGISTER_APP()
DltReturnValue dlt_kpi_remove_process_at_cursor(DltKpiProcessList *list)
struct DltKpiProcess * cursor
DLT_DECLARE_CONTEXT(kpi_ctx)
static DltKpiProcessList * list
unsigned long int get_millis()
DltReturnValue dlt_log(int prio, char *s)
DltReturnValue dlt_kpi_irq_loop()
DltReturnValue dlt_kpi_get_msg_process_update(DltKpiProcess *process, char *buffer, int maxlen)
DltKpiProcessList * dlt_kpi_create_process_list()
DltReturnValue dlt_kpi_get_msg_process_stop(DltKpiProcess *process, char *buffer, int maxlen)
DltReturnValue dlt_kpi_process_loop()
int main(int argc, char **argv)
static char data[kDataSize]
void * dlt_kpi_start_check_thread()
DltKpiProcess * dlt_kpi_clone_process(DltKpiProcess *original)
unsigned long int timespec_to_millis(struct timespec *time)
static DltKpiProcessList * update_process_list
struct DltKpiProcess * next
DltReturnValue dlt_kpi_add_process_before_cursor(DltKpiProcessList *list, DltKpiProcess *process)
DltReturnValue dlt_kpi_free_process_list(DltKpiProcessList *list)
#define DLT_REGISTER_APP(APPID, DESCRIPTION)
DltLogLevelType log_level
DltReturnValue dlt_kpi_free_process_lists()
unsigned char buffer[BUFFER_SIZE]
Buffer for dlt file transfer. The size is defined by BUFFER_SIZE.
void * dlt_kpi_start_irq_thread()
static pthread_mutex_t process_list_mutex
DltReturnValue dlt_kpi_increment_cursor(DltKpiProcessList *list)
static struct timespec _tmp_time
DltReturnValue dlt_kpi_add_process_after_cursor(DltKpiProcessList *list, DltKpiProcess *process)
unsigned long int cpu_time
#define DLT_UNREGISTER_CONTEXT(CONTEXT)
DltReturnValue dlt_kpi_update_process(DltKpiProcess *process, unsigned long int time_dif_ms)
#define DLT_REGISTER_CONTEXT_LL_TS(CONTEXT, CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS)
static volatile sig_atomic_t stop_loop
DltReturnValue dlt_kpi_init_process_lists()
#define DLT_LOG(CONTEXT, LOGLEVEL, ARGS...)
DltReturnValue dlt_kpi_log_check_commandlines()
static DltKpiProcessList * stopped_process_list
DltReturnValue dlt_kpi_log_interrupts(DltContext *ctx, DltLogLevelType log_level)
DltReturnValue dlt_kpi_reset_cursor(DltKpiProcessList *list)
DltReturnValue dlt_kpi_check_loop()
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)
void dlt_kpi_init_sigterm_handler()
void * dlt_kpi_start_process_thread()
DltReturnValue dlt_user_log_write_finish(DltContextData *log)
DltReturnValue dlt_user_log_write_start(DltContext *handle, DltContextData *log, DltLogLevelType loglevel)