From 629097436a2c654402e2a5210a2a0b4ca217b42c Mon Sep 17 00:00:00 2001 From: "Dr. James Dominic P. Guana" Date: Fri, 20 Aug 2021 19:08:15 +0800 Subject: [PATCH] Exposes the processor model Accessing processor model becomes easier Signed off: Dr. James Dominic P. Guana --- examples/Makefile.am | 2 +- examples/sysinfo.c | 8 +++++++- include/glibtop/sysinfo.h | 2 +- sysdeps/linux/sysinfo.c | 5 +++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/examples/Makefile.am b/examples/Makefile.am index fb95f825..e2b72115 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -72,4 +72,4 @@ diskio_SOURCES = diskio.c diskio_LDADD = $(top_builddir)/lib/libgtop-2.0.la sysinfo_SOURCES = sysinfo.c -sysinfo_LDADD = $(top_builddir)/lib/libgtop-2.0.la -lm +sysinfo_LDADD = $(top_builddir)/lib/libgtop-2.0.la diff --git a/examples/sysinfo.c b/examples/sysinfo.c index ed6fb162..40eed37a 100644 --- a/examples/sysinfo.c +++ b/examples/sysinfo.c @@ -32,10 +32,16 @@ int main (int argc, char *argv []) { - const glibtop_sysinfo * sysinfo = glibtop_get_sysinfo (); + const glibtop_sysinfo * sysinfo; + + glibtop_init(); + + sysinfo = glibtop_get_sysinfo (); printf ("\nProcessor Model: %s\n", sysinfo->model); printf ("Number of Cores: %d\n\n", sysinfo->ncpu); + glibtop_close (); + exit (0); } diff --git a/include/glibtop/sysinfo.h b/include/glibtop/sysinfo.h index 52e204ff..30598f16 100644 --- a/include/glibtop/sysinfo.h +++ b/include/glibtop/sysinfo.h @@ -50,7 +50,7 @@ struct _glibtop_sysinfo { guint64 flags; guint64 ncpu; - gchar *model; + gchar *model; glibtop_entry cpuinfo [GLIBTOP_NCPU]; }; diff --git a/sysdeps/linux/sysinfo.c b/sysdeps/linux/sysinfo.c index c9a66653..2ebe0ec5 100644 --- a/sysdeps/linux/sysinfo.c +++ b/sysdeps/linux/sysinfo.c @@ -59,8 +59,9 @@ init_sysinfo (glibtop *server) if (buf != NULL) { - buf+=2; // we want to look at what's _after_ the ':' - sysinfo.model = buf; + /* we want to look at what's _after_ the ':' */ + buf+=2; + sysinfo.model = g_strdup (buf); } break; }