Skip to content

Commit

Permalink
addpkg(x11/xfce4-cpugraph-plugin): 1.2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
knyipab authored and licy183 committed Jun 22, 2024
1 parent cc92f43 commit 70afae4
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
80 changes: 80 additions & 0 deletions x11-packages/xfce4-cpugraph-plugin/0001-cpu-data.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
diff --git a/panel-plugin/os.cc b/panel-plugin/os.cc
index a8c9e40..887c5f3 100644
--- a/panel-plugin/os.cc
+++ b/panel-plugin/os.cc
@@ -42,6 +42,11 @@

using namespace std;

+#ifdef __ANDROID__
+#include <math.h>
+#include <unistd.h>
+#endif
+
#if defined (__linux__) || defined (__FreeBSD_kernel__)
#define PROC_STAT "/proc/stat"
#define PROCMAXLNLEN 256 /* should make it */
@@ -78,7 +83,7 @@ using namespace std;
static kstat_ctl_t *kc;
#endif

-#if defined (__linux__) || defined (__FreeBSD_kernel__)
+#if (defined (__linux__) && !defined (__ANDROID__)) || defined (__FreeBSD_kernel__)
void
read_cpu_data (unordered_map<guint, CpuData> &data, unordered_map<guint, guint> &cpu_to_index)
{
@@ -401,12 +406,53 @@ read_cpu_data (unordered_map<guint, CpuData> &data)
data[0].load /= nb_cpu;
return true;
}
+#elif defined (__ANDROID__)
+
+static guint
+detect_cpu_number ()
+{
+ return sysconf(_SC_NPROCESSORS_ONLN);
+}
+
+static bool
+read_cpu_data (unordered_map<guint, CpuData> &data)
+{
+ FILE* top_process;
+ int pid;
+ float cpu_usage;
+ int cpu_index;
+ char line[100];
+
+ if (G_UNLIKELY(data.size() == 0))
+ return false;
+
+ const size_t nb_cpu = data.size()-1;
+
+ for (int i = 0; i <= nb_cpu; i++) {
+ data[i].user = 0;
+ data[i].load = 0;
+ }
+
+ if ((top_process = popen("top -H -b -q -o TID,%CPU,CPU -s 2 -n 1", "r"))) {
+ while (fgets(line, sizeof(line), top_process) != NULL) {
+ if (sscanf(line, "%d %f %d", &pid, &cpu_usage, &cpu_index) == 3) {
+ data[cpu_index+1].user += cpu_usage / 100;
+ data[cpu_index+1].load += cpu_usage / 100;
+ data[0].user += cpu_usage / 100 / nb_cpu;
+ data[0].load += cpu_usage / 100 / nb_cpu;
+ if (cpu_usage < 0.05) break;
+ }
+ }
+ pclose(top_process);
+ }
+ return true;
+}
#else
#error "Your OS is not supported."
#endif


-#if !(defined (__linux__) || defined (__FreeBSD_kernel__))
+#if !(defined (__linux__) || defined (__FreeBSD_kernel__)) || defined (__ANDROID__)
void
read_cpu_data (unordered_map<guint, CpuData> &data, unordered_map<guint, guint> &cpu_to_index)
{
13 changes: 13 additions & 0 deletions x11-packages/xfce4-cpugraph-plugin/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
TERMUX_PKG_HOMEPAGE=https://docs.xfce.org/panel-plugins/xfce4-cpugraph-plugin/start
TERMUX_PKG_DESCRIPTION="Graphical representation of the CPU load"
TERMUX_PKG_LICENSE="GPL-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION="1.2.10"
TERMUX_PKG_SRCURL=https://archive.xfce.org/src/panel-plugins/xfce4-cpugraph-plugin/${TERMUX_PKG_VERSION%.*}/xfce4-cpugraph-plugin-${TERMUX_PKG_VERSION}.tar.bz2
TERMUX_PKG_SHA256=37792dd052691712195658169b95fb6583f924485ce7a467b33d01e08775d915
TERMUX_PKG_AUTO_UPDATE=true
TERMUX_PKG_DEPENDS="xfce4-panel"

termux_step_pre_configure() {
LDFLAGS+=" $($CC -print-libgcc-file-name)"
}

0 comments on commit 70afae4

Please sign in to comment.