FreeBSD Bugzilla – Attachment 243720 Details for
Bug 272831
x11/polybar: Add patches for CPU and memory module
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
patch
0001-x11-polybar-Add-patches-for-CPU-memory-modules.patch (text/plain), 6.07 KB, created by
Joel Bodenmann
on 2023-07-30 22:21:14 UTC
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
Joel Bodenmann
Created:
2023-07-30 22:21:14 UTC
Size:
6.07 KB
patch
obsolete
>From 08c8fd5e7772992bb7f8aaf173883065f2b8d0d0 Mon Sep 17 00:00:00 2001 >From: Joel Bodenmann <jbo@insane.engineer> >Date: Mon, 31 Jul 2023 00:18:51 +0200 >Subject: [PATCH] x11/polybar: Add patches for CPU & memory modules > >This adds patches to make the CPU and memory modules of polybar work under FreeBSD. >--- > x11/polybar/Makefile | 2 +- > x11/polybar/files/patch-src_modules_cpu.cpp | 66 +++++++++++++++++++ > .../files/patch-src_modules_memory.cpp | 49 ++++++++++++++ > x11/polybar/pkg-message | 4 +- > 4 files changed, 118 insertions(+), 3 deletions(-) > create mode 100644 x11/polybar/files/patch-src_modules_cpu.cpp > create mode 100644 x11/polybar/files/patch-src_modules_memory.cpp > >diff --git a/x11/polybar/Makefile b/x11/polybar/Makefile >index c0de6b457..7772fd420 100644 >--- a/x11/polybar/Makefile >+++ b/x11/polybar/Makefile >@@ -1,6 +1,6 @@ > PORTNAME= polybar > DISTVERSION= 3.6.3 >-PORTREVISION= 1 >+PORTREVISION= 2 > CATEGORIES= x11 > MASTER_SITES= https://github.com/polybar/polybar/releases/download/${DISTVERSION}/ > >diff --git a/x11/polybar/files/patch-src_modules_cpu.cpp b/x11/polybar/files/patch-src_modules_cpu.cpp >new file mode 100644 >index 000000000..6e2682d53 >--- /dev/null >+++ b/x11/polybar/files/patch-src_modules_cpu.cpp >@@ -0,0 +1,66 @@ >+diff --git src/modules/cpu.cpp src/modules/cpu.cpp >+index 527f27fb..179d9221 100644 >+--- src/modules/cpu.cpp >++++ src/modules/cpu.cpp >+@@ -2,6 +2,11 @@ >+ >+ #include <fstream> >+ #include <istream> >++#ifdef __FreeBSD__ >++ #include <sys/types.h> >++ #include <sys/resource.h> >++ #include <sys/sysctl.h> >++#endif >+ >+ #include "drawtypes/label.hpp" >+ #include "drawtypes/progressbar.hpp" >+@@ -128,6 +133,41 @@ namespace modules { >+ m_cputimes.clear(); >+ >+ try { >++#ifdef __FreeBSD__ >++ // Get number of CPUs >++ // ToDo: No need to do this on every invocation. >++ int ncpu = -1; >++ std::size_t sz = sizeof(ncpu); >++ if (sysctlbyname("hw.ncpu", &ncpu, &sz, nullptr, 0) != 0) { >++ m_log.err("Failed to query sysctl 'hw.ncpu' (errno: %s)", strerror(errno)); >++ return false; >++ } >++ if (ncpu < 1) { >++ m_log.err("Failed to determine number of CPUs."); >++ return false; >++ } >++ >++ // Query 'kern.cp_time' >++ long cpu_stat[CPUSTATES]; >++ sz = sizeof(cpu_stat); >++ if (sysctlbyname("kern.cp_time", cpu_stat, &sz, nullptr, 0) != 0) { >++ m_log.err("Failed to query sysctl 'kern.cp_time' (errno: %s)", strerror(errno)); >++ return false; >++ } >++ >++ // Parse >++ static std::size_t field_offset = sizeof(*cpu_stat) + ncpu; >++ for (std::size_t i = 0; i < ncpu; i++) { >++ m_cputimes.emplace_back(new cpu_time); >++ m_cputimes.back()->user = cpu_stat[CP_USER]; >++ m_cputimes.back()->nice = cpu_stat[CP_NICE]; >++ m_cputimes.back()->system = cpu_stat[CP_SYS]; >++ m_cputimes.back()->steal = cpu_stat[CP_INTR]; // Note: This is technically the reported "interrupt" time >++ m_cputimes.back()->idle = cpu_stat[CP_IDLE]; >++ m_cputimes.back()->total = m_cputimes.back()->user + m_cputimes.back()->nice + m_cputimes.back()->system + >++ m_cputimes.back()->idle + m_cputimes.back()->steal; >++ } >++#else >+ std::ifstream in(PATH_CPU_INFO); >+ string str; >+ >+@@ -148,6 +188,7 @@ namespace modules { >+ m_cputimes.back()->total = m_cputimes.back()->user + m_cputimes.back()->nice + m_cputimes.back()->system + >+ m_cputimes.back()->idle + m_cputimes.back()->steal; >+ } >++#endif >+ } catch (const std::ios_base::failure& e) { >+ m_log.err("Failed to read CPU values (what: %s)", e.what()); >+ } >diff --git a/x11/polybar/files/patch-src_modules_memory.cpp b/x11/polybar/files/patch-src_modules_memory.cpp >new file mode 100644 >index 000000000..e94b05608 >--- /dev/null >+++ b/x11/polybar/files/patch-src_modules_memory.cpp >@@ -0,0 +1,49 @@ >+diff --git src/modules/memory.cpp src/modules/memory.cpp >+index eb36e5dc..042d85cb 100644 >+--- src/modules/memory.cpp >++++ src/modules/memory.cpp >+@@ -1,6 +1,10 @@ >+ #include <fstream> >+ #include <iomanip> >+ #include <istream> >++#ifdef __FreeBSD__ >++ #include <sys/types.h> >++ #include <sys/sysctl.h> >++#endif >+ >+ #include "drawtypes/label.hpp" >+ #include "drawtypes/progressbar.hpp" >+@@ -63,6 +67,25 @@ namespace modules { >+ unsigned long long kb_swap_free{0ULL}; >+ >+ try { >++#ifdef __FreeBSD__ >++ std::size_t sz; >++ >++ // Total >++ sz = sizeof(kb_total); >++ if (sysctlbyname("hw.physmem", &kb_total, &sz, nullptr, 0) != 0) { >++ m_log.err("Failed to query sysctl 'hw.physmem' (errno: %s)", strerror(errno)); >++ return false; >++ } >++ kb_total /= 1024; >++ >++ // Available >++ sz = sizeof(kb_avail); >++ if (sysctlbyname("hw.usermem", &kb_avail, &sz, nullptr, 0) != 0) { >++ m_log.err("Failed to query sysctl 'hw.usermem' (errno: %s)", strerror(errno)); >++ return false; >++ } >++ kb_avail /= 1024; >++#else >+ std::ifstream meminfo(PATH_MEMORY_INFO); >+ std::map<std::string, unsigned long long int> parsed; >+ >+@@ -91,6 +114,7 @@ namespace modules { >+ // old kernel; give a best-effort approximation of available memory >+ kb_avail = parsed["MemFree"] + parsed["Buffers"] + parsed["Cached"] + parsed["SReclaimable"] - parsed["Shmem"]; >+ } >++#endif >+ } catch (const std::exception& err) { >+ m_log.err("Failed to read memory values (what: %s)", err.what()); >+ } >diff --git a/x11/polybar/pkg-message b/x11/polybar/pkg-message >index ed6bc5b10..30a0aa183 100644 >--- a/x11/polybar/pkg-message >+++ b/x11/polybar/pkg-message >@@ -6,10 +6,12 @@ not function in FreeBSD. > > Working modules: > - bspwm >+- cpu > - date > - github > - i3 > - ipc (polybar-msg method does not seem to work) >+- memory > - menu > - mpd > - script >@@ -19,9 +21,7 @@ Working modules: > - xworkspaces (not extensively tested) > > Broken modules: >-- cpu > - filesystem >-- memory > - network (requires wireless_tools) > - temperature (requires /sys/class/thermal/* in sysfs) > - volume (requires full alsa, not a wrapper) >-- >2.41.0 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
jbo
:
maintainer-approval?
Actions:
View
|
Diff
Attachments on
bug 272831
: 243720