/* * Write the message into log file according to different level. */ void debug_print(FILE *out, int level, const char *fmt, ...) { va_list ap; if (level <= s_debuglevel) { if (out == NULL) { if (s_logfile != NULL) { (void) pthread_mutex_lock(&s_debug_ctl.mutex); (void) fprintf(s_logfile, "%"PRIu64": ", current_ms() / 1000); va_start(ap, fmt); (void) vfprintf(s_logfile, fmt, ap); va_end(ap); (void) fflush(s_logfile); (void) pthread_mutex_unlock( &s_debug_ctl.mutex); } } else { (void) pthread_mutex_lock(&s_debug_ctl.mutex); (void) fprintf(out, "%"PRIu64": ", current_ms() / 1000); va_start(ap, fmt); (void) vfprintf(out, fmt, ap); va_end(ap); (void) fflush(out); (void) pthread_mutex_unlock(&s_debug_ctl.mutex); } } }
static int ll_smpl(perf_ctl_t *ctl, task_ll_t *task, int *intval_ms) { *intval_ms = current_ms() - ctl->last_ms; proc_intval_update(*intval_ms); node_cpu_traverse(cpu_ll_smpl, (void *)task, B_FALSE, cpu_ll_setupstart); ctl->last_ms = current_ms(); return (0); }
static int profiling_smpl(perf_ctl_t *ctl, task_profiling_t *task, int *intval_ms) { *intval_ms = current_ms() - ctl->last_ms; proc_intval_update(*intval_ms); node_intval_update(*intval_ms); node_cpu_traverse(cpu_profiling_smpl, NULL, B_FALSE, cpu_profiling_setupstart); ctl->last_ms = current_ms(); return (0); }
static int profiling_restore(perf_ctl_t *ctl, task_restore_t *task) { node_cpu_traverse(cpu_profiling_restore, (void *)(task->count_id), B_FALSE, NULL); s_partpause_enabled = B_FALSE; ctl->last_ms = current_ms(); return (0); }
int os_pqos_cmt_smpl(perf_ctl_t *ctl, perf_task_t *task, int *intval_ms) { task_pqos_cmt_t *t = (task_pqos_cmt_t *)task; track_proc_t *proc; track_lwp_t *lwp = NULL; boolean_t end; proc_enum_update(0); if (t->pid == 0) proc_pqos_func(NULL, os_pqos_cmt_proc_smpl); else { if ((proc = proc_find(t->pid)) == NULL) { disp_pqos_cmt_data_ready(0); return -1; } if (t->lwpid == 0) os_pqos_cmt_proc_smpl(proc, NULL, &end); else { if ((lwp = proc_lwp_find(proc, t->lwpid)) == NULL) { proc_refcount_dec(proc); disp_pqos_cmt_data_ready(0); return -1; } os_pqos_cmt_lwp_smpl(lwp, NULL, &end); } if (lwp != NULL) lwp_refcount_dec(lwp); proc_refcount_dec(proc); } *intval_ms = current_ms() - ctl->last_ms_pqos; ctl->last_ms_pqos = current_ms(); disp_pqos_cmt_data_ready(*intval_ms); return (0); }
static int ll_start(perf_ctl_t *ctl) { /* Setup perf on each CPU. */ if (node_cpu_traverse(cpu_ll_setup, NULL, B_TRUE, NULL) != 0) { return (-1); } /* Start to count on each CPU. */ node_cpu_traverse(cpu_ll_start, NULL, B_FALSE, NULL); ctl->last_ms = current_ms(); return (0); }
static int profiling_start(perf_ctl_t *ctl, task_profiling_t *task) { /* Setup perf on each CPU. */ if (node_cpu_traverse(cpu_profiling_setup, NULL, B_TRUE, NULL) != 0) { return (-1); } profiling_pause(); /* Start to count on each CPU. */ if (node_cpu_traverse(cpu_profiling_start, NULL, B_TRUE, NULL) != 0) { return (-1); } ctl->last_ms = current_ms(); return (0); }
/****************************************************************************** * * check_time_event * * If time delta is > XTestSHORT_DELAY_TIME then insert a time event * and return 0; else return the delay time. */ static CARD16 check_time_event() { CARD32 tstamp; CARD16 tchar; XTestDelayInfo *tptr; /* * get the number of milliseconds between input actions */ tstamp = current_ms(¤t_time); /* * if the number of milliseconds is too large to fit in a CARD16, * then add a XTestDELAY_ACTION to the input action event. */ if (tstamp > XTestSHORT_DELAY_TIME) { /* * If there isn't room in the input action event for * an XTestDELAY_ACTION, then send that event to the * client and start filling an empty one. */ if (!there_is_room(sizeof(XTestDelayInfo))) { flush_input_actions(); } /* * point tptr to the correct place in the input action event */ tptr = (XTestDelayInfo *) (&(input_action_packet.actions[packet_index])); /* * compute the input action header */ tptr->header = XTestPackDeviceID(XTestDELAY_DEVICE_ID) | XTestDELAY_ACTION; /* * set the delay time in the input action */ tptr->delay_time = tstamp; /* * increment the packet index by the size of the input action */ packet_index = packet_index + (sizeof(XTestDelayInfo)); if (packed_mode != XTestPACKED_ACTIONS) { /* * if input actions are not packed, send the input * action event to the client */ flush_input_actions(); } /* * set the returned delay time to 0 */ tchar = 0; } else { /* * set the returned delay time to the computed delay time */ tchar = tstamp; } return(tchar); }
/* ARGSUSED */ static void * disp_handler(void *arg) { disp_flag_t flag; int status = 0; cmd_t cmd; boolean_t quit, pagelist_inited = B_FALSE; struct timespec timeout; uint64_t start_ms; int64_t diff_ms; /* * Wait cons thread to complete initialization. */ if (!consthr_init_wait()) { debug_print(NULL, 2, "Timeout for waiting cons thread to " "complete initialization\n"); /* * The cons thread should exit with error or startup failed, * disp thread stops running. */ goto L_EXIT; } /* * NumaTOP contains multiple windows. It uses double linked list * to link all of windows. */ page_list_init(); pagelist_inited = B_TRUE; timeout_set(&timeout, 0); start_ms = current_ms(); for (;;) { status = 0; (void) pthread_mutex_lock(&s_disp_ctl.mutex); flag = s_disp_ctl.flag; while (flag == DISP_FLAG_NONE) { status = pthread_cond_timedwait(&s_disp_ctl.cond, &s_disp_ctl.mutex, &timeout); flag = s_disp_ctl.flag; if (status == ETIMEDOUT) { break; } } if (flag == DISP_FLAG_CMD) { (void) memcpy(&cmd, &s_disp_ctl.cmd, sizeof (cmd)); } s_disp_ctl.flag = DISP_FLAG_NONE; (void) pthread_mutex_unlock(&s_disp_ctl.mutex); diff_ms = current_ms() - start_ms; if (g_run_secs <= diff_ms / MS_SEC) { g_run_secs = TIME_NSEC_MAX; debug_print(NULL, 2, "disp: it's time to exit\n"); continue; } if ((status == ETIMEDOUT) && (flag == DISP_FLAG_NONE)) { if (page_current_get() == NULL) { timeout_set(&timeout, DISP_DEFAULT_INTVAL); continue; } /* * Force a 'refresh' operation. */ CMD_ID_SET(&cmd, CMD_REFRESH_ID); cmd_execute(&cmd, NULL); timeout_set(&timeout, DISP_DEFAULT_INTVAL); continue; } switch (flag) { case DISP_FLAG_QUIT: debug_print(NULL, 2, "disp: received DISP_FLAG_QUIT\n"); goto L_EXIT; case DISP_FLAG_CMD: cmd_received(&cmd, &quit, &timeout); if (quit) { debug_print(NULL, 2, "disp thread received CMD_QUIT_ID\n"); goto L_EXIT; } break; case DISP_FLAG_PROFILING_DATA_READY: case DISP_FLAG_CALLCHAIN_DATA_READY: case DISP_FLAG_LL_DATA_READY: case DISP_FLAG_PQOS_CMT_READY: /* * Show the page. */ (void) page_next_execute(B_FALSE); timeout_set(&timeout, DISP_DEFAULT_INTVAL); break; case DISP_FLAG_PROFILING_DATA_FAIL: case DISP_FLAG_CALLCHAIN_DATA_FAIL: case DISP_FLAG_LL_DATA_FAIL: case DISP_FLAG_PQOS_CMT_FAIL: /* * Received the notification that the perf counting * was failed. */ debug_print(NULL, 2, "disp: profiling/callchain/LL data failed.\n"); disp_go_home(); break; case DISP_FLAG_SCROLLUP: /* * User hits the "UP" key. */ key_scroll(SCROLL_UP); if (status == ETIMEDOUT) { timeout_set(&timeout, DISP_DEFAULT_INTVAL); } break; case DISP_FLAG_SCROLLDOWN: /* * User hits the "DOWN" key. */ key_scroll(SCROLL_DOWN); if (status == ETIMEDOUT) { timeout_set(&timeout, DISP_DEFAULT_INTVAL); } break; case DISP_FLAG_SCROLLENTER: /* * User selects a scroll item and hit the "ENTER". */ scroll_enter(); if (status == ETIMEDOUT) { timeout_set(&timeout, DISP_DEFAULT_INTVAL); } break; default: break; } } L_EXIT: if (pagelist_inited) { page_list_fini(); } /* * Let the perf thread exit first. */ perf_fini(); debug_print(NULL, 2, "disp thread is exiting\n"); return (NULL); }