drm/i915: Remove a duplicated assignment
[dragonfly.git] / contrib / mpfr / src / logging.c
blob7b3f8c5d731f0ce56698d49e814c207febd81383
1 /* MPFR Logging functions.
3 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
4 Contributed by the AriC and Caramel projects, INRIA.
6 This file is part of the GNU MPFR Library.
8 The GNU MPFR Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
13 The GNU MPFR Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MPFR Library; see the file COPYING.LESSER. If not, see
20 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
23 #include "mpfr-impl.h"
25 /* Logging MPFR needs GCC >= 3.0 and GLIBC >= 2.0. */
27 #ifdef MPFR_USE_LOGGING
29 /* Can't include them before (in particular, printf.h) */
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <time.h>
34 /* Define LOGGING variables */
36 FILE *mpfr_log_file;
37 int mpfr_log_type;
38 int mpfr_log_level;
39 int mpfr_log_current;
40 int mpfr_log_worstcase_limit;
41 mpfr_prec_t mpfr_log_prec;
43 static void mpfr_log_begin (void) __attribute__((constructor));
45 /* We let the system close the LOG itself
46 (Otherwise functions called by destructor can't use LOG File */
47 static void
48 mpfr_log_begin (void)
50 const char *var;
51 time_t tt;
53 /* Grab some information */
54 var = getenv ("MPFR_LOG_LEVEL");
55 mpfr_log_level = var == NULL || *var == 0 ? 7 : atoi (var);
56 mpfr_log_current = 0;
58 var = getenv ("MPFR_LOG_PREC");
59 mpfr_log_prec = var == NULL ? 6 : atol (var);
61 /* Get what we need to log */
62 mpfr_log_type = 0;
63 if (getenv ("MPFR_LOG_INPUT") != NULL)
64 mpfr_log_type |= MPFR_LOG_INPUT_F;
65 if (getenv ("MPFR_LOG_OUTPUT") != NULL)
66 mpfr_log_type |= MPFR_LOG_OUTPUT_F;
67 if (getenv ("MPFR_LOG_TIME") != NULL)
68 mpfr_log_type |= MPFR_LOG_TIME_F;
69 if (getenv ("MPFR_LOG_INTERNAL") != NULL)
70 mpfr_log_type |= MPFR_LOG_INTERNAL_F;
71 if (getenv ("MPFR_LOG_MSG") != NULL)
72 mpfr_log_type |= MPFR_LOG_MSG_F;
73 if (getenv ("MPFR_LOG_ZIV") != NULL)
74 mpfr_log_type |= MPFR_LOG_BADCASE_F;
75 if (getenv ("MPFR_LOG_STAT") != NULL)
76 mpfr_log_type |= MPFR_LOG_STAT_F;
77 if (getenv ("MPFR_LOG_ALL") != NULL)
78 mpfr_log_type = MPFR_LOG_INPUT_F|MPFR_LOG_OUTPUT_F|MPFR_LOG_TIME_F
79 |MPFR_LOG_INTERNAL_F|MPFR_LOG_MSG_F|MPFR_LOG_BADCASE_F|MPFR_LOG_STAT_F;
81 /* Open filename if needed */
82 var = getenv ("MPFR_LOG_FILE");
83 if (var == NULL || *var == 0)
84 var = "mpfr.log";
85 if (mpfr_log_type != 0)
87 mpfr_log_file = fopen (var, "w");
88 if (mpfr_log_file == NULL)
90 fprintf (stderr, "MPFR LOG: Can't open '%s' with w.\n", var);
91 abort ();
93 time (&tt);
94 fprintf (mpfr_log_file, "MPFR LOG FILE %s\n", ctime (&tt));
98 /* Return user CPU time measured in milliseconds. Thanks to Torbjorn. */
100 #if defined (ANSIONLY) || defined (USG) || defined (__SVR4) \
101 || defined (_UNICOS) || defined(__hpux)
104 mpfr_get_cputime (void)
106 return (int) ((unsigned long long) clock () * 1000 / CLOCKS_PER_SEC);
109 #else /* Use getrusage for cputime */
111 #include <sys/types.h>
112 #include <sys/resource.h>
115 mpfr_get_cputime (void)
117 struct rusage rus;
118 getrusage (0, &rus);
119 return rus.ru_utime.tv_sec * 1000 + rus.ru_utime.tv_usec / 1000;
122 #endif /* cputime */
124 #endif /* MPFR_USE_LOGGING */