Merge changes Ie2676b20,Ie8db6f85
* changes: Connectivity metrics: add WakeupStats events Connectivity metrics: collect NFLOG wakeup events
This commit is contained in:
34
core/java/android/net/metrics/WakeupEvent.java
Normal file
34
core/java/android/net/metrics/WakeupEvent.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.metrics;
|
||||
|
||||
/**
|
||||
* An event logged when NFLOG notifies userspace of a wakeup packet for
|
||||
* watched interfaces.
|
||||
* {@hide}
|
||||
*/
|
||||
public class WakeupEvent {
|
||||
public String iface;
|
||||
public long timestampMs;
|
||||
public int uid;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("WakeupEvent(%tT.%tL, %s, uid: %d)",
|
||||
timestampMs, timestampMs, iface, uid);
|
||||
}
|
||||
}
|
||||
87
core/java/android/net/metrics/WakeupStats.java
Normal file
87
core/java/android/net/metrics/WakeupStats.java
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package android.net.metrics;
|
||||
|
||||
import android.os.Process;
|
||||
import android.os.SystemClock;
|
||||
|
||||
/**
|
||||
* An event logged per interface and that aggregates WakeupEvents for that interface.
|
||||
* {@hide}
|
||||
*/
|
||||
public class WakeupStats {
|
||||
|
||||
private static final int NO_UID = -1;
|
||||
|
||||
public final long creationTimeMs = SystemClock.elapsedRealtime();
|
||||
public final String iface;
|
||||
|
||||
public long totalWakeups = 0;
|
||||
public long rootWakeups = 0;
|
||||
public long systemWakeups = 0;
|
||||
public long nonApplicationWakeups = 0;
|
||||
public long applicationWakeups = 0;
|
||||
public long unroutedWakeups = 0;
|
||||
public long durationSec = 0;
|
||||
|
||||
public WakeupStats(String iface) {
|
||||
this.iface = iface;
|
||||
}
|
||||
|
||||
/** Update durationSec with current time. */
|
||||
public void updateDuration() {
|
||||
durationSec = (SystemClock.elapsedRealtime() - creationTimeMs) / 1000;
|
||||
}
|
||||
|
||||
/** Update wakeup counters for the given WakeupEvent. */
|
||||
public void countEvent(WakeupEvent ev) {
|
||||
totalWakeups++;
|
||||
switch (ev.uid) {
|
||||
case Process.ROOT_UID:
|
||||
rootWakeups++;
|
||||
break;
|
||||
case Process.SYSTEM_UID:
|
||||
systemWakeups++;
|
||||
break;
|
||||
case NO_UID:
|
||||
unroutedWakeups++;
|
||||
break;
|
||||
default:
|
||||
if (ev.uid >= Process.FIRST_APPLICATION_UID) {
|
||||
applicationWakeups++;
|
||||
} else {
|
||||
nonApplicationWakeups++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
updateDuration();
|
||||
return new StringBuilder()
|
||||
.append("WakeupStats(").append(iface)
|
||||
.append(", total: ").append(totalWakeups)
|
||||
.append(", root: ").append(rootWakeups)
|
||||
.append(", system: ").append(systemWakeups)
|
||||
.append(", apps: ").append(applicationWakeups)
|
||||
.append(", non-apps: ").append(nonApplicationWakeups)
|
||||
.append(", unrouted: ").append(unroutedWakeups)
|
||||
.append(", ").append(durationSec).append("s)")
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user