-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
addpkg(x11/xfce4-cpugraph-plugin): 1.2.10
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" | ||
} |