Skip to content

Commit

Permalink
Keeps track of the duration.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev committed Jun 3, 2019
1 parent 6c316f4 commit 45c5c4a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/jitsi/utils/queue/QueueStatistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public class QueueStatistics
*/
private AtomicInteger totalPacketsDropped = new AtomicInteger();

/**
* The time the first packet was added.
*/
private long firstPacketAddedMs = -1;

/**
* Initializes a new {@link QueueStatistics} instance.
*
Expand All @@ -89,6 +94,9 @@ public JSONObject getStats()
stats.put("add_rate", addRate.getRate(now));
stats.put("remove_rate", removeRate.getRate(now));
stats.put("drop_rate", dropRate.getRate(now));
double duration = (now - firstPacketAddedMs) / 1000;
stats.put("duration_s", duration);
stats.put("average_remove_rate_pps", totalPacketsRemoved.get() / duration);

return stats;
}
Expand All @@ -100,6 +108,10 @@ public JSONObject getStats()
*/
void add(long now)
{
if (firstPacketAddedMs < 0)
{
firstPacketAddedMs = now;
}
addRate.update(1, now);
totalPacketsAdded.incrementAndGet();
}
Expand Down

0 comments on commit 45c5c4a

Please sign in to comment.