aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/logging/PerformanceLogContext.java
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/logging/PerformanceLogContext.java')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/logging/PerformanceLogContext.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/logging/PerformanceLogContext.java b/org.eclipse.jgit/src/org/eclipse/jgit/logging/PerformanceLogContext.java
new file mode 100644
index 0000000000..fab0dd102a
--- /dev/null
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/logging/PerformanceLogContext.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2020, Google LLC and others
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+package org.eclipse.jgit.logging;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Singleton that collects performance logs.
+ *
+ * @since 5.10
+ */
+public class PerformanceLogContext {
+ /** Singleton instance that stores the statistics. */
+ private static final PerformanceLogContext INSTANCE = new PerformanceLogContext();
+
+ /** List that stores events as performance logs. */
+ private static final ThreadLocal<List<PerformanceLogRecord>> eventRecords = ThreadLocal
+ .withInitial(ArrayList::new);
+
+ private PerformanceLogContext() {
+ }
+
+ /**
+ * Get the instance of the context.
+ *
+ * @return instance of performance log context.
+ */
+ public static PerformanceLogContext getInstance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Get the unmodifiable list of events as performance records.
+ *
+ * @return unmodifiable list of events as performance logs.
+ */
+ public List<PerformanceLogRecord> getEventRecords() {
+ return Collections.unmodifiableList(eventRecords.get());
+ }
+
+ /**
+ * Adds a performance log record to the current list of events.
+ *
+ * @param record
+ * performance log record that is going to be added.
+ */
+ public void addEvent(PerformanceLogRecord record) {
+ eventRecords.get().add(record);
+ }
+
+ /**
+ * Removes all of the existing records from the current list of events.
+ */
+ public void cleanEvents() {
+ eventRecords.remove();
+ }
+} \ No newline at end of file