summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Dominic P. Guana <guana.histark@gmail.com>2021-08-21 16:17:13 +0000
committerRobert Roth <robert.roth.off@gmail.com>2022-03-28 12:32:26 +0000
commitf92f6ea029e62023aecb7a29d98f102e7e13f544 (patch)
tree2a104ce918400ce2346f180e38f9d85d524895a6
parente89475c0b22108a24faaa1bded7b9beef5f235ce (diff)
downloadlibgtop-f92f6ea029e62023aecb7a29d98f102e7e13f544.tar.gz
Add sysinfo example
Retrieve cpu model via hashtable & number of logical cpu via exposed variable Signed off: Dr. James Dominic P. Guana <jdpguana@histark.com>
-rw-r--r--examples/sysinfo.c5
-rw-r--r--include/glibtop/sysinfo.h1
-rw-r--r--sysdeps/linux/sysinfo.c20
3 files changed, 3 insertions, 23 deletions
diff --git a/examples/sysinfo.c b/examples/sysinfo.c
index 40eed37a..f1350cdd 100644
--- a/examples/sysinfo.c
+++ b/examples/sysinfo.c
@@ -32,13 +32,14 @@
int
main (int argc, char *argv [])
{
+ char *model;
const glibtop_sysinfo * sysinfo;
glibtop_init();
-
sysinfo = glibtop_get_sysinfo ();
+ model = g_hash_table_lookup (sysinfo->cpuinfo [1].values, "model name");
- printf ("\nProcessor Model: %s\n", sysinfo->model);
+ printf ("\nProcessor Model: %s\n", g_strdup (model));
printf ("Number of Cores: %d\n\n", sysinfo->ncpu);
glibtop_close ();
diff --git a/include/glibtop/sysinfo.h b/include/glibtop/sysinfo.h
index 93e9b509..bc249513 100644
--- a/include/glibtop/sysinfo.h
+++ b/include/glibtop/sysinfo.h
@@ -51,7 +51,6 @@ struct _glibtop_sysinfo
guint64 flags;
guint64 ncpu;
glibtop_entry cpuinfo [GLIBTOP_NCPU];
- gchar *model;
};
#define glibtop_get_sysinfo_r glibtop_get_sysinfo_s
diff --git a/sysdeps/linux/sysinfo.c b/sysdeps/linux/sysinfo.c
index 2ebe0ec5..7dbd5eeb 100644
--- a/sysdeps/linux/sysinfo.c
+++ b/sysdeps/linux/sysinfo.c
@@ -37,7 +37,6 @@ static void
init_sysinfo (glibtop *server)
{
char* buffer;
- gchar *buf, *line;
gchar ** processors;
if(G_LIKELY(sysinfo.flags)) return;
@@ -49,25 +48,6 @@ init_sysinfo (glibtop *server)
/* cpuinfo records are seperated by a blank line */
processors = g_strsplit(buffer, "\n\n", 0);
- line = strtok(processors[0], "\n");
-
- while(line != NULL)
- {
- if (strstr(line, "model name") != NULL)
- {
- buf = strchr(line, ':');
-
- if (buf != NULL)
- {
- /* we want to look at what's _after_ the ':' */
- buf+=2;
- sysinfo.model = g_strdup (buf);
- }
- break;
- }
- line = strtok(NULL, "\n");
- }
-
g_free(buffer);
sysinfo.ncpu = 0;