static void* flush_thread_main(void *in) { hlld_config *config; hlld_setmgr *mgr; int *should_run; UNPACK_ARGS(); // Perform the initial checkpoint with the manager setmgr_client_checkpoint(mgr); syslog(LOG_INFO, "Flush thread started. Interval: %d seconds.", config->flush_interval); unsigned int ticks = 0; while (*should_run) { usleep(PERIODIC_TIME_USEC); setmgr_client_checkpoint(mgr); if ((++ticks % SEC_TO_TICKS(config->flush_interval)) == 0 && *should_run) { // Time how long this takes struct timeval start, end; gettimeofday(&start, NULL); // List all the sets syslog(LOG_INFO, "Scheduled flush started."); hlld_set_list_head *head; int res = setmgr_list_sets(mgr, NULL, &head); if (res != 0) { syslog(LOG_WARNING, "Failed to list sets for flushing!"); continue; } // Flush all, ignore errors since // sets might get deleted in the process hlld_set_list *node = head->head; unsigned int cmds = 0; while (node) { setmgr_flush_set(mgr, node->set_name); if (!(++cmds % PERIODIC_CHECKPOINT)) setmgr_client_checkpoint(mgr); node = node->next; } // Compute the elapsed time gettimeofday(&end, NULL); syslog(LOG_INFO, "Flushed %d sets in %d msecs", head->size, timediff_msec(&start, &end)); // Cleanup setmgr_cleanup_list(head); } } return NULL; }
static void* unmap_thread_main(void *in) { hlld_config *config; hlld_setmgr *mgr; int *should_run; UNPACK_ARGS(); // Perform the initial checkpoint with the manager setmgr_client_checkpoint(mgr); syslog(LOG_INFO, "Cold unmap thread started. Interval: %d seconds.", config->cold_interval); unsigned int ticks = 0; while (*should_run) { usleep(PERIODIC_TIME_USEC); setmgr_client_checkpoint(mgr); if ((++ticks % SEC_TO_TICKS(config->cold_interval)) == 0 && *should_run) { // Time how long this takes struct timeval start, end; gettimeofday(&start, NULL); // List the cold sets syslog(LOG_INFO, "Cold unmap started."); hlld_set_list_head *head; int res = setmgr_list_cold_sets(mgr, &head); if (res != 0) { continue; } // Close the sets, save memory hlld_set_list *node = head->head; unsigned int cmds = 0; while (node) { syslog(LOG_DEBUG, "Unmapping set '%s' for being cold.", node->set_name); setmgr_unmap_set(mgr, node->set_name); if (!(++cmds % PERIODIC_CHECKPOINT)) setmgr_client_checkpoint(mgr); node = node->next; } // Compute the elapsed time gettimeofday(&end, NULL); syslog(LOG_INFO, "Unmapped %d sets in %d msecs", head->size, timediff_msec(&start, &end)); // Cleanup setmgr_cleanup_list(head); } } return NULL; }
void execute_drag(int fd, uint32_t device_flags, int start_x, int start_y, int end_x, int end_y, int num_steps, int duration_msec) { int delta[] = {(end_x-start_x)/num_steps, (end_y-start_y)/num_steps}; double desired_interval_msec, avg_event_dispatch_time_msec; struct timespec start_time, current_time, time_before_last_move; int i; clock_gettime(CLOCK_MONOTONIC, &start_time); double start_nsecs = (double) (start_time.tv_sec * (1000*1000)) + start_time.tv_nsec; print_action(ACTION_START, "drag", "\"start_x\": %d, \"start_y\": %d, " "\"end_x\": %d, \"end_y\": %d, \"num_steps\": %d, " "\"duration_msec\": %d", start_x, start_y, end_x, end_y, num_steps, duration_msec); // press clock_gettime(CLOCK_MONOTONIC, &time_before_last_move); execute_press(fd, device_flags, start_x, start_y); // drag desired_interval_msec = duration_msec / num_steps; for (i=0; i<num_steps; i++) { clock_gettime(CLOCK_MONOTONIC, ¤t_time); avg_event_dispatch_time_msec = ((avg_event_dispatch_time_msec * i) + timediff_msec(&time_before_last_move, ¤t_time)) / i; if (desired_interval_msec > 0 && avg_event_dispatch_time_msec < desired_interval_msec) { execute_sleep(desired_interval_msec - avg_event_dispatch_time_msec); } memcpy(&time_before_last_move, ¤t_time, sizeof(struct timespec)); execute_move(fd, device_flags, start_x+delta[0]*i, start_y+delta[1]*i); } // release execute_release(fd, device_flags); // wait execute_sleep(100); print_action(ACTION_END, "drag", NULL); }
/** * Flushes the filter. Idempotent if the * filter is proxied or not dirty. * @arg filter The filter to close * @return 0 on success. */ int bloomf_flush(bloom_filter *filter) { // Only do things if we are non-proxied if (filter->sbf) { // Time how long this takes struct timeval start, end; gettimeofday(&start, NULL); // If our size has not changed, there is no need to flush uint64_t new_size = bloomf_size(filter); if (new_size == filter->filter_config.size && filter->filter_config.bytes != 0) { return 0; } // Store our properties for a future unmap filter->filter_config.size = new_size; filter->filter_config.capacity = bloomf_capacity(filter); filter->filter_config.bytes = bloomf_byte_size(filter); // Write out filter_config char *config_name = join_path(filter->full_path, (char*)CONFIG_FILENAME); int res = update_filename_from_filter_config(config_name, &filter->filter_config); free(config_name); if (res) { syslog(LOG_ERR, "Failed to write filter '%s' configuration. Err: %d.", filter->filter_name, res); } // Flush the filter res = 0; if (!filter->filter_config.in_memory) { res = sbf_flush((bloom_sbf*)filter->sbf); } // Compute the elapsed time gettimeofday(&end, NULL); syslog(LOG_INFO, "Flushed filter '%s'. Total time: %d msec.", filter->filter_name, timediff_msec(&start, &end)); return res; } return 0; }