mirror of
https://github.com/emanuele-f/PCAPdroid.git
synced 2026-06-16 21:10:57 +08:00
If enabled, show allocs summary in the Stats
This commit is contained in:
parent
4645b16a05
commit
f018c82cc3
@ -58,6 +58,7 @@ public class StatsActivity extends BaseActivity {
|
||||
private TextView mDnsQueries;
|
||||
private TableLayout mTable;
|
||||
private TextView mBlacklistsStatus;
|
||||
private TextView mAllocStats;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -80,6 +81,7 @@ public class StatsActivity extends BaseActivity {
|
||||
mDnsQueries = findViewById(R.id.dns_queries);
|
||||
mDnsServer = findViewById(R.id.dns_server);
|
||||
mBlacklistsStatus = findViewById(R.id.blacklists_status);
|
||||
mAllocStats = findViewById(R.id.alloc_stats);
|
||||
|
||||
if(CaptureService.isCapturingAsRoot()) {
|
||||
findViewById(R.id.dns_server_row).setVisibility(View.GONE);
|
||||
@ -139,6 +141,11 @@ public class StatsActivity extends BaseActivity {
|
||||
|
||||
if(stats.num_dropped_conns > 0)
|
||||
mDroppedConns.setTextColor(Color.RED);
|
||||
|
||||
if(stats.alloc_summary != null) {
|
||||
mAllocStats.setVisibility(View.VISIBLE);
|
||||
mAllocStats.setText(stats.alloc_summary);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -22,6 +22,7 @@ package com.emanuelef.remote_capture.model;
|
||||
import java.io.Serializable;
|
||||
|
||||
public class VPNStats implements Serializable {
|
||||
public String alloc_summary;
|
||||
public long bytes_sent;
|
||||
public long bytes_rcvd;
|
||||
public int pkts_sent;
|
||||
@ -35,9 +36,11 @@ public class VPNStats implements Serializable {
|
||||
public int num_dns_queries;
|
||||
|
||||
/* Invoked by native code */
|
||||
public void setData(long _bytes_sent, long _bytes_rcvd, int _pkts_sent, int _pkts_rcvd,
|
||||
public void setData(String _alloc_summary,
|
||||
long _bytes_sent, long _bytes_rcvd, int _pkts_sent, int _pkts_rcvd,
|
||||
int _pkts_dropped, int _num_dropped_conns, int _num_open_sockets,
|
||||
int _max_fd, int _active_conns, int _tot_conns, int _num_dns_queries) {
|
||||
alloc_summary = _alloc_summary;
|
||||
bytes_sent = _bytes_sent;
|
||||
bytes_rcvd = _bytes_rcvd;
|
||||
pkts_sent = _pkts_sent;
|
||||
|
||||
@ -166,4 +166,18 @@ jmethodID jniGetMethodID(JNIEnv *env, jclass cls, const char *name, const char *
|
||||
}
|
||||
|
||||
return method;
|
||||
}
|
||||
|
||||
/* ******************************************************* */
|
||||
|
||||
char* humanSize(char *buf, int bufsize, double bytes) {
|
||||
static char *suffix[] = {"B", "KB", "MB", "GB", "TB"};
|
||||
int num_suffix = sizeof(suffix) / sizeof(suffix[0]);
|
||||
int i;
|
||||
|
||||
for(i = 0; (bytes >= 1024) && (i < num_suffix); i++)
|
||||
bytes /= 1024;
|
||||
|
||||
snprintf(buf, bufsize, "%.02f %s", bytes, suffix[i]);
|
||||
return buf;
|
||||
}
|
||||
@ -46,5 +46,6 @@ char loglvl2char(int lvl);
|
||||
jclass jniFindClass(JNIEnv *env, const char *name);
|
||||
jmethodID jniGetMethodID(JNIEnv *env, jclass cls, const char *name, const char *signature);
|
||||
int jniCheckException(JNIEnv *env);
|
||||
char* humanSize(char *buf, int bufsize, double bytes);
|
||||
|
||||
#endif // __LOG_UTILS_H__
|
||||
|
||||
@ -844,10 +844,40 @@ cleanup:
|
||||
|
||||
/* ******************************************************* */
|
||||
|
||||
#ifdef PCAPDROID_TRACK_ALLOCS
|
||||
|
||||
static char allocs_buf[1024];
|
||||
|
||||
static char* get_allocs_summary() {
|
||||
char b1[16], b2[16], b3[16], b4[16];
|
||||
|
||||
snprintf(allocs_buf, sizeof(allocs_buf),
|
||||
"*** Allocs Summary ***\n"
|
||||
" PCAPdroid: %s\n"
|
||||
" nDPI: %s\n"
|
||||
" Blacklist (domains): %s\n"
|
||||
" UTHash: %s\n",
|
||||
humanSize(b1, 32, memtrack.scopes[MEMTRACK_PCAPDROID]),
|
||||
humanSize(b2, 32, memtrack.scopes[MEMTRACK_NDPI]),
|
||||
humanSize(b3, 32, memtrack.scopes[MEMTRACK_BLACKLIST]),
|
||||
humanSize(b4, 32, memtrack.scopes[MEMTRACK_UTHASH]));
|
||||
return allocs_buf;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ******************************************************* */
|
||||
|
||||
static void sendStatsDump(const vpnproxy_data_t *proxy) {
|
||||
JNIEnv *env = proxy->env;
|
||||
const capture_stats_t *capstats = &proxy->capture_stats;
|
||||
const zdtun_statistics_t *stats = &proxy->stats;
|
||||
jstring allocs_summary =
|
||||
#ifdef PCAPDROID_TRACK_ALLOCS
|
||||
(*proxy->env)->NewStringUTF(proxy->env, get_allocs_summary());
|
||||
#else
|
||||
NULL;
|
||||
#endif
|
||||
|
||||
int active_conns = (int)(stats->num_icmp_conn + stats->num_tcp_conn + stats->num_udp_conn);
|
||||
int tot_conns = (int)(stats->num_icmp_opened + stats->num_tcp_opened + stats->num_udp_opened);
|
||||
@ -860,16 +890,19 @@ static void sendStatsDump(const vpnproxy_data_t *proxy) {
|
||||
}
|
||||
|
||||
(*env)->CallVoidMethod(env, stats_obj, mids.statsSetData,
|
||||
allocs_summary,
|
||||
capstats->sent_bytes, capstats->rcvd_bytes,
|
||||
capstats->sent_pkts, capstats->rcvd_pkts,
|
||||
min(proxy->num_dropped_pkts, INT_MAX), proxy->num_dropped_connections,
|
||||
stats->num_open_sockets, stats->all_max_fd, active_conns, tot_conns, proxy->num_dns_requests);
|
||||
stats->num_open_sockets, stats->all_max_fd, active_conns, tot_conns,
|
||||
proxy->num_dns_requests);
|
||||
|
||||
if(!jniCheckException(env)) {
|
||||
(*env)->CallVoidMethod(env, proxy->vpn_service, mids.sendStatsDump, stats_obj);
|
||||
jniCheckException(env);
|
||||
}
|
||||
|
||||
(*env)->DeleteLocalRef(env, allocs_summary);
|
||||
(*env)->DeleteLocalRef(env, stats_obj);
|
||||
}
|
||||
|
||||
@ -958,24 +991,6 @@ static void reload_blacklists(vpnproxy_data_t *proxy) {
|
||||
|
||||
/* ******************************************************* */
|
||||
|
||||
#ifdef PCAPDROID_TRACK_ALLOCS
|
||||
|
||||
static void print_allocs_summary() {
|
||||
log_w("*** Allocs Summary ***\n"
|
||||
" PCAPdroid: %zu B\n"
|
||||
" nDPI: %zu B\n"
|
||||
" Blacklist (domains): %zu B\n"
|
||||
" UTHash: %zu B\n",
|
||||
memtrack.scopes[MEMTRACK_PCAPDROID],
|
||||
memtrack.scopes[MEMTRACK_NDPI],
|
||||
memtrack.scopes[MEMTRACK_BLACKLIST],
|
||||
memtrack.scopes[MEMTRACK_UTHASH]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ******************************************************* */
|
||||
|
||||
void run_housekeeping(vpnproxy_data_t *proxy) {
|
||||
if(proxy->capture_stats.new_stats
|
||||
&& ((proxy->now_ms - proxy->capture_stats.last_update_ms) >= CAPTURE_STATS_UPDATE_FREQUENCY_MS) ||
|
||||
@ -994,9 +1009,6 @@ void run_housekeeping(vpnproxy_data_t *proxy) {
|
||||
last_connections_dump = proxy->now_ms;
|
||||
next_connections_dump = proxy->now_ms + CONNECTION_DUMP_UPDATE_FREQUENCY_MS;
|
||||
netd_resolve_waiting = 0;
|
||||
#ifdef PCAPDROID_TRACK_ALLOCS
|
||||
print_allocs_summary();
|
||||
#endif
|
||||
} else if ((proxy->pcap_dump.buffer_idx > 0)
|
||||
&& (proxy->now_ms - proxy->pcap_dump.last_dump_ms) >= MAX_JAVA_DUMP_DELAY_MS) {
|
||||
javaPcapDump(proxy);
|
||||
@ -1153,7 +1165,7 @@ static int run_tun(JNIEnv *env, jclass vpn, int tunfd, jint sdk) {
|
||||
mids.connUpdateSetStats = jniGetMethodID(env, cls.conn_update, "setStats", "(JJJIIII)V");
|
||||
mids.connUpdateSetInfo = jniGetMethodID(env, cls.conn_update, "setInfo", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
mids.statsInit = jniGetMethodID(env, cls.stats, "<init>", "()V");
|
||||
mids.statsSetData = jniGetMethodID(env, cls.stats, "setData", "(JJIIIIIIIII)V");
|
||||
mids.statsSetData = jniGetMethodID(env, cls.stats, "setData", "(Ljava/lang/String;JJIIIIIIIII)V");
|
||||
|
||||
vpnproxy_data_t proxy = {
|
||||
.tunfd = tunfd,
|
||||
@ -1286,7 +1298,7 @@ static int run_tun(JNIEnv *env, jclass vpn, int tunfd, jint sdk) {
|
||||
global_proxy = NULL;
|
||||
|
||||
#ifdef PCAPDROID_TRACK_ALLOCS
|
||||
print_allocs_summary();
|
||||
log_i(get_allocs_summary());
|
||||
#endif
|
||||
|
||||
return(rv);
|
||||
|
||||
@ -242,13 +242,13 @@ android:layout_height="fill_parent">
|
||||
<RelativeLayout
|
||||
android:id="@+id/blacklists_status_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/blacklists_status_lbl"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:text="@string/blacklists_status"
|
||||
android:textStyle="bold" />
|
||||
@ -260,6 +260,15 @@ android:layout_height="fill_parent">
|
||||
android:layout_below="@+id/blacklists_status_lbl"
|
||||
tools:text="Up-to-date: 4/4 ― Domain rules: 12k ― IP rules: 800\nLast update: 3h ago" />
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/alloc_stats"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
tools:text="Alloc Stats..."/>
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
Loading…
Reference in New Issue
Block a user