Include message timestamp in local send timings.

This commit is contained in:
Greyson Parrelli 2024-05-13 16:00:45 -04:00 committed by Nicholas Tinsley
parent c3c743fbb8
commit b4a8f01980
6 changed files with 32 additions and 7 deletions

View file

@ -136,7 +136,7 @@ class LocalMetricsDatabase private constructor(
put(EVENT_ID, event.eventId)
put(EVENT_NAME, event.eventName)
put(SPLIT_NAME, split.name)
put(DURATION, event.timeunit.convert(split.duration, TimeUnit.NANOSECONDS))
put(DURATION, event.timeUnit.convert(split.duration, TimeUnit.NANOSECONDS))
}
)
}

View file

@ -10,10 +10,12 @@ data class LocalMetricsEvent(
val eventId: String,
val eventName: String,
val splits: MutableList<LocalMetricsSplit>,
val timeunit: TimeUnit
val timeUnit: TimeUnit,
val extraLabel: String? = null
) {
override fun toString(): String {
return "[$eventName] total: ${splits.sumOf { it.duration }.fractionalMillis(timeunit)} | ${splits.map { it.toString() }.joinToString(", ")}"
val extra = extraLabel?.let { "[$extraLabel]" } ?: ""
return "[$eventName]$extra total: ${splits.sumOf { it.duration }.fractionalMillis(timeUnit)} | ${splits.map { it.toString() }.joinToString(", ")}"
}
private fun Long.fractionalMillis(timeunit: TimeUnit): String {

View file

@ -323,7 +323,7 @@ public class IndividualSendJob extends PushSendJob {
SignalDatabase.messageLog().insertIfPossible(messageRecipient.getId(), message.getSentTimeMillis(), result, ContentHint.RESENDABLE, new MessageId(messageId), false);
return syncAccess.isPresent();
} else {
SignalLocalMetrics.IndividualMessageSend.onDeliveryStarted(messageId);
SignalLocalMetrics.IndividualMessageSend.onDeliveryStarted(messageId, message.getSentTimeMillis());
SendMessageResult result = messageSender.sendDataMessage(address, UnidentifiedAccessUtil.getAccessFor(context, messageRecipient), ContentHint.RESENDABLE, mediaMessage, new MetricEventListener(messageId), message.isUrgent(), messageRecipient.getNeedsPniSignature());
SignalDatabase.messageLog().insertIfPossible(messageRecipient.getId(), message.getSentTimeMillis(), result, ContentHint.RESENDABLE, new MessageId(messageId), message.isUrgent());

View file

@ -186,6 +186,8 @@ public final class PushGroupSendJob extends PushSendJob {
Set<NetworkFailure> existingNetworkFailures = new HashSet<>(message.getNetworkFailures());
Set<IdentityKeyMismatch> existingIdentityMismatches = new HashSet<>(message.getIdentityKeyMismatches());
SignalLocalMetrics.GroupMessageSend.setSentTimestamp(messageId, message.getSentTimeMillis());
ApplicationDependencies.getJobManager().cancelAllInQueue(TypingSendJob.getQueue(threadId));
if (database.isSent(messageId)) {

View file

@ -56,7 +56,7 @@ object LocalMetrics {
eventId = id,
eventName = name,
splits = mutableListOf(),
timeunit = timeunit
timeUnit = timeunit
)
lastSplitTimeById[id] = time
}
@ -76,12 +76,21 @@ object LocalMetrics {
val splitDoesNotExist: Boolean = eventsById[id]?.splits?.none { it.name == split } ?: true
if (lastTime != null && splitDoesNotExist) {
val event = eventsById[id]
event?.splits?.add(LocalMetricsSplit(split, time - lastTime, event.timeunit))
event?.splits?.add(LocalMetricsSplit(split, time - lastTime, event.timeUnit))
lastSplitTimeById[id] = time
}
}
}
fun setLabel(id: String, label: String) {
executor.execute {
val event = eventsById[id]
if (event != null) {
eventsById[id] = event.copy(extraLabel = label)
}
}
}
/**
* Marks a split for an event. Updates the last time, so future splits will have duration relative to this event.
*

View file

@ -154,8 +154,13 @@ public final class SignalLocalMetrics {
split(messageId, SPLIT_JOB_ENQUEUE);
}
public static void onDeliveryStarted(long messageId) {
public static void onDeliveryStarted(long messageId, long sentTimestamp) {
split(messageId, SPLIT_JOB_PRE_NETWORK);
String splitId = ID_MAP.get(messageId);
if (splitId != null) {
LocalMetrics.getInstance().setLabel(splitId, String.valueOf(sentTimestamp));
}
}
public static void onMessageEncrypted(long messageId) {
@ -337,6 +342,13 @@ public final class SignalLocalMetrics {
split(messageId, SPLIT_JOB_ENQUEUE);
}
public static void setSentTimestamp(long messageId, long sentTimestamp) {
String splitId = ID_MAP.get(messageId);
if (splitId != null) {
LocalMetrics.getInstance().setLabel(splitId, String.valueOf(sentTimestamp));
}
}
public static void onSenderKeyStarted(long messageId) {
split(messageId, SPLIT_JOB_PRE_NETWORK);
}