From f688edd5c6bcb75121b9fc4bc680103458a2f8f7 Mon Sep 17 00:00:00 2001 From: npyl Date: Wed, 11 Jul 2018 19:55:12 +0300 Subject: [PATCH 01/18] Try to amend #31 --- src/net_stat.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/net_stat.cc b/src/net_stat.cc index 710ca7a88..4505bd704 100644 --- a/src/net_stat.cc +++ b/src/net_stat.cc @@ -476,7 +476,11 @@ int interface_up(struct text_object *obj) { if (dev == nullptr) { return 0; } +#if defined(__APPLE__) && defined(__MACH__) + if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { +#else if ((fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0) { +#endif CRIT_ERR(nullptr, nullptr, "could not create sockfd"); return 0; } From 306ded2e05868338c411841f3c1970df84d896eb Mon Sep 17 00:00:00 2001 From: npyl Date: Thu, 12 Jul 2018 04:39:18 +0300 Subject: [PATCH 02/18] BUILD_WLAN should be available for all OS. Keep BUILD_WLAN OFF by default for compatibility reasons. --- cmake/ConkyBuildOptions.cmake | 4 ++-- cmake/ConkyPlatformChecks.cmake | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake index bf89dc15a..58512fc96 100644 --- a/cmake/ConkyBuildOptions.cmake +++ b/cmake/ConkyBuildOptions.cmake @@ -76,7 +76,6 @@ if(OS_LINUX) option(BUILD_PORT_MONITORS "Build TCP portmon support" true) option(BUILD_IBM "Support for IBM/Lenovo notebooks" true) option(BUILD_HDDTEMP "Support for hddtemp" true) - option(BUILD_WLAN "Enable wireless support" false) # nvidia may also work on FreeBSD, not sure option(BUILD_NVIDIA "Enable nvidia support" false) option(BUILD_IPV6 "Enable if you want IPv6 support" true) @@ -84,7 +83,6 @@ else(OS_LINUX) set(BUILD_PORT_MONITORS false) set(BUILD_IBM false) set(BUILD_HDDTEMP false) - set(BUILD_WLAN false) set(BUILD_NVIDIA false) set(BUILD_IPV6 false) endif(OS_LINUX) @@ -92,6 +90,8 @@ endif(OS_LINUX) # Optional features etc # +option(BUILD_WLAN "Enable wireless support" false) + option(BUILD_BUILTIN_CONFIG "Enable builtin default configuration" true) option(BUILD_IOSTATS "Enable disk I/O stats" true) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index 39bef3d45..2c966f469 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -198,7 +198,7 @@ if(BUILD_MYSQL) set(conky_libs ${conky_libs} ${MYSQLCLIENT_LIB}) endif(BUILD_MYSQL) -if(BUILD_WLAN) +if(BUILD_WLAN AND OS_LINUX) set(CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE) check_include_files(iwlib.h IWLIB_H) if(NOT IWLIB_H) @@ -210,7 +210,7 @@ if(BUILD_WLAN) endif(NOT IWLIB_LIB) set(conky_libs ${conky_libs} ${IWLIB_LIB}) check_function_exists(iw_sockets_open IWLIB_SOCKETS_OPEN_FUNC) -endif(BUILD_WLAN) +endif(BUILD_WLAN AND OS_LINUX) if(BUILD_PORT_MONITORS) check_function_exists(getnameinfo HAVE_GETNAMEINFO) From c2b4cbd9c7f406b3c761c4903dc2ee5682e45881 Mon Sep 17 00:00:00 2001 From: npyl Date: Thu, 12 Jul 2018 04:45:07 +0300 Subject: [PATCH 03/18] WLAN-related variables should be available for every OS. There are some problems (probably null-dereference) --- src/core.cc | 66 ++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/core.cc b/src/core.cc index de2f8c075..c7ba7f332 100644 --- a/src/core.cc +++ b/src/core.cc @@ -484,42 +484,42 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, obj->data.i = atoi(&arg[0]); } obj->callbacks.print = &print_voltage_v; + +#endif /* __linux__ */ #ifdef BUILD_WLAN - END OBJ(wireless_essid, &update_net_stats) obj->data.opaque = - get_net_stat(arg, obj, free_at_crash); - obj->callbacks.print = &print_wireless_essid; - END OBJ(wireless_channel, &update_net_stats) - parse_net_stat_arg(obj, arg, free_at_crash); - obj->callbacks.print = &print_wireless_channel; - END OBJ(wireless_freq, &update_net_stats) - parse_net_stat_arg(obj, arg, free_at_crash); - obj->callbacks.print = &print_wireless_frequency; - END OBJ(wireless_mode, &update_net_stats) - parse_net_stat_arg(obj, arg, free_at_crash); - obj->callbacks.print = &print_wireless_mode; - END OBJ(wireless_bitrate, &update_net_stats) - parse_net_stat_arg(obj, arg, free_at_crash); - obj->callbacks.print = &print_wireless_bitrate; - END OBJ(wireless_ap, &update_net_stats) - parse_net_stat_arg(obj, arg, free_at_crash); - obj->callbacks.print = &print_wireless_ap; - END OBJ(wireless_link_qual, &update_net_stats) - parse_net_stat_arg(obj, arg, free_at_crash); - obj->callbacks.print = &print_wireless_link_qual; - END OBJ(wireless_link_qual_max, &update_net_stats) - parse_net_stat_arg(obj, arg, free_at_crash); - obj->callbacks.print = &print_wireless_link_qual_max; - END OBJ(wireless_link_qual_perc, &update_net_stats) - parse_net_stat_arg(obj, arg, free_at_crash); - obj->callbacks.print = &print_wireless_link_qual_perc; - END OBJ(wireless_link_bar, &update_net_stats) - parse_net_stat_bar_arg(obj, arg, free_at_crash); - obj->callbacks.barval = &wireless_link_barval; + END OBJ(wireless_essid, &update_net_stats) obj->data.opaque = + get_net_stat(arg, obj, free_at_crash); + obj->callbacks.print = &print_wireless_essid; + END OBJ(wireless_channel, &update_net_stats) + parse_net_stat_arg(obj, arg, free_at_crash); + obj->callbacks.print = &print_wireless_channel; + END OBJ(wireless_freq, &update_net_stats) + parse_net_stat_arg(obj, arg, free_at_crash); + obj->callbacks.print = &print_wireless_frequency; + END OBJ(wireless_mode, &update_net_stats) + parse_net_stat_arg(obj, arg, free_at_crash); + obj->callbacks.print = &print_wireless_mode; + END OBJ(wireless_bitrate, &update_net_stats) + parse_net_stat_arg(obj, arg, free_at_crash); + obj->callbacks.print = &print_wireless_bitrate; + END OBJ(wireless_ap, &update_net_stats) + parse_net_stat_arg(obj, arg, free_at_crash); + obj->callbacks.print = &print_wireless_ap; + END OBJ(wireless_link_qual, &update_net_stats) + parse_net_stat_arg(obj, arg, free_at_crash); + obj->callbacks.print = &print_wireless_link_qual; + END OBJ(wireless_link_qual_max, &update_net_stats) + parse_net_stat_arg(obj, arg, free_at_crash); + obj->callbacks.print = &print_wireless_link_qual_max; + END OBJ(wireless_link_qual_perc, &update_net_stats) + parse_net_stat_arg(obj, arg, free_at_crash); + obj->callbacks.print = &print_wireless_link_qual_perc; + END OBJ(wireless_link_bar, &update_net_stats) + parse_net_stat_bar_arg(obj, arg, free_at_crash); + obj->callbacks.barval = &wireless_link_barval; #endif /* BUILD_WLAN */ - -#endif /* __linux__ */ - + #ifndef __OpenBSD__ END OBJ(acpifan, nullptr) obj->callbacks.print = &print_acpifan; END OBJ(battery, nullptr) char bat[64]; From a1d079328f9456f26d004cac9b3fe385d990fa9d Mon Sep 17 00:00:00 2001 From: npyl Date: Thu, 12 Jul 2018 20:04:53 +0300 Subject: [PATCH 04/18] Fix $wireless_essid crashing conky if no argument provided. Conky wasn't parsing the argument of the variable as it should, thus wasn't allocating the `dev` member variable. Also fix some documentation stuff. --- doc/variables.xml | 4 ++-- src/core.cc | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index 617aa8404..0b6564b6a 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -4784,7 +4784,7 @@ - WLAN channel on which device 'net' is listening (Linux only) + WLAN channel on which device 'net' is listening @@ -4804,7 +4804,7 @@ - Frequency on which device 'net' is listening (Linux only) + Frequency on which device 'net' is listening diff --git a/src/core.cc b/src/core.cc index c7ba7f332..9011540d1 100644 --- a/src/core.cc +++ b/src/core.cc @@ -490,6 +490,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, #ifdef BUILD_WLAN END OBJ(wireless_essid, &update_net_stats) obj->data.opaque = get_net_stat(arg, obj, free_at_crash); + parse_net_stat_arg(obj, arg, free_at_crash); obj->callbacks.print = &print_wireless_essid; END OBJ(wireless_channel, &update_net_stats) parse_net_stat_arg(obj, arg, free_at_crash); From 6e5dbf6daf817b27afb1d8c48ede9be4065e7840 Mon Sep 17 00:00:00 2001 From: npyl Date: Fri, 27 Jul 2018 02:36:14 +0300 Subject: [PATCH 05/18] Improve `get_freq` #20 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using the Intel® Power Gadget API (https://software.intel.com/en-us/blogs/2012/12/13/using-the-intel-power-gadget-api-on-mac-os-x) we can now get actual Core frequency and not the constant factory one. Though, for some weird reason the API gives the same freq for all Cores, thus the |cpu| arg becomes useless. --- src/darwin.cc | 52 ++++++++++++++++--------------------------------- src/net_stat.cc | 4 ++++ 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/src/darwin.cc b/src/darwin.cc index cfb95c50a..e3ea1c016 100644 --- a/src/darwin.cc +++ b/src/darwin.cc @@ -74,6 +74,8 @@ #include "darwin_sip.h" // sip status +#include + /* clock_gettime includes */ #ifndef HAVE_CLOCK_GETTIME #include @@ -974,50 +976,30 @@ void get_acpi_fan(char * /*p_client_buffer*/, size_t /*client_buffer_size*/) { /* void */ char get_freq(char *p_client_buffer, size_t client_buffer_size, - const char *p_format, int divisor, unsigned int /*cpu*/) { + const char *p_format, int divisor, unsigned int cpu) { /* - * For now, we get the factory cpu frequency, not **current** cpu frequency - * (Also, it is always the same for every core, so ignore |cpu| argument) + * Our data is always the same for every core, so ignore |cpu| argument. */ - // XXX Probably find a way to get **current** cpu frequency - - int mib[2]; - unsigned int freq; - size_t len; - - if ((p_client_buffer == nullptr) || client_buffer_size <= 0 || - (p_format == nullptr) || divisor <= 0) { - return 0; + bool initialised = false; + + if (!initialised) + { + IntelEnergyLibInitialize(); + initialised = true; } + + int freq = 0; + GetIAFrequency(cpu, &freq); - mib[0] = CTL_HW; - mib[1] = HW_CPU_FREQ; - len = sizeof(freq); - - if (sysctl(mib, 2, &freq, &len, nullptr, 0) == 0) { - /* - * convert to MHz - */ - divisor *= 1000000; - - snprintf(p_client_buffer, client_buffer_size, p_format, - static_cast(freq) / divisor); - } else { - snprintf(p_client_buffer, client_buffer_size, p_format, 0.0f); - return 0; - } + snprintf(p_client_buffer, client_buffer_size, p_format, + static_cast(freq)); + + // XXX provide a func which will call IntelEnergyLibShutdown() return 1; } -#if 0 -void update_wifi_stats(void) -{ - printf("update_wifi_stats: STUB but also in #if 0\n"); -} -#endif - int update_diskio() { printf("update_diskio: STUB\n"); return 0; diff --git a/src/net_stat.cc b/src/net_stat.cc index 4505bd704..900161ad7 100644 --- a/src/net_stat.cc +++ b/src/net_stat.cc @@ -477,6 +477,10 @@ int interface_up(struct text_object *obj) { if (dev == nullptr) { return 0; } #if defined(__APPLE__) && defined(__MACH__) + // + // TODO: when opening pull request remember to ask if we should have only the macOS + // version for all OS, as shown at: showif.c + if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { #else if ((fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0) { From 70f530dcae2ee76baecd922ea7936da48e33d260 Mon Sep 17 00:00:00 2001 From: npyl Date: Fri, 27 Jul 2018 04:04:29 +0300 Subject: [PATCH 06/18] Oops, this accidently slipped in --- src/net_stat.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/net_stat.cc b/src/net_stat.cc index 900161ad7..4505bd704 100644 --- a/src/net_stat.cc +++ b/src/net_stat.cc @@ -477,10 +477,6 @@ int interface_up(struct text_object *obj) { if (dev == nullptr) { return 0; } #if defined(__APPLE__) && defined(__MACH__) - // - // TODO: when opening pull request remember to ask if we should have only the macOS - // version for all OS, as shown at: showif.c - if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { #else if ((fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0)) < 0) { From be8d41d175ed47905587d1305926e7503df7d7ff Mon Sep 17 00:00:00 2001 From: npyl Date: Sat, 28 Jul 2018 16:57:33 +0300 Subject: [PATCH 07/18] Introduce BUILD_IPGFREQ build option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This build option has been introduced for one particular reason: On macOS getting current core-frequency is not supported by the APIs. A solution is to install Intel's ® Power Gadget which comes with an .app, a Framework and a kernel-extension. Though, this may trouble some alot, thus introduce BUILD_IPGFREQ. --- cmake/ConkyBuildOptions.cmake | 5 ++++ cmake/ConkyPlatformChecks.cmake | 5 ++++ cmake/config.h.in | 2 ++ src/darwin.cc | 48 ++++++++++++++++++++++++++------- 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake index 58512fc96..781e8d6e4 100644 --- a/cmake/ConkyBuildOptions.cmake +++ b/cmake/ConkyBuildOptions.cmake @@ -87,6 +87,11 @@ else(OS_LINUX) set(BUILD_IPV6 false) endif(OS_LINUX) +# macOS Only +if(OS_DARWIN) + option(BUILD_IPGFREQ "Enable cpu freq calculation based on Intel® Power Gadget; otherwise use constant factory value" false) +endif(OS_DARWIN) + # Optional features etc # diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index 2c966f469..cb0d1626e 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -141,6 +141,11 @@ if(BUILD_MATH) set(conky_libs ${conky_libs} -lm) endif(BUILD_MATH) +if(OS_DARWIN AND BUILD_IPGFREQ) + find_library(IPG IntelPowerGadget) + set(conky_libs ${conky_libs} ${IPG}) +endif(OS_DARWIN AND BUILD_IPGFREQ) + if(BUILD_ICAL) check_include_files(libical/ical.h ICAL_H_) if(NOT ICAL_H_) diff --git a/cmake/config.h.in b/cmake/config.h.in index 8bd09725f..8a442bbe0 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -102,6 +102,8 @@ #cmakedefine BUILD_IOSTATS 1 +#cmakedefine BUILD_IPGFREQ 0 + #cmakedefine BUILD_WLAN 1 #cmakedefine BUILD_ICAL 1 diff --git a/src/darwin.cc b/src/darwin.cc index e3ea1c016..e0480a179 100644 --- a/src/darwin.cc +++ b/src/darwin.cc @@ -42,12 +42,6 @@ *is available. patched the _csr_check function to return the bool bit instead. */ -/* - * Apologies for the code style... - * In my eyes it feels better to have - * different styles at some specific places... :) - */ - #include "conky.h" // for struct info #include "darwin.h" @@ -74,7 +68,9 @@ #include "darwin_sip.h" // sip status +#ifdef BUILD_IPGFREQ #include +#endif /* clock_gettime includes */ #ifndef HAVE_CLOCK_GETTIME @@ -977,12 +973,13 @@ void get_acpi_fan(char * /*p_client_buffer*/, size_t /*client_buffer_size*/) { /* void */ char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_format, int divisor, unsigned int cpu) { +#ifdef BUILD_IPGFREQ /* * Our data is always the same for every core, so ignore |cpu| argument. */ - + bool initialised = false; - + if (!initialised) { IntelEnergyLibInitialize(); @@ -991,11 +988,42 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, int freq = 0; GetIAFrequency(cpu, &freq); - + snprintf(p_client_buffer, client_buffer_size, p_format, static_cast(freq)); +#else + /* + * We get the factory cpu frequency, not **current** cpu frequency + * (Also, it is always the same for every core, so ignore |cpu| argument) + * Enable BUILD_IPGFREQ for getting current frequency. + */ - // XXX provide a func which will call IntelEnergyLibShutdown() + int mib[2]; + unsigned int freq; + size_t len; + + if ((p_client_buffer == nullptr) || client_buffer_size <= 0 || + (p_format == nullptr) || divisor <= 0) { + return 0; + } + + mib[0] = CTL_HW; + mib[1] = HW_CPU_FREQ; + len = sizeof(freq); + + if (sysctl(mib, 2, &freq, &len, nullptr, 0) == 0) { + /* + * convert to MHz + */ + divisor *= 1000000; + + snprintf(p_client_buffer, client_buffer_size, p_format, + static_cast(freq) / divisor); + } else { + snprintf(p_client_buffer, client_buffer_size, p_format, 0.0f); + return 0; + } +#endif return 1; } From b267fa42457e72e7ca58336dac893f04cc687f8b Mon Sep 17 00:00:00 2001 From: npyl Date: Sat, 28 Jul 2018 17:01:10 +0300 Subject: [PATCH 08/18] Forgot static here. --- src/darwin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/darwin.cc b/src/darwin.cc index e0480a179..2a501e7b9 100644 --- a/src/darwin.cc +++ b/src/darwin.cc @@ -978,7 +978,7 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, * Our data is always the same for every core, so ignore |cpu| argument. */ - bool initialised = false; + static bool initialised = false; if (!initialised) { From df52a17dba03235347f50947ae9f7e92e26bc46a Mon Sep 17 00:00:00 2001 From: npyl Date: Sun, 29 Jul 2018 16:49:19 +0300 Subject: [PATCH 09/18] Some improvements for get_freq again. Fix frequency not printing correctly (I wasn't using the divisor) Add more guards. --- src/darwin.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/darwin.cc b/src/darwin.cc index 2a501e7b9..d66498609 100644 --- a/src/darwin.cc +++ b/src/darwin.cc @@ -973,6 +973,12 @@ void get_acpi_fan(char * /*p_client_buffer*/, size_t /*client_buffer_size*/) { /* void */ char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_format, int divisor, unsigned int cpu) { + + if ((p_client_buffer == nullptr) || client_buffer_size <= 0 || + (p_format == nullptr) || divisor <= 0) { + return 0; + } + #ifdef BUILD_IPGFREQ /* * Our data is always the same for every core, so ignore |cpu| argument. @@ -980,8 +986,7 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, static bool initialised = false; - if (!initialised) - { + if (!initialised) { IntelEnergyLibInitialize(); initialised = true; } @@ -990,7 +995,7 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, GetIAFrequency(cpu, &freq); snprintf(p_client_buffer, client_buffer_size, p_format, - static_cast(freq)); + static_cast(freq) / divisor); #else /* * We get the factory cpu frequency, not **current** cpu frequency @@ -1002,11 +1007,6 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, unsigned int freq; size_t len; - if ((p_client_buffer == nullptr) || client_buffer_size <= 0 || - (p_format == nullptr) || divisor <= 0) { - return 0; - } - mib[0] = CTL_HW; mib[1] = HW_CPU_FREQ; len = sizeof(freq); @@ -1024,7 +1024,7 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, return 0; } #endif - + return 1; } From 8f2272c2aa794b37d64d3d3c5bc3636cd3ede52a Mon Sep 17 00:00:00 2001 From: npyl Date: Mon, 30 Jul 2018 17:22:02 +0300 Subject: [PATCH 10/18] Setup cmake files and project code for Objective-C code #17 We want to use CoreWLAN framework. --- cmake/ConkyPlatformChecks.cmake | 11 ++++++++--- src/CMakeLists.txt | 2 +- src/{darwin.cc => darwin.mm} | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) rename src/{darwin.cc => darwin.mm} (99%) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index cb0d1626e..d926aa81d 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -137,15 +137,20 @@ if(BUILD_NCURSES AND OS_DARWIN) set(conky_libs ${conky_libs} -lncurses) endif(BUILD_NCURSES AND OS_DARWIN) -if(BUILD_MATH) - set(conky_libs ${conky_libs} -lm) -endif(BUILD_MATH) +if(BUILD_WLAN AND OS_DARWIN) + find_library(CW CoreWLAN) + set(conky_libs ${conky_libs} ${CW}) +endif(BUILD_WLAN AND OS_DARWIN) if(OS_DARWIN AND BUILD_IPGFREQ) find_library(IPG IntelPowerGadget) set(conky_libs ${conky_libs} ${IPG}) endif(OS_DARWIN AND BUILD_IPGFREQ) +if(BUILD_MATH) + set(conky_libs ${conky_libs} -lm) +endif(BUILD_MATH) + if(BUILD_ICAL) check_include_files(libical/ical.h ICAL_H_) if(NOT ICAL_H_) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 59d2efbad..4e490ac0c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -135,7 +135,7 @@ endif(OS_HAIKU) if(OS_DARWIN) set(darwin - darwin.cc darwin.h + darwin.mm darwin.h darwin_sip.h i18n.h ) diff --git a/src/darwin.cc b/src/darwin.mm similarity index 99% rename from src/darwin.cc rename to src/darwin.mm index d66498609..d83e3d1e5 100644 --- a/src/darwin.cc +++ b/src/darwin.mm @@ -72,6 +72,10 @@ #include #endif +#ifdef BUILD_WLAN +#import +#endif + /* clock_gettime includes */ #ifndef HAVE_CLOCK_GETTIME #include @@ -636,6 +640,14 @@ int update_meminfo() { return 0; } +#ifdef BUILD_WLAN + +void update_wlan_stats(struct net_stat *ns) { + +} + +#endif + int update_net_stats() { struct net_stat *ns; double delta; @@ -655,6 +667,10 @@ int update_net_stats() { if ((ifa->ifa_flags & IFF_UP) != 0u) { struct ifaddrs *iftmp; +#ifdef BUILD_WLAN + update_wlan_stats(ns); +#endif + ns->up = 1; last_recv = ns->recv; last_trans = ns->trans; From 2942e67dd1ac65fc7f3e27c43ac6fd1cb85eba3f Mon Sep 17 00:00:00 2001 From: npyl Date: Thu, 2 Aug 2018 18:32:31 +0300 Subject: [PATCH 11/18] update_cpu_usage() now supports multiple cores Also, some cleanup. --- src/core.cc | 10 +++++ src/darwin.h | 2 + src/darwin.mm | 122 ++++++++++++++++++++++++++------------------------ 3 files changed, 75 insertions(+), 59 deletions(-) diff --git a/src/core.cc b/src/core.cc index 9011540d1..4e7d40516 100644 --- a/src/core.cc +++ b/src/core.cc @@ -121,6 +121,12 @@ #include "darwin.h" #endif +#if defined (__APPLE__) && defined (__MACH__) +#define DARWIN_DEALLOCATE_CPU_SAMPLE obj->callbacks.free = &deallocate_cpu_sample; +#else +#define DARWIN_DEALLOCATE_CPU_SAMPLE +#endif + #include #include @@ -674,18 +680,21 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, END OBJ(cpu, &update_cpu_usage) get_cpu_count(); SCAN_CPU(arg, obj->data.i); obj->callbacks.percentage = &cpu_percentage; + DARWIN_DEALLOCATE_CPU_SAMPLE DBGP2("Adding $cpu for CPU %d", obj->data.i); #ifdef BUILD_X11 END OBJ(cpugauge, &update_cpu_usage) get_cpu_count(); SCAN_CPU(arg, obj->data.i); scan_gauge(obj, arg, 1); obj->callbacks.gaugeval = &cpu_barval; + DARWIN_DEALLOCATE_CPU_SAMPLE DBGP2("Adding $cpugauge for CPU %d", obj->data.i); #endif END OBJ(cpubar, &update_cpu_usage) get_cpu_count(); SCAN_CPU(arg, obj->data.i); scan_bar(obj, arg, 1); obj->callbacks.barval = &cpu_barval; + DARWIN_DEALLOCATE_CPU_SAMPLE DBGP2("Adding $cpubar for CPU %d", obj->data.i); #ifdef BUILD_X11 END OBJ(cpugraph, &update_cpu_usage) get_cpu_count(); @@ -695,6 +704,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, DBGP2("Adding $cpugraph for CPU %d", obj->data.i); free_and_zero(buf); obj->callbacks.graphval = &cpu_barval; + DARWIN_DEALLOCATE_CPU_SAMPLE END OBJ(loadgraph, &update_load_average) scan_loadgraph_arg(obj, arg); obj->callbacks.graphval = &loadgraphval; #endif /* BUILD_X11 */ diff --git a/src/darwin.h b/src/darwin.h index 55491228c..d6e6673e7 100644 --- a/src/darwin.h +++ b/src/darwin.h @@ -56,4 +56,6 @@ int get_entropy_poolsize(const unsigned int *); int get_sip_status(void); void print_sip_status(struct text_object *obj, char *p, int p_max_size); +void deallocate_cpu_sample(struct text_object *obj); + #endif /*DARWIN_H*/ diff --git a/src/darwin.mm b/src/darwin.mm index d83e3d1e5..638fe0222 100644 --- a/src/darwin.mm +++ b/src/darwin.mm @@ -68,6 +68,8 @@ #include "darwin_sip.h" // sip status +#include + #ifdef BUILD_IPGFREQ #include #endif @@ -108,6 +110,10 @@ void eprintf(const char *fmt, ...) { */ static conky::simple_config_setting top_cpu_separate("top_cpu_separate", false, true); +/* + * used by update_cpu_usage() + */ +std::vector sample_handles; /* a registry of handles */ static int getsysctl(const char *name, void *ptr, size_t len) { size_t nlen = len; @@ -221,13 +227,12 @@ static void helper_update_threads_processes() { * Gets systemTime, userTime and idleTime for CPU * MenuMeters has been great inspiration for this function */ -static void get_cpu_sample(struct cpusample *sample) { +static void get_cpu_sample(struct cpusample **sample) { host_name_port_t machHost; natural_t processorCount; processor_cpu_load_info_t processorTickInfo; mach_msg_type_number_t processorInfoCount; - struct cpusample *samples = nullptr; - + machHost = mach_host_self(); kern_return_t err = host_processor_info( @@ -239,22 +244,15 @@ static void get_cpu_sample(struct cpusample *sample) { return; } - /* - * allocate ncpus+1 cpusample structs (one foreach CPU) - * ** samples[0] is overal CPU usage - */ - samples = new struct cpusample[processorCount + 1]; - memset(samples, 0, sizeof(cpusample) * (processorCount + 1)); - /* * start from samples[1] because samples[0] is overall CPU usage */ for (natural_t i = 1; i < processorCount + 1; i++) { - samples[i].totalSystemTime = + (*sample)[i].totalSystemTime = processorTickInfo[i - 1].cpu_ticks[CPU_STATE_SYSTEM], - samples[i].totalUserTime = + (*sample)[i].totalUserTime = processorTickInfo[i - 1].cpu_ticks[CPU_STATE_USER], - samples[i].totalIdleTime = + (*sample)[i].totalIdleTime = processorTickInfo[i - 1].cpu_ticks[CPU_STATE_IDLE]; } @@ -262,24 +260,34 @@ static void get_cpu_sample(struct cpusample *sample) { * sum up all totals */ for (natural_t i = 1; i < processorCount + 1; i++) { - samples[0].totalSystemTime += samples[i].totalSystemTime; - samples[0].totalUserTime += samples[i].totalUserTime; - samples[0].totalIdleTime += samples[i].totalIdleTime; + (*sample)[0].totalSystemTime += (*sample)[i].totalSystemTime; + (*sample)[0].totalUserTime += (*sample)[i].totalUserTime; + (*sample)[0].totalIdleTime += (*sample)[i].totalIdleTime; } - /* - * set the sample pointer - */ - sample->totalSystemTime = samples[0].totalSystemTime; - sample->totalUserTime = samples[0].totalUserTime; - sample->totalIdleTime = samples[0].totalIdleTime; - /* * Dealloc */ vm_deallocate(mach_task_self(), (vm_address_t)processorTickInfo, static_cast(processorInfoCount * sizeof(natural_t))); - delete[] samples; +} + +void allocate_cpu_sample(struct cpusample **sample) { + /* + * allocate ncpus+1 cpusample structs (one foreach CPU) + * ** sample_handle[0] is overal CPU usage + */ + *sample = reinterpret_cast(malloc(sizeof(cpusample) * (info.cpu_count + 1))); + memset(*sample, 0, sizeof(cpusample) * (info.cpu_count + 1)); + + sample_handles.push_back(*sample); /* register handle */ +} + +void deallocate_cpu_sample(struct text_object *obj) { + while (sample_handles.size() > 0) { + free(sample_handles.back()); + sample_handles.pop_back(); + } } /* @@ -569,11 +577,9 @@ uint64_t get_physical_memory() { } int update_meminfo() { - /* XXX implement remaining memory-related variables (see conky.h) */ - /* XXX conky breaks the values ... :( probably some rounding problem... - Though we get the right values (based on top) */ - /* XXX probably investigate the "probably apple keeps some info secret" */ - + + /* XXX See #34 */ + vm_size_t page_size = getpagesize(); // get pagesize in bytes unsigned long swap_avail, swap_free; @@ -857,8 +863,6 @@ void get_cpu_count() { info.cpu_count = 0; } - /* XXX this can be moved to update_cpu_usage() but keep here to follow linux - * implementation */ if (info.cpu_usage == nullptr) { /* * Allocate ncpus+1 slots because cpu_usage[0] is overall usage. @@ -878,16 +882,14 @@ void get_cpu_count() { }; int update_cpu_usage() { - /* XXX add support for multiple cpus (see linux.cc) */ - static bool cpu_setup = 0; long used, total; static struct cpu_info *cpu = nullptr; unsigned int malloc_cpu_size = 0; extern void *global_cpu; - - struct cpusample sample {}; + + struct cpusample *sample = nullptr; static pthread_mutex_t last_stat_update_mutex = PTHREAD_MUTEX_INITIALIZER; static double last_stat_update = 0.0; @@ -919,19 +921,29 @@ int update_cpu_usage() { global_cpu = cpu; } + allocate_cpu_sample(&sample); + get_cpu_sample(&sample); - total = sample.totalUserTime + sample.totalIdleTime + sample.totalSystemTime; - used = total - sample.totalIdleTime; - if ((total - cpu[0].oldtotal) != 0) { - info.cpu_usage[0] = (static_cast(used - cpu[0].oldused)) / - static_cast(total - cpu[0].oldtotal); - } else { - info.cpu_usage[0] = 0; - } + /* + * Setup conky's structs for-each core + */ + for (int i = 1; i < info.cpu_count + 1; i++) { + int j = i - 1; - cpu[0].oldused = used; - cpu[0].oldtotal = total; + total = sample[i].totalUserTime + sample[i].totalIdleTime + sample[i].totalSystemTime; + used = total - sample[i].totalIdleTime; + + if ((total - cpu[j].oldtotal) != 0) { + info.cpu_usage[j] = (static_cast(used - cpu[j].oldused)) / + static_cast(total - cpu[j].oldtotal); + } else { + info.cpu_usage[j] = 0; + } + + cpu[j].oldused = used; + cpu[j].oldtotal = total; + } return 0; } @@ -1084,11 +1096,13 @@ static void calc_cpu_usage_for_proc(struct process *proc, uint64_t total) { */ static void calc_cpu_total(struct process *proc, uint64_t *total) { uint64_t current_total = 0; /* of current iteration */ - struct cpusample sample {}; - + struct cpusample *sample = nullptr; + + allocate_cpu_sample(&sample); + get_cpu_sample(&sample); current_total = - sample.totalUserTime + sample.totalIdleTime + sample.totalSystemTime; + sample[0].totalUserTime + sample[0].totalIdleTime + sample[0].totalSystemTime; *total = current_total - proc->previous_total_cpu_time; proc->previous_total_cpu_time = current_total; @@ -1201,17 +1215,7 @@ void get_top_info() { struct kinfo_proc *p = nullptr; /* - * QUICKFIX for #16 - * XXX if we run conky -t '${top_mem mem 1}' it will crash because - * info.cpu_count is not initialised. - * - * We can initialise it down here, but it seems like in the linux - * implementation of get_top_info() there is no call to the get_cpu_count() - * function. Neither is there in core.cc... If this is the case, when is - * info.cpu_count initialised??? - * - * Find a proper better place for get_cpu_count() call. (for comformance with - * linux.cc) + * See #16 */ get_cpu_count(); From 6adf22f3ab451cb4879339a05d782f4928aa47f9 Mon Sep 17 00:00:00 2001 From: TheFatDemon Date: Fri, 3 Aug 2018 11:33:25 -0700 Subject: [PATCH 12/18] Updated default conky config to monitor Mac Networking --- data/conky.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/conky.conf b/data/conky.conf index b3709c8d0..2f7e138b3 100644 --- a/data/conky.conf +++ b/data/conky.conf @@ -72,7 +72,7 @@ $hr ${color grey}File systems: / $color${fs_used /}/${fs_size /} ${fs_bar 6 /} ${color grey}Networking: -Up:$color ${upspeed eth0} ${color grey} - Down:$color ${downspeed eth0} +Up:$color ${upspeed en0} ${color grey} - Down:$color ${downspeed en0} $hr ${color grey}Name PID CPU% MEM% ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1} From ef1ad1b8e1c1173b53f1c3a3eb567c2a5bfa1f71 Mon Sep 17 00:00:00 2001 From: TheFatDemon Date: Mon, 6 Aug 2018 09:16:20 -0700 Subject: [PATCH 13/18] Made Mac Friendly BuildOptions and generic default conky configs --- cmake/ConkyBuildOptions.cmake | 14 ++++++++++++-- data/conky.conf | 2 +- data/conky_no_x11.conf | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake index 781e8d6e4..edfcceb96 100644 --- a/cmake/ConkyBuildOptions.cmake +++ b/cmake/ConkyBuildOptions.cmake @@ -62,7 +62,13 @@ if (NOT LIB_INSTALL_DIR) set (LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}") endif (NOT LIB_INSTALL_DIR) set(PACKAGE_LIBRARY_DIR "${LIB_INSTALL_DIR}/conky" CACHE STRING "Package library path (where Lua bindings are installed" FORCE) -set(DEFAULTNETDEV "eth0" CACHE STRING "Default networkdevice") + +if(OS_DARWIN) + set(DEFAULTNETDEV "en0" CACHE STRING "Default networkdevice") +else(OS_DARWIN) + set(DEFAULTNETDEV "eth0" CACHE STRING "Default networkdevice") +endif(OS_DARWIN) + set(XDG_CONFIG_FILE "$HOME/.config/conky/conky.conf" CACHE STRING "Configfile of the user (XDG)") set(CONFIG_FILE "$HOME/.conkyrc" CACHE STRING "Configfile of the user") set(MAX_USER_TEXT_DEFAULT "16384" CACHE STRING "Default maximum size of config TEXT buffer, i.e. below TEXT line.") @@ -115,7 +121,11 @@ endif(BUILD_NCURSES) option(BUILD_X11 "Build X11 support" true) if(BUILD_X11) option(OWN_WINDOW "Enable own_window support" true) - option(BUILD_XDAMAGE "Build Xdamage support" true) + if(OS_DARWIN) + option(BUILD_XDAMAGE "Build Xdamage support" false) + else(OS_DARWIN) + option(BUILD_XDAMAGE "Build Xdamage support" true) + endif(OS_DARWIN) option(BUILD_XINERAMA "Build Xinerama support" true) option(BUILD_XDBE "Build Xdbe (double-buffer) support" true) option(BUILD_XFT "Build Xft (freetype fonts) support" true) diff --git a/data/conky.conf b/data/conky.conf index 2f7e138b3..c515a5f95 100644 --- a/data/conky.conf +++ b/data/conky.conf @@ -72,7 +72,7 @@ $hr ${color grey}File systems: / $color${fs_used /}/${fs_size /} ${fs_bar 6 /} ${color grey}Networking: -Up:$color ${upspeed en0} ${color grey} - Down:$color ${downspeed en0} +Up:$color ${upspeed} ${color grey} - Down:$color ${downspeed} $hr ${color grey}Name PID CPU% MEM% ${color lightgrey} ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1} diff --git a/data/conky_no_x11.conf b/data/conky_no_x11.conf index 40a675da2..bfd3a9a20 100644 --- a/data/conky_no_x11.conf +++ b/data/conky_no_x11.conf @@ -46,7 +46,7 @@ Processes: $processes Running: $running_processes File systems: / ${fs_used /}/${fs_size /} ${fs_bar 6 /} Networking: -Up: ${upspeed eth0} - Down: ${downspeed eth0} +Up: ${upspeed} - Down: ${downspeed} Name PID CPU% MEM% ${top name 1} ${top pid 1} ${top cpu 1} ${top mem 1} ${top name 2} ${top pid 2} ${top cpu 2} ${top mem 2} From cc37fb93d072d37b28cf9468b0c92f9d5a65b654 Mon Sep 17 00:00:00 2001 From: TheFatDemon Date: Mon, 6 Aug 2018 09:47:38 -0700 Subject: [PATCH 14/18] Undid Xdamage config and cleaned up previous IF statements --- cmake/ConkyBuildOptions.cmake | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake index edfcceb96..178207b31 100644 --- a/cmake/ConkyBuildOptions.cmake +++ b/cmake/ConkyBuildOptions.cmake @@ -62,11 +62,11 @@ if (NOT LIB_INSTALL_DIR) set (LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}") endif (NOT LIB_INSTALL_DIR) set(PACKAGE_LIBRARY_DIR "${LIB_INSTALL_DIR}/conky" CACHE STRING "Package library path (where Lua bindings are installed" FORCE) +set(DEFAULTNETDEV "eth0" CACHE STRING "Default networkdevice") +# Mac only override if(OS_DARWIN) - set(DEFAULTNETDEV "en0" CACHE STRING "Default networkdevice") -else(OS_DARWIN) - set(DEFAULTNETDEV "eth0" CACHE STRING "Default networkdevice") + set(DEFAULTNETDEV "en0" CACHE STRING "Default networkdevice" FORCE) endif(OS_DARWIN) set(XDG_CONFIG_FILE "$HOME/.config/conky/conky.conf" CACHE STRING "Configfile of the user (XDG)") @@ -121,11 +121,7 @@ endif(BUILD_NCURSES) option(BUILD_X11 "Build X11 support" true) if(BUILD_X11) option(OWN_WINDOW "Enable own_window support" true) - if(OS_DARWIN) - option(BUILD_XDAMAGE "Build Xdamage support" false) - else(OS_DARWIN) - option(BUILD_XDAMAGE "Build Xdamage support" true) - endif(OS_DARWIN) + option(BUILD_XDAMAGE "Build Xdamage support" true) option(BUILD_XINERAMA "Build Xinerama support" true) option(BUILD_XDBE "Build Xdbe (double-buffer) support" true) option(BUILD_XFT "Build Xft (freetype fonts) support" true) From c546c847620a0d83afcbdf379ea47f9d91febf2e Mon Sep 17 00:00:00 2001 From: TheFatDemon Date: Mon, 6 Aug 2018 11:21:43 -0700 Subject: [PATCH 15/18] Re-Added XDamage fix --- cmake/ConkyBuildOptions.cmake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake index 178207b31..e9584c9db 100644 --- a/cmake/ConkyBuildOptions.cmake +++ b/cmake/ConkyBuildOptions.cmake @@ -121,7 +121,14 @@ endif(BUILD_NCURSES) option(BUILD_X11 "Build X11 support" true) if(BUILD_X11) option(OWN_WINDOW "Enable own_window support" true) - option(BUILD_XDAMAGE "Build Xdamage support" true) + + # Mac Fix + if(OS_DARWIN) + option(BUILD_XDAMAGE "Build Xdamage support" false) + else(OS_DARWIN) + option(BUILD_XDAMAGE "Build Xdamage support" true) + endif(OS_DARWIN) + option(BUILD_XINERAMA "Build Xinerama support" true) option(BUILD_XDBE "Build Xdbe (double-buffer) support" true) option(BUILD_XFT "Build Xft (freetype fonts) support" true) From ce0676957c22db0c0502225be4f1a78ce3289b1d Mon Sep 17 00:00:00 2001 From: npyl Date: Tue, 7 Aug 2018 01:50:22 +0300 Subject: [PATCH 16/18] Finish up the algorithm. I think its now correct. Closes: #33 --- src/darwin.mm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/darwin.mm b/src/darwin.mm index 638fe0222..34e1929e2 100644 --- a/src/darwin.mm +++ b/src/darwin.mm @@ -113,7 +113,7 @@ void eprintf(const char *fmt, ...) { /* * used by update_cpu_usage() */ -std::vector sample_handles; /* a registry of handles */ +struct cpusample *sample_handle = nullptr; static int getsysctl(const char *name, void *ptr, size_t len) { size_t nlen = len; @@ -273,20 +273,23 @@ static void get_cpu_sample(struct cpusample **sample) { } void allocate_cpu_sample(struct cpusample **sample) { + if (*sample != nullptr) + return; + /* * allocate ncpus+1 cpusample structs (one foreach CPU) * ** sample_handle[0] is overal CPU usage */ *sample = reinterpret_cast(malloc(sizeof(cpusample) * (info.cpu_count + 1))); memset(*sample, 0, sizeof(cpusample) * (info.cpu_count + 1)); - - sample_handles.push_back(*sample); /* register handle */ + + sample_handle = *sample; /* use a public handle for deallocating */ } void deallocate_cpu_sample(struct text_object *obj) { - while (sample_handles.size() > 0) { - free(sample_handles.back()); - sample_handles.pop_back(); + if (sample_handle != nullptr) { + free(sample_handle); + sample_handle = nullptr; } } @@ -889,7 +892,7 @@ int update_cpu_usage() { unsigned int malloc_cpu_size = 0; extern void *global_cpu; - struct cpusample *sample = nullptr; + static struct cpusample *sample = nullptr; static pthread_mutex_t last_stat_update_mutex = PTHREAD_MUTEX_INITIALIZER; static double last_stat_update = 0.0; @@ -922,7 +925,7 @@ int update_cpu_usage() { } allocate_cpu_sample(&sample); - + get_cpu_sample(&sample); /* From 03abfc68245559873e0c186761a827b29491404c Mon Sep 17 00:00:00 2001 From: npyl Date: Tue, 7 Aug 2018 18:01:42 +0300 Subject: [PATCH 17/18] Cleanup macro and introduce a no-op free_cpu() function for ALL cpu-related variables free_cpu() must be implemented for every OS and on all except macOS its a no-op function. --- src/common.h | 2 ++ src/core.cc | 14 ++++---------- src/darwin.mm | 2 +- src/dragonfly.cc | 3 +++ src/freebsd.cc | 3 +++ src/haiku.cc | 3 +++ src/linux.cc | 3 +++ src/netbsd.cc | 3 +++ src/openbsd.cc | 3 +++ src/solaris.cc | 3 +++ 10 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/common.h b/src/common.h index 8b6407ec0..69ccb9958 100644 --- a/src/common.h +++ b/src/common.h @@ -158,6 +158,8 @@ uint8_t battery_percentage(struct text_object *); void print_battery_short(struct text_object *, char *, int); #endif /* !__OpenBSD__ */ +void free_cpu(struct text_object *); + void print_blink(struct text_object *, char *, int); void print_include(struct text_object *, char *, int); diff --git a/src/core.cc b/src/core.cc index 4e7d40516..98d3566c4 100644 --- a/src/core.cc +++ b/src/core.cc @@ -121,12 +121,6 @@ #include "darwin.h" #endif -#if defined (__APPLE__) && defined (__MACH__) -#define DARWIN_DEALLOCATE_CPU_SAMPLE obj->callbacks.free = &deallocate_cpu_sample; -#else -#define DARWIN_DEALLOCATE_CPU_SAMPLE -#endif - #include #include @@ -680,21 +674,21 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, END OBJ(cpu, &update_cpu_usage) get_cpu_count(); SCAN_CPU(arg, obj->data.i); obj->callbacks.percentage = &cpu_percentage; - DARWIN_DEALLOCATE_CPU_SAMPLE + obj->callbacks.free = &free_cpu; DBGP2("Adding $cpu for CPU %d", obj->data.i); #ifdef BUILD_X11 END OBJ(cpugauge, &update_cpu_usage) get_cpu_count(); SCAN_CPU(arg, obj->data.i); scan_gauge(obj, arg, 1); obj->callbacks.gaugeval = &cpu_barval; - DARWIN_DEALLOCATE_CPU_SAMPLE + obj->callbacks.free = &free_cpu; DBGP2("Adding $cpugauge for CPU %d", obj->data.i); #endif END OBJ(cpubar, &update_cpu_usage) get_cpu_count(); SCAN_CPU(arg, obj->data.i); scan_bar(obj, arg, 1); obj->callbacks.barval = &cpu_barval; - DARWIN_DEALLOCATE_CPU_SAMPLE + obj->callbacks.free = &free_cpu; DBGP2("Adding $cpubar for CPU %d", obj->data.i); #ifdef BUILD_X11 END OBJ(cpugraph, &update_cpu_usage) get_cpu_count(); @@ -704,7 +698,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, DBGP2("Adding $cpugraph for CPU %d", obj->data.i); free_and_zero(buf); obj->callbacks.graphval = &cpu_barval; - DARWIN_DEALLOCATE_CPU_SAMPLE + obj->callbacks.free = &free_cpu; END OBJ(loadgraph, &update_load_average) scan_loadgraph_arg(obj, arg); obj->callbacks.graphval = &loadgraphval; #endif /* BUILD_X11 */ diff --git a/src/darwin.mm b/src/darwin.mm index 34e1929e2..a41a03b4a 100644 --- a/src/darwin.mm +++ b/src/darwin.mm @@ -286,7 +286,7 @@ void allocate_cpu_sample(struct cpusample **sample) { sample_handle = *sample; /* use a public handle for deallocating */ } -void deallocate_cpu_sample(struct text_object *obj) { +void free_cpu(struct text_object *) { if (sample_handle != nullptr) { free(sample_handle); sample_handle = nullptr; diff --git a/src/dragonfly.cc b/src/dragonfly.cc index 689ceb34e..7a2fb2d89 100644 --- a/src/dragonfly.cc +++ b/src/dragonfly.cc @@ -357,6 +357,9 @@ int update_cpu_usage(void) { return 0; } +void free_cpu(struct text_object *) { +} + int update_load_average(void) { double v[3]; diff --git a/src/freebsd.cc b/src/freebsd.cc index 8e27bad3b..75c03d1d9 100644 --- a/src/freebsd.cc +++ b/src/freebsd.cc @@ -371,6 +371,9 @@ int update_cpu_usage(void) { return 0; } +void free_cpu(struct text_object *) { +} + int update_load_average(void) { double v[3]; diff --git a/src/haiku.cc b/src/haiku.cc index 2f4a217fa..62423f391 100644 --- a/src/haiku.cc +++ b/src/haiku.cc @@ -143,6 +143,9 @@ int update_cpu_usage() { return 1; } +void free_cpu(struct text_object *) { +} + int update_load_average() { // TODO return 1; diff --git a/src/linux.cc b/src/linux.cc index ec425c9d7..a9ebd22da 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -936,6 +936,9 @@ int update_cpu_usage(void) { return 0; } +void free_cpu(struct text_object *) { +} + // fscanf() that reads floats with points even if you are using a locale where // floats are with commas int fscanf_no_i18n(FILE *stream, const char *format, ...) { diff --git a/src/netbsd.cc b/src/netbsd.cc index e844b20f0..514657806 100644 --- a/src/netbsd.cc +++ b/src/netbsd.cc @@ -286,6 +286,9 @@ void update_cpu_usage() { oldtotal = total; } +void free_cpu(struct text_object *) { +} + void update_load_average() { double v[3]; diff --git a/src/openbsd.cc b/src/openbsd.cc index 758572aa9..36568ebb6 100644 --- a/src/openbsd.cc +++ b/src/openbsd.cc @@ -400,6 +400,9 @@ void update_cpu_usage() { #endif } +void free_cpu(struct text_object *) { +} + void update_load_average() { double v[3]; diff --git a/src/solaris.cc b/src/solaris.cc index c28d94088..2dbbdf64f 100644 --- a/src/solaris.cc +++ b/src/solaris.cc @@ -314,6 +314,9 @@ int update_cpu_usage(void) { return 0; } +void free_cpu(struct text_object *) { +} + void update_proc_entry(struct process *p) { psinfo_t proc; int fd; From d9b218b7e6fcc38f34951e93c6aaac644a890235 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Tue, 7 Aug 2018 11:47:08 -0400 Subject: [PATCH 18/18] Reformat, add empty comment. --- src/dragonfly.cc | 31 ++++++++----------------------- src/freebsd.cc | 7 ++----- src/haiku.cc | 3 +-- src/linux.cc | 3 +-- src/netbsd.cc | 3 +-- src/openbsd.cc | 2 +- src/solaris.cc | 3 +-- 7 files changed, 15 insertions(+), 37 deletions(-) diff --git a/src/dragonfly.cc b/src/dragonfly.cc index 7a2fb2d89..06fc207df 100644 --- a/src/dragonfly.cc +++ b/src/dragonfly.cc @@ -126,9 +126,7 @@ int check_mount(char *s) { mntsize = getmntinfo(&mntbuf, MNT_NOWAIT); for (i = mntsize - 1; i >= 0; i--) { - if (strcmp(mntbuf[i].f_mntonname, s) == 0) { - return 1; - } + if (strcmp(mntbuf[i].f_mntonname, s) == 0) { return 1; } } return 0; @@ -178,13 +176,9 @@ int update_net_stats(void) { /* get delta */ delta = current_update_time - last_update_time; - if (delta <= 0.0001) { - return 0; - } + if (delta <= 0.0001) { return 0; } - if (getifaddrs(&ifap) < 0) { - return 0; - } + if (getifaddrs(&ifap) < 0) { return 0; } for (ifa = ifap; ifa; ifa = ifa->ifa_next) { ns = get_net_stat((const char *)ifa->ifa_name, nullptr, NULL); @@ -196,9 +190,7 @@ int update_net_stats(void) { last_recv = ns->recv; last_trans = ns->trans; - if (ifa->ifa_addr->sa_family != AF_LINK) { - continue; - } + if (ifa->ifa_addr->sa_family != AF_LINK) { continue; } for (iftmp = ifa->ifa_next; iftmp != nullptr && strcmp(ifa->ifa_name, iftmp->ifa_name) == 0; @@ -286,9 +278,7 @@ void get_cpu_count(void) { } info.cpu_usage = (float *)malloc((info.cpu_count + 1) * sizeof(float)); - if (info.cpu_usage == nullptr) { - CRIT_ERR(nullptr, NULL, "malloc"); - } + if (info.cpu_usage == nullptr) { CRIT_ERR(nullptr, NULL, "malloc"); } } struct cpu_info { @@ -357,8 +347,7 @@ int update_cpu_usage(void) { return 0; } -void free_cpu(struct text_object *) { -} +void free_cpu(struct text_object *) { /* no-op */ } int update_load_average(void) { double v[3]; @@ -492,9 +481,7 @@ void get_acpi_ac_adapter(char *p_client_buffer, size_t client_buffer_size, (void)adapter; // only linux uses this - if (!p_client_buffer || client_buffer_size <= 0) { - return; - } + if (!p_client_buffer || client_buffer_size <= 0) { return; } if (GETSYSCTL("hw.acpi.acline", state)) { fprintf(stderr, "Cannot read sysctl \"hw.acpi.acline\"\n"); @@ -714,9 +701,7 @@ void get_top_info(void) { #define APM_UNKNOWN 255 int apm_getinfo(int fd, apm_info_t aip) { - if (ioctl(fd, APMIO_GETINFO, aip) == -1) { - return -1; - } + if (ioctl(fd, APMIO_GETINFO, aip) == -1) { return -1; } return 0; } diff --git a/src/freebsd.cc b/src/freebsd.cc index 75c03d1d9..76490414b 100644 --- a/src/freebsd.cc +++ b/src/freebsd.cc @@ -371,8 +371,7 @@ int update_cpu_usage(void) { return 0; } -void free_cpu(struct text_object *) { -} +void free_cpu(struct text_object *) { /* no-op */ } int update_load_average(void) { double v[3]; @@ -644,9 +643,7 @@ int update_diskio(void) { free(dev_select); } - if (statinfo_cur.dinfo->mem_ptr) { - free(statinfo_cur.dinfo->mem_ptr); - } + if (statinfo_cur.dinfo->mem_ptr) { free(statinfo_cur.dinfo->mem_ptr); } free(statinfo_cur.dinfo); return 0; } diff --git a/src/haiku.cc b/src/haiku.cc index 62423f391..6138374ab 100644 --- a/src/haiku.cc +++ b/src/haiku.cc @@ -143,8 +143,7 @@ int update_cpu_usage() { return 1; } -void free_cpu(struct text_object *) { -} +void free_cpu(struct text_object *) { /* no-op */ } int update_load_average() { // TODO diff --git a/src/linux.cc b/src/linux.cc index a9ebd22da..b10fd7ed1 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -936,8 +936,7 @@ int update_cpu_usage(void) { return 0; } -void free_cpu(struct text_object *) { -} +void free_cpu(struct text_object *) { /* no-op */ } // fscanf() that reads floats with points even if you are using a locale where // floats are with commas diff --git a/src/netbsd.cc b/src/netbsd.cc index 514657806..4d59c9d43 100644 --- a/src/netbsd.cc +++ b/src/netbsd.cc @@ -286,8 +286,7 @@ void update_cpu_usage() { oldtotal = total; } -void free_cpu(struct text_object *) { -} +void free_cpu(struct text_object *) { /* no-op */ } void update_load_average() { double v[3]; diff --git a/src/openbsd.cc b/src/openbsd.cc index 36568ebb6..870be3623 100644 --- a/src/openbsd.cc +++ b/src/openbsd.cc @@ -400,7 +400,7 @@ void update_cpu_usage() { #endif } -void free_cpu(struct text_object *) { +void free_cpu(struct text_object *) { /* no-op */ } void update_load_average() { diff --git a/src/solaris.cc b/src/solaris.cc index 2dbbdf64f..eee15160e 100644 --- a/src/solaris.cc +++ b/src/solaris.cc @@ -314,8 +314,7 @@ int update_cpu_usage(void) { return 0; } -void free_cpu(struct text_object *) { -} +void free_cpu(struct text_object *) { /* no-op */ } void update_proc_entry(struct process *p) { psinfo_t proc;