Line data Source code
1 : /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 : /*
3 : * clock.c
4 : * This file is part of "Sauvegarde" project.
5 : *
6 : * (C) Copyright 2014 - 2016 Olivier Delhomme
7 : * e-mail : olivier.delhomme@free.fr
8 : *
9 : * "Sauvegarde" is free software: you can redistribute it and/or modify
10 : * it under the terms of the GNU General Public License as published by
11 : * the Free Software Foundation, either version 3 of the License, or
12 : * (at your option) any later version.
13 : *
14 : * "Sauvegarde" is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with "Sauvegarde". If not, see <http://www.gnu.org/licenses/>
21 : */
22 :
23 : /**
24 : * @file clock.c
25 : * This file contains the functions to measure time.
26 : */
27 :
28 : #include "libcdpfgl.h"
29 :
30 : /**
31 : * Creates a new clock_t structure filled accordingly
32 : * @returns a clock_t * structure with begin field set.
33 : */
34 338026 : a_clock_t *new_clock_t(void)
35 : {
36 338026 : a_clock_t * my_clock = NULL;
37 :
38 338026 : my_clock = (a_clock_t *) g_malloc0(sizeof(a_clock_t));
39 :
40 338026 : my_clock->end = NULL;
41 338026 : my_clock->begin = g_date_time_new_now_local();
42 :
43 338026 : return my_clock;
44 : }
45 :
46 :
47 : /**
48 : * Ends the clock and prints the elapsed time and then frees everything
49 : * @param my_clock is a clock_t * structure with begin already filled
50 : * @param message is a message that we want to include into the displayed
51 : * result in order to know what was measured.
52 : */
53 338026 : void end_clock(a_clock_t *my_clock, gchar *message)
54 : {
55 338026 : GTimeSpan difference = 0;
56 :
57 338026 : if (my_clock != NULL && my_clock->begin != NULL)
58 : {
59 338026 : my_clock->end = g_date_time_new_now_local();
60 338026 : difference = g_date_time_difference(my_clock->end, my_clock->begin);
61 :
62 338026 : g_date_time_unref(my_clock->begin);
63 338026 : g_date_time_unref(my_clock->end);
64 338026 : free_variable(my_clock);
65 :
66 338026 : print_debug(_("Elapsed time (%s): %d µs\n"), message, difference);
67 : }
68 338026 : }
69 :
70 :
71 :
|