aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/profiler/BaseIndexProfiler.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/profiler/BaseIndexProfiler.java')
-rw-r--r--subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/profiler/BaseIndexProfiler.java79
1 files changed, 79 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/profiler/BaseIndexProfiler.java b/subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/profiler/BaseIndexProfiler.java
new file mode 100644
index 00000000..d3cc152e
--- /dev/null
+++ b/subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/profiler/BaseIndexProfiler.java
@@ -0,0 +1,79 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2019, Zoltan Ujhelyi, IncQuery Labs Ltd.
3 * This program and the accompanying materials are made available under the
4 * terms of the Eclipse Public License v. 2.0 which is available at
5 * http://www.eclipse.org/legal/epl-v20.html.
6 *
7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/
9package tools.refinery.viatra.runtime.base.api.profiler;
10
11import tools.refinery.viatra.runtime.base.api.NavigationHelper;
12import tools.refinery.viatra.runtime.base.core.NavigationHelperContentAdapter;
13import tools.refinery.viatra.runtime.base.core.NavigationHelperImpl;
14import tools.refinery.viatra.runtime.base.core.profiler.ProfilingNavigationHelperContentAdapter;
15import tools.refinery.viatra.runtime.matchers.util.Preconditions;
16
17/**
18 * An index profiler can be attached to an existing navigation helper instance to access the profiling data and control
19 * the profiler itself. If the NavigationHelper was not started in profiling mode, the profiler cannot be initialized.
20 *
21 * @since 2.3
22 */
23public class BaseIndexProfiler {
24
25 ProfilingNavigationHelperContentAdapter adapter;
26
27 /**
28 *
29 * @throws IllegalArgumentException if the profiler cannot be attached to the base index instance
30 */
31 public BaseIndexProfiler(NavigationHelper navigationHelper) {
32 if (navigationHelper instanceof NavigationHelperImpl) {
33 final NavigationHelperContentAdapter contentAdapter = ((NavigationHelperImpl) navigationHelper).getContentAdapter();
34 if (contentAdapter instanceof ProfilingNavigationHelperContentAdapter) {
35 adapter = (ProfilingNavigationHelperContentAdapter)contentAdapter;
36 }
37 }
38 Preconditions.checkArgument(adapter != null, "Cannot attach profiler to Base Index");
39 }
40
41 /**
42 * Returns the number of external request (e.g. model changes) the profiler recorded.
43 */
44 public long getNotificationCount() {
45 return adapter.getNotificationCount();
46 }
47
48 /**
49 * Return the total time base index profiler recorded for reacting to model operations.
50 */
51 public long getTotalMeasuredTimeInMS() {
52 return adapter.getTotalMeasuredTimeInMS();
53 }
54
55 /**
56 * Returns whether the profiler is turned on (e.g. measured values are increased).
57 */
58 public boolean isEnabled() {
59 return adapter.isEnabled();
60 }
61
62 /**
63 * Enables the base index profiling (e.g. measured values are increased)
64 */
65 public void setEnabled(boolean isEnabled) {
66 adapter.setEnabled(isEnabled);
67 }
68
69 /**
70 * Resets all measurements to 0, regardless whether the profiler is enabled or not.
71 * </p>
72 *
73 * <strong>Note</strong>: The behavior of the profiler is undefined when the measurements are reset while an EMF
74 * notification is being processed and the profiler is enabled.
75 */
76 public void resetMeasurement() {
77 adapter.resetMeasurement();
78 }
79}