mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-22 18:00:02 +01:00
Add push websocket fetch stats.
This commit is contained in:
@@ -77,6 +77,24 @@ object LocalMetrics {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a split for an event. Updates the last time, so future splits will have duration relative to this event.
|
||||
*
|
||||
* If an event with the provided ID does not exist, this is effectively a no-op.
|
||||
*/
|
||||
fun splitWithDuration(id: String, split: String, duration: Long) {
|
||||
val time = System.currentTimeMillis()
|
||||
|
||||
executor.execute {
|
||||
val lastTime: Long? = lastSplitTimeById[id]
|
||||
val splitDoesNotExist: Boolean = eventsById[id]?.splits?.none { it.name == split } ?: true
|
||||
if (lastTime != null && splitDoesNotExist) {
|
||||
eventsById[id]?.splits?.add(LocalMetricsSplit(split, duration))
|
||||
lastSplitTimeById[id] = time
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop tracking an event you were previously tracking. All future calls to [split] and [end] will do nothing for this id.
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* A nice interface for {@link LocalMetrics} that gives us a place to define string constants and nicer method names.
|
||||
@@ -189,6 +190,54 @@ public final class SignalLocalMetrics {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class PushWebsocketFetch {
|
||||
private static final String SUCCESS_EVENT = "push-websocket-fetch";
|
||||
private static final String TIMEOUT_EVENT = "timed-out-fetch";
|
||||
|
||||
private static final String SPLIT_BATCH_PROCESSED = "batches-processed";
|
||||
private static final String SPLIT_PROCESS_TIME = "fetch-time";
|
||||
private static final String SPLIT_TIMED_OUT = "timeout";
|
||||
|
||||
private static final AtomicInteger processedBatches = new AtomicInteger(0);
|
||||
|
||||
public static @NonNull String startFetch() {
|
||||
String baseId = System.currentTimeMillis() + "";
|
||||
|
||||
String timeoutId = TIMEOUT_EVENT + baseId;
|
||||
String successId = SUCCESS_EVENT + baseId;
|
||||
|
||||
LocalMetrics.getInstance().start(successId, SUCCESS_EVENT);
|
||||
LocalMetrics.getInstance().start(timeoutId, TIMEOUT_EVENT);
|
||||
processedBatches.set(0);
|
||||
|
||||
return baseId;
|
||||
}
|
||||
|
||||
public static void onProcessedBatch() {
|
||||
processedBatches.incrementAndGet();
|
||||
}
|
||||
|
||||
public static void onTimedOut(String metricId) {
|
||||
LocalMetrics.getInstance().cancel(SUCCESS_EVENT + metricId);
|
||||
|
||||
String timeoutId = TIMEOUT_EVENT + metricId;
|
||||
|
||||
LocalMetrics.getInstance().split(timeoutId, SPLIT_TIMED_OUT);
|
||||
LocalMetrics.getInstance().end(timeoutId);
|
||||
}
|
||||
|
||||
public static void onDrained(String metricId) {
|
||||
LocalMetrics.getInstance().cancel(TIMEOUT_EVENT + metricId);
|
||||
|
||||
String successId = SUCCESS_EVENT + metricId;
|
||||
|
||||
LocalMetrics.getInstance().split(successId, SPLIT_PROCESS_TIME);
|
||||
LocalMetrics.getInstance().splitWithDuration(successId, SPLIT_BATCH_PROCESSED, processedBatches.get());
|
||||
LocalMetrics.getInstance().end(successId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final class GroupMessageSend {
|
||||
private static final String NAME = "group-message-send";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user