summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorAlexa Panfil <alexapizza@google.com>2020-10-12 08:55:46 +0000
committerAlexa Panfil <alexapizza@google.com>2020-10-21 12:54:30 +0000
commita09e2051764c751b69eee7ba52c5e8cf7bb3197a (patch)
treee48ac16ac26d111dc754cdd5a45fdd53b290e47e /org.eclipse.jgit.test
parenta0d3680f494caa6275695fbd3397fd9b5805964d (diff)
downloadjgit-a09e2051764c751b69eee7ba52c5e8cf7bb3197a.tar.gz
jgit-a09e2051764c751b69eee7ba52c5e8cf7bb3197a.zip
Add new performance logging
Add new performance logging to register events of type duration. The proposed logging is similar to the performance logging in OS Gerrit https://gerrit-review.googlesource.com/c/gerrit/+/225628: a global Singleton (LoggingContext in Gerrit) is collecting the performance logs in a thread-safe events list, and at the end of the monitored command the list of events is retrieved and written to a log, after which it is cleared. What this patch does: The main component is the Singleton (PerformanceLogContext), which is used to collect the records (PerformanceLogRecord) in one place (ThreadLocal eventsList) from anywhere using PerformanceLogContext.getInstance().addEvent(). Reason why this change is needed: The current monitoring in JGit has several issues: 1. git fetch and git push events are handled separately (PackStatistics and ReceivedPackStatistics), with no unified way of writing or reading the statistics. 2. PostUploadHook is only invoked on the event of sending the pack, which means that the PackStatistics is not available for the fetch requests that did not end with sending the pack (negotiation requests). 3. The way the logs are created is different from the performance log approach, so the long-running operations need to be collected from both performance log (for JGit DFS overridden operations and Gerrit operations) and gitlog (for JGit ones). The proposed performance logging is going to solve the above mentioned issues: it collects all of the performance logs in one place, thus accounting for the commands that do not result in sending a pack. The logs are compatible with the ones on Gerrit. Moreover, the Singleton is accessible anywhere in the call stack, which proved to be successful in other projects like Dapper (https://research.google/pubs/pub36356/). Signed-off-by: Alexa Panfil <alexapizza@google.com> Change-Id: Iabfe667a3412d8a9db94aabb0f39b57f43469c41
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java
new file mode 100644
index 0000000000..e061833d17
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java
@@ -0,0 +1,66 @@
+package org.eclipse.jgit.logging;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import java.util.List;
+
+/**
+ * Tests for performance log context utilities.
+ */
+public class PerformanceLogContextTest {
+
+ @Test
+ public void testAddEvent() {
+ PerformanceLogRecord record = new PerformanceLogRecord("record", 0);
+ PerformanceLogContext.getInstance().addEvent(record);
+
+ List<PerformanceLogRecord> eventRecords = PerformanceLogContext
+ .getInstance().getEventRecords();
+ assertTrue(eventRecords.contains(record));
+ assertEquals(1, eventRecords.size());
+ }
+
+ @Test
+ public void testCleanEvents() {
+ PerformanceLogRecord record1 = new PerformanceLogRecord("record1", 0);
+ PerformanceLogContext.getInstance().addEvent(record1);
+
+ PerformanceLogRecord record2 = new PerformanceLogRecord("record2", 0);
+ PerformanceLogContext.getInstance().addEvent(record2);
+
+ PerformanceLogContext.getInstance().cleanEvents();
+ List<PerformanceLogRecord> eventRecords = PerformanceLogContext
+ .getInstance().getEventRecords();
+ assertEquals(0, eventRecords.size());
+ }
+
+ @Test
+ public void testAddEventsTwoThreads() {
+ TestRunnable thread1 = new TestRunnable("record1", 1);
+ TestRunnable thread2 = new TestRunnable("record2", 2);
+
+ new Thread(thread1).start();
+ new Thread(thread2).start();
+ }
+
+ private static class TestRunnable implements Runnable {
+ private String name;
+ private long durationMs;
+
+ public TestRunnable(String name, long durationMs) {
+ this.name = name;
+ this.durationMs = durationMs;
+ }
+
+ @Override
+ public void run() {
+ PerformanceLogRecord record = new PerformanceLogRecord(name,
+ durationMs);
+ PerformanceLogContext.getInstance().addEvent(record);
+ assertEquals(1, PerformanceLogContext.getInstance()
+ .getEventRecords().size());
+ }
+ }
+}