static gboolean gdm_display_real_unmanage (GdmDisplay *display) { gdouble elapsed; g_return_val_if_fail (GDM_IS_DISPLAY (display), FALSE); g_debug ("GdmDisplay: unmanage display"); g_timer_stop (display->priv->slave_timer); if (display->priv->slave_proxy != NULL) { gdm_slave_proxy_stop (display->priv->slave_proxy); g_object_unref (display->priv->slave_proxy); display->priv->slave_proxy = NULL; } if (display->priv->user_access_file != NULL) { gdm_display_access_file_close (display->priv->user_access_file); g_object_unref (display->priv->user_access_file); display->priv->user_access_file = NULL; } if (display->priv->access_file != NULL) { gdm_display_access_file_close (display->priv->access_file); g_object_unref (display->priv->access_file); display->priv->access_file = NULL; } elapsed = g_timer_elapsed (display->priv->slave_timer, NULL); if (elapsed < 3) { g_warning ("GdmDisplay: display lasted %lf seconds", elapsed); _gdm_display_set_status (display, GDM_DISPLAY_FAILED); } else { _gdm_display_set_status (display, GDM_DISPLAY_UNMANAGED); } return TRUE; }
bool audio_output_update(struct audio_output *ao, const struct audio_format *audio_format, const struct music_pipe *mp) { assert(mp != NULL); g_mutex_lock(ao->mutex); if (ao->enabled && ao->really_enabled) { if (ao->fail_timer == NULL || g_timer_elapsed(ao->fail_timer, NULL) > REOPEN_AFTER) { bool success = audio_output_open(ao, audio_format, mp); g_mutex_unlock(ao->mutex); return success; } } else if (audio_output_is_open(ao)) audio_output_close_locked(ao); g_mutex_unlock(ao->mutex); return false; }
static void launch_test (const char *binary) { gboolean success = TRUE; GTimer *btimer = g_timer_new(); gboolean need_restart; testcase_count = 0; testcase_fail_count = 0; if (!gtester_quiet) g_print ("TEST: %s... ", binary); retry: test_log_printfe ("%s<testbinary path=\"%s\">\n", sindent (log_indent), binary); log_indent += 2; g_timer_start (btimer); subtest_exitstatus = 0; success &= launch_test_binary (binary, testcase_count); success &= subtest_exitstatus == 0; need_restart = testcase_open != 0; if (testcase_open) testcase_close (0, -256, 0); g_timer_stop (btimer); test_log_printfe ("%s<duration>%.6f</duration>\n", sindent (log_indent), g_timer_elapsed (btimer, NULL)); log_indent -= 2; test_log_printfe ("%s</testbinary>\n", sindent (log_indent)); g_free (subtest_last_seed); subtest_last_seed = NULL; if (need_restart) { /* restart test binary, skipping processed test cases */ goto retry; } if (!gtester_quiet) g_print ("%s: %s\n", testcase_fail_count || !success ? "FAIL" : "PASS", binary); g_timer_destroy (btimer); if (subtest_mode_fatal && !success) terminate(); }
void pluma_debug (PlumaDebugSection section, const gchar *file, gint line, const gchar *function) { if (G_UNLIKELY (debug & section)) { #ifdef ENABLE_PROFILING gdouble seconds; g_return_if_fail (timer != NULL); seconds = g_timer_elapsed (timer, NULL); g_print ("[%f (%f)] %s:%d (%s)\n", seconds, seconds - last, file, line, function); last = seconds; #else g_print ("%s:%d (%s)\n", file, line, function); #endif fflush (stdout); } }
/* * Print a debug line with file and line number and a message */ void iris_debug_message (IrisDebugSection section, const gchar *file, gint line, const gchar *function, const gchar *format, ...) { if (G_UNLIKELY (debug & section)) { IrisThread *thread = iris_thread_get (); #ifdef ENABLE_PROFILING gdouble seconds; #endif va_list args; gchar *msg; g_return_if_fail (format != NULL); va_start (args, format); msg = g_strdup_vprintf (format, args); va_end (args); #ifdef ENABLE_PROFILING g_return_if_fail (timer != NULL); seconds = g_timer_elapsed (timer, NULL); g_print ("[%f (%f)] [Thread=%lx] %s:%d (%s) %s\n", seconds, seconds - last, (gulong)thread, file, line, function, msg); last = seconds; #else g_print ("[Thread=%lx] %s:%d (%s) %s\n", (gulong)thread, file, line, function, msg); #endif fflush (stdout); g_free (msg); } }
/** * li_daemon_timeout_check_cb: **/ static gboolean li_daemon_timeout_check_cb (LiHelperDaemon *helper) { guint idle; /* we don't do anything when a job is running */ if (li_daemon_job_is_running (helper->job)) { li_daemon_reset_timer (helper); return TRUE; } idle = (guint) g_timer_elapsed (helper->timer, NULL); g_debug ("idle is %i", idle); if (idle > helper->exit_idle_time) { g_main_loop_quit (helper->loop); helper->timer_id = 0; return FALSE; } return TRUE; }
static void shutdown_state_dispatch(ShutdownEvent *event) { ShutdownState next_state = gCurrentState->state; bool running = true; while (running) { running = gCurrentState->function(event, &next_state); _assert(next_state >= gCurrentState->state); if (next_state != gCurrentState->state) { SLEEPDLOG(LOG_DEBUG, "Shutdown: entering state: %s @ %fs", kStateMachine[next_state].name, g_timer_elapsed(shutdown_timer, NULL)); } gCurrentState = &kStateMachine[next_state]; } }
gboolean MiracBroker::connect_cb (gint fd, GIOCondition condition) { try { if (!network_->Connect(NULL, NULL)) return G_SOURCE_CONTINUE; WDS_LOG("connection success to: %s", network_->GetPeerAddress().c_str()); connection(network_.release()); /* make sure any network event sources are removed */ network(NULL); on_connected(); } catch (const std::exception &x) { gdouble elapsed = 1000 * g_timer_elapsed(connect_timer_, NULL); if (elapsed + connect_wait_ > connect_timeout_) { on_connection_failure(CONNECTION_TIMEOUT); } else { connect_wait_id_ = g_timeout_add (connect_wait_, try_connect, this); } } return G_SOURCE_REMOVE; }
gboolean lead_user_cb (gpointer data) { render_priv *priv = data; Coord step; double elapsed_time; /* Queue a redraw */ ghid_invalidate_all (); /* Update radius */ elapsed_time = g_timer_elapsed (priv->lead_user_timer, NULL); g_timer_start (priv->lead_user_timer); step = MM_TO_COORD (LEAD_USER_VELOCITY * elapsed_time); if (priv->lead_user_radius > step) priv->lead_user_radius -= step; else priv->lead_user_radius = MM_TO_COORD (LEAD_USER_INITIAL_RADIUS); return TRUE; }
void ipmsg_wait_ms(const int wait_ms){ GTimer *wait_timer = NULL; gulong elapsed = 0; gint remains_ms = 0; wait_timer = g_timer_new(); g_assert(wait_timer != NULL); for(remains_ms = wait_ms;remains_ms > 0; --remains_ms) { g_timer_start(wait_timer); for(elapsed = 0; elapsed < 1000UL;g_timer_elapsed(wait_timer, &elapsed)) { ipmsg_update_ui(); /* 待ちループ */ } } g_timer_destroy(wait_timer); return; }
static int get_active_frame(topview * t) { gulong microseconds; gdouble seconds; int fr; seconds = g_timer_elapsed(view->timer, µseconds); fr = (int) (seconds / ((double) view->frame_length / (double) 1000)); if (fr < view->total_frames) { if (fr == view->active_frame) return 0; else { view->active_frame = fr; return 1; } } else { g_timer_stop(view->timer); view->Topview->fisheyeParams.animate = 0; return 0; } }
BP_EXPORT void bp_scene_draw (scene_t * scene) { unsigned int i; GTimer *timer; timer = g_timer_new (); g_timer_reset (timer); g_timer_start (timer); #if 0 ADD (background, scene->settings.atmosphere.background, scene->settings.atmosphere.ambient_light); #else ASSIGN (background, scene->settings.atmosphere.background); #endif for (i = 0; i < scene->settings.num_threads; i++) { int rc = pthread_create (&threads [i], &thread_attr, draw_scanlines, &thread_args [i]); if (rc) { printf("ERROR; thread %d return code from pthread_create() is %d\n", i + 1,rc); exit(-1); } } for (i = 0; i < scene->settings.num_threads; i++) { int rc = pthread_join(threads[i], NULL); if (rc) { printf("ERROR; return code from pthread_join() is %d\n", rc); exit(-1); } } g_timer_stop (timer); gulong microseconds; /* not really usefully but needed by the timing code */ printf ("Drawing took %f.\n", g_timer_elapsed (timer, µseconds)); }
static void switch_to_page (OfficeRunner *run, int page) { gtk_notebook_set_current_page (GTK_NOTEBOOK (run->notebook), page); switch (page) { case RUN_PAGE: set_running_settings (run, TRUE); gtk_label_set_text (GTK_LABEL (WID ("run_button_label")), _("Run!")); break; case RUNNING_PAGE: { set_running_settings (run, TRUE); disable_block_timeout (run); run->timer = g_timer_new (); run->timeout = gtk_widget_add_tick_callback (run->time_label, count_tick, run, NULL); gtk_label_set_text (GTK_LABEL (WID ("run_button_label")), _("Done!")); break; } case SCORES_PAGE: { run->elapsed = g_timer_elapsed (run->timer, NULL); g_timer_destroy (run->timer); run->timer = NULL; gtk_widget_remove_tick_callback (run->time_label, run->timeout); run->timeout = 0; gtk_label_set_text (GTK_LABEL (WID ("run_button_label")), _("Try Again")); set_records_page (run); /* This should be enough time for the machine to go to sleep */ set_running_settings (run, FALSE); run->reenable_block_id = g_timeout_add_seconds (3, reenable_block_timeout_cb, run); break; } } }
/* update the animation information for each widget. This will also queue a redraw * and stop the animation if it is done. */ static gboolean qtcAnimationUpdateInfo(gpointer key, gpointer value, gpointer user_data) { QTC_UNUSED(user_data); AnimationInfo *animation_info = value; GtkWidget *widget = key; if ((widget == NULL) || (animation_info == NULL)) g_assert_not_reached(); /* remove the widget from the hash table if it is not drawable */ if (!gtk_widget_is_drawable(widget)) return TRUE; if (GTK_IS_PROGRESS_BAR(widget)) { gfloat fraction = gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(widget)); /* stop animation for filled/not filled progress bars */ if (fraction <= 0.0 || fraction >= 1.0) { return TRUE; } } else if (GTK_IS_ENTRY(widget)) { gfloat fraction = gtk_entry_get_progress_fraction(GTK_ENTRY(widget)); /* stop animation for filled/not filled progress bars */ if(fraction <= 0.0 || fraction >= 1.0) { return TRUE; } } force_widget_redraw(widget); /* stop at stop_time */ if(animation_info->stop_time != 0 && g_timer_elapsed(animation_info->timer, NULL) > animation_info->stop_time) return TRUE; return FALSE; }
int fpi_img_compare_print_data(struct fp_print_data *enrolled_print, struct fp_print_data *new_print) { struct xyt_struct *gstruct = (struct xyt_struct *) enrolled_print->data; struct xyt_struct *pstruct = (struct xyt_struct *) new_print->data; GTimer *timer; int r; if (enrolled_print->type != PRINT_DATA_NBIS_MINUTIAE || new_print->type != PRINT_DATA_NBIS_MINUTIAE) { fp_err("invalid print format"); return -EINVAL; } timer = g_timer_new(); r = bozorth_main(pstruct, gstruct); g_timer_stop(timer); fp_dbg("bozorth processing took %f seconds, score=%d", g_timer_elapsed(timer, NULL), r); g_timer_destroy(timer); return r; }
void vsg_packed_msg_trace (gchar *format, ...) { gdouble seconds; gulong microseconds; va_list ap; if (! _trace_active) return; _trace_file_open (); seconds = g_timer_elapsed (_timer, NULL); microseconds = (glong) (seconds * 1.e6); g_fprintf (_trace_file, "%lu: # ", microseconds); va_start (ap, format); g_vfprintf (_trace_file, format, ap); va_end (ap); g_fprintf (_trace_file, "\n"); fflush (_trace_file); }
static void run_child (GIOChannel *in_channel, GIOChannel *out_channel) { int i; int val = 1; GTimer *timer = g_timer_new(); for (i = 0; i < n_iters; i++) { write_all (out_channel, (char *)&val, sizeof (val)); read_all (in_channel, (char *)&val, sizeof (val)); } val = 0; write_all (out_channel, (char *)&val, sizeof (val)); val = g_timer_elapsed (timer, NULL) * 1000; write_all (out_channel, (char *)&val, sizeof (val)); g_timer_destroy (timer); exit (0); }
static gboolean printTimeElapsed(GtkWidget *timeElapsedLabel) { int timeElapsed; gchar *timeToSet = NULL; if (timerMode > 0) { timeElapsed = (int)g_timer_elapsed(timer, NULL); int min = (int)timeElapsed / 60.0; int sec = timeElapsed % 60; timeToSet = g_strdup_printf("%02d:%02d", min, sec); gtk_label_set_text(GTK_LABEL(timeElapsedLabel), timeToSet); g_free(timeToSet); } else { gtk_label_set_text(GTK_LABEL(timeElapsedLabel), "00:00"); } return TRUE; }
void benchmark_fib(void) { GTimer *timer = g_timer_new(); bench_value r = EMPTY_BENCH_VALUE; shell_view_set_enabled(FALSE); shell_status_update("Calculating the 42nd Fibonacci number..."); g_timer_reset(timer); g_timer_start(timer); fib(42); g_timer_stop(timer); r.elapsed_time = g_timer_elapsed(timer, NULL); g_timer_destroy(timer); r.threads_used = 1; r.result = r.elapsed_time; bench_results[BENCHMARK_FIB] = r; }
void remote_client_merge_results (RemoteClient* self, IterativeMap* dest) { double elapsed; /* Don't let our stream requests get too backed up */ if (self->pending_stream_requests >= 4) return; /* Always keep the status updated */ remote_client_command(self, status_merge_callback, dest, "calc_status"); /* Have we waited long enough since the last request? */ elapsed = g_timer_elapsed(self->stream_request_timer, NULL); if (elapsed < self->min_stream_interval) return; g_timer_start(self->stream_request_timer); self->pending_stream_requests++; remote_client_command(self, histogram_merge_callback, dest, "get_histogram_stream"); }
int main(int argc, char *argv[]) { GRand *rand; GTimer *timer; gint n; gint i, j; gint x = 0; //创建随机数 rand = g_rand_new(); for(n=0; n < 20; n++) { g_print("%d ", g_rand_int_range(rand, 1, 100)); } g_print("\n"); g_rand_free(rand); //创建计时器 timer = g_timer_new(); //开启计时 g_timer_start(timer); for (i=0; i< 10000; i++) for (j=0; j < 100000; j++) x++; //停止计时 g_timer_stop(timer); //计算耗时 g_printf("%ld\tall:%.2f seconds was used!\n",x, g_timer_elapsed(timer, NULL)); g_free(timer); return 0; }
void test5() { sc_uint32 i; sc_addr addr; sc_stream *stream = 0; printf("Segments count: %d\n", sc_storage_get_segments_count()); print_storage_statistics(); timer = g_timer_new(); printf("Create %d links\n", link_append_count); //g_snprintf(test, 1024, "../CMakeLists.txt"); g_timer_reset(timer); g_timer_start(timer); for (i = 0; i < link_append_count; i++) { addr = sc_storage_link_new(); printf("Created sc-link: seg=%d, offset=%d, content=%d\n", addr.seg, addr.offset, i); stream = sc_stream_memory_new((char*)&i, sizeof(i), SC_STREAM_READ, SC_FALSE); sc_storage_set_link_content(addr, stream); sc_stream_free(stream); } g_timer_stop(timer); printf("Created links: %d\n", link_append_count); printf("Links per second: %f\n", link_append_count / g_timer_elapsed(timer, 0)); printf("Segments count: %d\n", sc_storage_get_segments_count()); print_storage_statistics(); g_timer_destroy(timer); }
/* update the animation information for each widget. This will also queue a redraw * and stop the animation if it is done. */ static gboolean update_animation_info (gpointer key, gpointer value, gpointer user_data) { AnimationInfo *animation_info = value; GtkWidget *widget = key; gdouble elapsed; if ((widget == NULL) || (animation_info == NULL)) g_assert_not_reached (); /* remove the widget from the hash table if it is not drawable */ if (!GTK_WIDGET_DRAWABLE (widget)) return TRUE; if (GTK_IS_PROGRESS_BAR (widget)) { gfloat fraction = gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (widget)); /* stop animation for filled/not filled progress bars */ if (fraction <= 0.0 || fraction >= 1.0) return TRUE; animation_info->update_delay--; if (animation_info->update_delay <= 0) { animation_info->update_delay = PROGRESSBAR_DELAY; force_widget_redraw (widget); } } else force_widget_redraw (widget); /* stop at stop_time */ if (animation_info->stop_time != 0 && g_timer_elapsed (animation_info->timer, NULL) > animation_info->stop_time) return TRUE; return FALSE; }
int main (int argc, char **argv) { GTimer *timer; int i,j; gtk_init (&argc, &argv); GdkPixbuf *pixbuf[4], *ret; pixbuf[0] = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 400, 600); pixbuf[1] = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 40, 60); pixbuf[2] = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 400, 600); pixbuf[3] = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 40, 60); for (j=0; j<4; j++) fill_pixbuf (pixbuf[j]); timer = g_timer_new (); g_timer_start (timer); for (i = 0; i < 10 ; i++) { for (j=0; j<4; j++) { ret = gdk_pixbuf_scale_simple (pixbuf[j], 700, 900, GDK_INTERP_BILINEAR); gdk_pixbuf_unref (ret); ret = gdk_pixbuf_scale_simple (pixbuf[j], 20, 50, GDK_INTERP_BILINEAR); gdk_pixbuf_unref (ret); } } g_timer_stop (timer); total_seconds += g_timer_elapsed (timer, NULL); g_print ("time spent scaling (in seconds): %lf\n", total_seconds ); return 0; }
MpdData *magnatune_db_get_album_list(char *wanted_genre,char *wanted_artist) { int r; MpdData *list = NULL; /** check if there is data */ char *query = sqlite3_mprintf("SELECT albumname from 'albums' WHERE artist=%Q",wanted_artist); sqlite3_stmt *stmt = NULL; const char *tail; GTimer *timer = g_timer_new(); r = sqlite3_prepare_v2(magnatune_sqlhandle, query, -1, &stmt, &tail); if(r ==SQLITE_OK) { while((r = sqlite3_step(stmt)) == SQLITE_ROW) { sqlite3_stmt *stmt2 = NULL; const char *tail2; char *query2 = sqlite3_mprintf("SELECT albumname from 'genres' WHERE albumname=%Q AND genre=%Q", sqlite3_column_text(stmt,0),wanted_genre); int r2 = sqlite3_prepare_v2(magnatune_sqlhandle, query2, -1, &stmt2, &tail2); if(r2 ==SQLITE_OK) { while((r2 = sqlite3_step(stmt2)) == SQLITE_ROW) { list = mpd_new_data_struct_append(list); list->type = MPD_DATA_TYPE_TAG; list->tag_type = MPD_TAG_ITEM_ALBUM; list->tag = g_strdup(sqlite3_column_text(stmt2,0)); } } sqlite3_finalize(stmt2); sqlite3_free(query2); } } sqlite3_finalize(stmt); sqlite3_free(query); g_debug("%f s elapsed listing albums songs\n", g_timer_elapsed(timer,NULL)); g_timer_destroy(timer); return mpd_data_get_first(list); }
void pluma_debug_message (PlumaDebugSection section, const gchar *file, gint line, const gchar *function, const gchar *format, ...) { if (G_UNLIKELY (debug & section)) { #ifdef ENABLE_PROFILING gdouble seconds; g_return_if_fail (timer != NULL); #endif va_list args; gchar *msg; g_return_if_fail (format != NULL); va_start (args, format); msg = g_strdup_vprintf (format, args); va_end (args); #ifdef ENABLE_PROFILING seconds = g_timer_elapsed (timer, NULL); g_print ("[%f (%f)] %s:%d (%s) %s\n", seconds, seconds - last, file, line, function, msg); last = seconds; #else g_print ("%s:%d (%s) %s\n", file, line, function, msg); #endif fflush (stdout); g_free (msg); } }
static gpointer test_threads_thread_func3 (gpointer data) { GstTocSetter *setter = GST_TOC_SETTER (data); GTimer *timer; timer = g_timer_new (); g_atomic_int_inc (&threads_running); while (g_atomic_int_get (&spin_and_wait)) g_usleep (0); GST_INFO ("Go!"); g_timer_start (timer); while (g_timer_elapsed (timer, NULL) < THREADS_TEST_SECONDS) { gst_toc_setter_reset (setter); } g_timer_destroy (timer); GST_INFO ("Done"); return NULL; }
static void on_paint (ClutterActor *actor, gconstpointer *data) { static GTimer *timer = NULL; static int fps = 0; if (!timer) { timer = g_timer_new (); g_timer_start (timer); } if (g_timer_elapsed (timer, NULL) >= 1) { printf ("fps=%d, strings/sec=%d, chars/sec=%d\n", fps, fps * rows * cols, fps * rows * cols * n_chars); g_timer_start (timer); fps = 0; } ++fps; }
static void on_percent (FmFileOpsJob *job, guint percent, FmProgressDisplay *data) { if (data->dlg) { GTimeVal cur_time; char percent_text[64]; g_snprintf (percent_text, 64, "%d %%", percent); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (data->progress), (gdouble)percent/100); gtk_progress_bar_set_text (GTK_PROGRESS_BAR (data->progress), percent_text); gdouble elapsed = g_timer_elapsed (data->timer, NULL); if (elapsed >= 0.5) { gdouble remaining = elapsed * (100 - percent) / percent; if (data->remaining_time) { char time_str[32]; guint secs = (guint)remaining; guint mins = 0; guint hrs = 0; if (secs > 60) { mins = secs / 60; secs %= 60; if (mins > 60) { hrs = mins / 60; mins %= 60; } } g_snprintf (time_str, 32, "%02d:%02d:%02d", hrs, mins, secs); gtk_label_set_text (GTK_LABEL (data->remaining_time), time_str); } } } }
gboolean find_entry(GHashTable* pht, gchar* key, gboolean verbose_in) { gchar* str; GTimer* tmp_timer = NULL; if (pht == NULL) { g_error("NULL hash table"); } if (verbose_in) { tmp_timer=g_timer_new(); //g_timer_start(my_timer); } str = g_hash_table_lookup(ht, key); if (verbose_in) { g_timer_stop(tmp_timer); printf("Found key=%s with value %s in %lf\n", key, str, g_timer_elapsed(tmp_timer, NULL)); g_timer_destroy(tmp_timer); } if (str != NULL) { return(TRUE); } else { return(FALSE); } }