Show actual / maximum number of open files in speed notification

Refs #311
This commit is contained in:
M66B 2016-02-11 10:33:43 +01:00
parent 9f07fdb39a
commit 556ef90e04
2 changed files with 21 additions and 23 deletions

View File

@ -146,7 +146,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
private native void jni_stop(int tun, boolean clear);
private native int[] jni_get_session_count();
private native int[] jni_get_stats();
private static native void jni_pcap(String name);
@ -635,27 +635,9 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
// Show session/file count
if (filter && loglevel <= Log.WARN) {
int[] count = jni_get_session_count();
int[] count = jni_get_stats();
remoteViews.setTextViewText(R.id.tvSessions, count[0] + "/" + count[1] + "/" + count[2]);
File proc = new File("/proc/sys/fs/file-nr");
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(proc));
String line = br.readLine();
String[] filenr = line.split("\\s+");
if (filenr.length == 3) {
int perc = Integer.parseInt(filenr[0]) * 100 / Integer.parseInt(filenr[2]);
remoteViews.setTextViewText(R.id.tvFiles, perc + "%");
}
} catch (Throwable ignored) {
} finally {
if (br != null)
try {
br.close();
} catch (IOException ignored) {
}
}
remoteViews.setTextViewText(R.id.tvFiles, count[3] + "/" + count[4]);
}
// Show notification

View File

@ -174,12 +174,14 @@ Java_eu_faircode_netguard_SinkholeService_jni_1stop(
log_android(ANDROID_LOG_WARN, "Not running thread %x", t);
}
#include <dirent.h>
JNIEXPORT jintArray JNICALL
Java_eu_faircode_netguard_SinkholeService_jni_1get_1session_1count(JNIEnv *env, jobject instance) {
Java_eu_faircode_netguard_SinkholeService_jni_1get_1stats(JNIEnv *env, jobject instance) {
if (pthread_mutex_lock(&lock))
log_android(ANDROID_LOG_ERROR, "pthread_mutex_lock failed");
jintArray jarray = (*env)->NewIntArray(env, 3);
jintArray jarray = (*env)->NewIntArray(env, 5);
jint *jcount = (*env)->GetIntArrayElements(env, jarray, NULL);
jcount[0] = get_icmp_sessions();
jcount[1] = get_udp_sessions();
@ -188,6 +190,20 @@ Java_eu_faircode_netguard_SinkholeService_jni_1get_1session_1count(JNIEnv *env,
if (pthread_mutex_unlock(&lock))
log_android(ANDROID_LOG_ERROR, "pthread_mutex_unlock failed");
jcount[3] = 0;
DIR *d = opendir("/proc/self/fd");
if (d) {
struct dirent *dir;
while ((dir = readdir(d)) != NULL)
if (dir->d_type != DT_DIR)
jcount[3]++;
closedir(d);
}
struct rlimit rlim;
memset(&rlim, 0, sizeof(struct rlimit));
getrlimit(RLIMIT_NOFILE, &rlim);
jcount[4] = rlim.rlim_cur;
(*env)->ReleaseIntArrayElements(env, jarray, jcount, NULL);
return jarray;