summaryrefslogtreecommitdiff
path: root/sysinfo.c
diff options
context:
space:
mode:
authorhorchi <vdr@jwendel.de>2017-03-05 16:47:41 +0100
committerhorchi <vdr@jwendel.de>2017-03-05 16:47:41 +0100
commit22ffee20bbacbc3378e4ba0df5b7f0c3daaeffc0 (patch)
treede46c945c62d43d1febb027b5bfa075e58c5b69a /sysinfo.c
downloadvdr-plugin-graphtftng-22ffee20bbacbc3378e4ba0df5b7f0c3daaeffc0.tar.gz
vdr-plugin-graphtftng-22ffee20bbacbc3378e4ba0df5b7f0c3daaeffc0.tar.bz2
Diffstat (limited to 'sysinfo.c')
-rw-r--r--sysinfo.c158
1 files changed, 158 insertions, 0 deletions
diff --git a/sysinfo.c b/sysinfo.c
new file mode 100644
index 0000000..8de6e34
--- /dev/null
+++ b/sysinfo.c
@@ -0,0 +1,158 @@
+/*
+ * sysinfo.c: A plugin for the Video Disk Recorder
+ *
+ * See the README file for copyright information and how to reach the author.
+ *
+ * Date: 03.06.07
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include <glibtop.h>
+#include <glibtop/cpu.h>
+#include <glibtop/mem.h>
+
+#ifndef WITHOUT_VDR
+# include <vdr/tools.h>
+#endif
+
+#include <sysinfo.h>
+
+int Sysinfo::initialized = no;
+double Sysinfo::lastIdle = 0;
+double Sysinfo::lastTotal = 0;
+
+//***************************************************************************
+// Init
+//***************************************************************************
+
+int Sysinfo::init()
+{
+ if (initialized)
+ return done;
+
+#if LIBGTOP_MAJOR_VERSION > 2 || (LIBGTOP_MAJOR_VERSION == 2 && LIBGTOP_MINOR_VERSION >= 14)
+ tell(0, "init libgtop (%d.%d)",
+ LIBGTOP_MAJOR_VERSION, LIBGTOP_MINOR_VERSION);
+ glibtop_init();
+#endif
+
+ initialized = yes;
+
+ return done;
+}
+
+//***************************************************************************
+// Init
+//***************************************************************************
+
+int Sysinfo::exit()
+{
+ if (!initialized)
+ return done;
+
+#if LIBGTOP_MAJOR_VERSION > 2 || (LIBGTOP_MAJOR_VERSION == 2 && LIBGTOP_MINOR_VERSION >= 14)
+ glibtop_close();
+#endif
+
+ initialized = no;
+
+ return done;
+
+}
+
+//***************************************************************************
+// Get CPU Load
+//***************************************************************************
+
+int Sysinfo::cpuLoad()
+{
+ static uint64_t lastCall = 0;
+ static int lastLoad = na;
+
+ if (!initialized)
+ init();
+
+ int load;
+ glibtop_cpu cpu;
+
+#ifndef WITHOUT_VDR
+ if (lastCall && lastLoad != na && cTimeMs::Now() - lastCall < 200)
+ return lastLoad;
+#endif
+
+ glibtop_get_cpu(&cpu);
+
+ double total = ((unsigned long)cpu.total) ? ((double)cpu.total) : 1.0;
+ double idle = ((unsigned long)cpu.idle) ? ((double)cpu.idle) : 1.0;
+
+ total /= (double)cpu.frequency;
+ idle /= (double)cpu.frequency;
+
+ // calc tic deltas (from last)
+
+ double loadTics = total- idle - lastTotal;
+ double idleTics = idle - lastIdle;
+
+ // calc load
+
+ load = (int) (loadTics * 100 / (loadTics + idleTics));
+
+ // remember
+
+ lastTotal = total - idle;
+ lastIdle = idle;
+ lastLoad = load;
+
+#ifndef WITHOUT_VDR
+ lastCall = cTimeMs::Now();
+#endif
+
+ return load;
+}
+
+//***************************************************************************
+// Get Memory Info
+//***************************************************************************
+
+int Sysinfo::memInfoMb(unsigned long& total,
+ unsigned long& used,
+ unsigned long& free,
+ unsigned long& cached)
+{
+ glibtop_mem memory;
+
+ if (!initialized)
+ init();
+
+ glibtop_get_mem(&memory);
+
+ total = (unsigned long)memory.total/(1024*1024);
+ used = (unsigned long)memory.used/(1024*1024);
+ free = (unsigned long)memory.free/(1024*1024);
+ cached = (unsigned long)memory.cached/(1024*1024);
+
+ /*
+ tell(4, "\nMEMORY USING\n\n"
+ "Memory Total : %ld MB\n"
+ "Memory Used : %ld MB\n"
+ "Memory Free : %ld MB\n"
+ "Memory Buffered : %ld MB\n"
+ "Memory Cached : %ld MB\n"
+ "Memory user : %ld MB\n"
+ "Memory Locked : %ld MB\n",
+ total, used, free,
+ (unsigned long)memory.shared/(1024*1024),
+ (unsigned long)memory.buffer/(1024*1024),
+ (unsigned long)memory.cached/(1024*1024),
+ (unsigned long)memory.user/(1024*1024),
+ (unsigned long)memory.locked/(1024*1024));
+ */
+
+ return done;
+}
+
+//***************************************************************************
+