Exemple #1
0
/**
 * Called every period to heartbeat the callout queue.
 */
static void
cq_heartbeat(cqueue_t *cq)
{
	tm_t tv;
	time_delta_t delay;

	cqueue_check(cq);

	/*
	 * How much milliseconds elapsed since last heart beat?
	 */

	mutex_lock(&cq->cq_lock);

	tm_now_exact(&tv);
	delay = tm_elapsed_ms(&tv, &cq->cq_last_heartbeat);
	cq->cq_last_heartbeat = tv;		/* struct copy */

	/*
	 * If too much variation, or too little, maybe the clock was adjusted.
	 * Assume a single period then.
	 */

	if (delay < 0 || delay > 10 * cq->cq_period)
		delay = cq->cq_period;

	/*
	 * We hold the mutex when calling cq_clock(), and it will be released there.
	 */

	cq_clock(cq, delay);
}
Exemple #2
0
/**
 * Display the data gathered during the last time period.
 * Perhaps it would be better to have this done on a button click(?)
 */
static void
search_stats_gui_update_display(void)
{
    gboolean sorting_disabled;
    tm_t start_time, end_time;
    time_delta_t elapsed;

    stat_count = 0;
    g_object_freeze_notify(G_OBJECT(treeview_search_stats));
    gtk_list_store_clear(store_search_stats);

    /*
     * Temporarily disable sorting while inserting the updated table.
     * Otherwise, CPU is overloaded with sorting every addition
     *  to the hash table.
     */
    sorting_disabled = FALSE;
    tm_now_exact(&start_time);
    if (store_search_stats->sort_column_id >= 0) {
        sorting_disabled = TRUE;
        search_stats_gui_sort_save();
    }
    /* insert the hash table contents into the sorted treeview */
    htable_foreach_remove(stat_hash, stats_hash_to_treeview, NULL);

    tm_now_exact(&end_time);
    elapsed = tm_elapsed_ms(&end_time, &start_time);

    /*
     * Re-enable sorting if previously disabled.
     * If too much time has elapsed, leave sorting disabled.
     */
    if (sorting_disabled && elapsed < 100) {
        search_stats_gui_sort_restore();
    } else if (!sorting_disabled && elapsed > 200) {
        /*
         * If sorting is disabled, and too much time is still elapsing,
         * then the search stats collection will need to be
         * discontinued
         */
        search_stats_gui_reset();
        search_stats_gui_disable();
        search_stats_gui_overload = TRUE;
    }

    if (search_stats_gui_overload) {
        /* update status bar message */
        gtk_label_set_text(GTK_LABEL(label_search_stats_count),
                           "Disabling Search Stats due to system load" );
    } else {
        /* update the status bar counter */
        gtk_label_printf(GTK_LABEL(label_search_stats_count),
                         NG_("%u term counted", "%u terms counted", stat_count),
                         stat_count);
    }
    g_object_thaw_notify(G_OBJECT(treeview_search_stats));
}