[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r11519 - gnunet/src/util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r11519 - gnunet/src/util |
Date: |
Wed, 26 May 2010 10:32:41 +0200 |
Author: grothoff
Date: 2010-05-26 10:32:41 +0200 (Wed, 26 May 2010)
New Revision: 11519
Modified:
gnunet/src/util/os_load.c
Log:
keep /proc/stat FD closed unless it is actually needed
Modified: gnunet/src/util/os_load.c
===================================================================
--- gnunet/src/util/os_load.c 2010-05-26 08:18:05 UTC (rev 11518)
+++ gnunet/src/util/os_load.c 2010-05-26 08:32:41 UTC (rev 11519)
@@ -58,7 +58,16 @@
#define DEBUG_STATUSCALLS GNUNET_NO
#ifdef LINUX
+/**
+ * File descriptor for reading /proc/stat (or NULL)
+ */
static FILE *proc_stat;
+
+/**
+ * Is this the first time we're trying to open /proc/stat? If
+ * not, we don't try again if we failed...
+ */
+static int first_time;
#endif
/**
@@ -112,6 +121,7 @@
}
#endif
+
/**
* Update the currentCPU and currentIO load values.
*
@@ -127,6 +137,13 @@
/* under linux, first try %idle/usage using /proc/stat;
if that does not work, disable /proc/stat for the future
by closing the file and use the next-best method. */
+ if (0 == first_time)
+ {
+ first_time = 1;
+ proc_stat = fopen ("/proc/stat", "r");
+ if (NULL == proc_stat)
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen",
"/proc/stat");
+ }
if (proc_stat != NULL)
{
static unsigned long long last_cpu_results[5] = { 0, 0, 0, 0, 0 };
@@ -620,15 +637,24 @@
void __attribute__ ((constructor)) GNUNET_cpustats_ltdl_init ()
{
#ifdef LINUX
- proc_stat = fopen ("/proc/stat", "r");
- if (NULL == proc_stat)
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "fopen", "/proc/stat");
+ updateUsage (); /* initialize */
+ /* Most GNUnet processes don't really need this, so close the FD, but allow
+ re-opening it (unless we failed) */
+ if (proc_stat != NULL)
+ {
+ GNUNET_break (0 == fclose (proc_stat));
+ proc_stat = NULL;
+ first_time = 0;
+ }
#elif defined(DARWIN)
initMachCpuStats ();
+ updateUsage (); /* initialize */
#elif MINGW
InitWinEnv (NULL);
+ updateUsage (); /* initialize */
+#else
+ updateUsage (); /* initialize */
#endif
- updateUsage (); /* initialize */
}
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r11519 - gnunet/src/util,
gnunet <=