You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by sh...@apache.org on 2018/02/19 14:24:00 UTC
incubator-unomi git commit: UNOMI-161 Rename callee to caller
Repository: incubator-unomi
Updated Branches:
refs/heads/master 384ed0262 -> 53ea767d0
UNOMI-161 Rename callee to caller
Signed-off-by: Serge Huber <sh...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/53ea767d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/53ea767d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/53ea767d
Branch: refs/heads/master
Commit: 53ea767d08bb4579abe13b4e5a6eef87c87bf1bf
Parents: 384ed02
Author: Serge Huber <sh...@apache.org>
Authored: Mon Feb 19 15:22:07 2018 +0100
Committer: Serge Huber <sh...@apache.org>
Committed: Mon Feb 19 15:23:48 2018 +0100
----------------------------------------------------------------------
.../org/apache/unomi/metrics/CalleeCount.java | 29 ---------
.../org/apache/unomi/metrics/CallerCount.java | 29 +++++++++
.../java/org/apache/unomi/metrics/Metric.java | 2 +-
.../apache/unomi/metrics/MetricsService.java | 15 ++++-
.../metrics/commands/CalleeStatusCommand.java | 64 -------------------
.../metrics/commands/CallerStatusCommand.java | 64 +++++++++++++++++++
.../unomi/metrics/commands/ListCommand.java | 14 ++---
.../unomi/metrics/commands/ViewCommand.java | 2 +-
.../unomi/metrics/internal/CalleeCountImpl.java | 66 --------------------
.../unomi/metrics/internal/CallerCountImpl.java | 66 ++++++++++++++++++++
.../unomi/metrics/internal/MetricImpl.java | 9 ++-
.../metrics/internal/MetricsServiceImpl.java | 44 ++++++-------
.../resources/OSGI-INF/blueprint/blueprint.xml | 2 +-
.../metrics/internal/MetricsServiceTest.java | 23 ++++---
14 files changed, 219 insertions(+), 210 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/java/org/apache/unomi/metrics/CalleeCount.java
----------------------------------------------------------------------
diff --git a/metrics/src/main/java/org/apache/unomi/metrics/CalleeCount.java b/metrics/src/main/java/org/apache/unomi/metrics/CalleeCount.java
deleted file mode 100644
index 3552b12..0000000
--- a/metrics/src/main/java/org/apache/unomi/metrics/CalleeCount.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.unomi.metrics;
-
-import java.util.List;
-
-public interface CalleeCount {
-
- String getHash();
- List<String> getCallee();
- long getCount();
- long incCount();
- long getTotalTime();
- long addTime(long time);
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/java/org/apache/unomi/metrics/CallerCount.java
----------------------------------------------------------------------
diff --git a/metrics/src/main/java/org/apache/unomi/metrics/CallerCount.java b/metrics/src/main/java/org/apache/unomi/metrics/CallerCount.java
new file mode 100644
index 0000000..c0fedcf
--- /dev/null
+++ b/metrics/src/main/java/org/apache/unomi/metrics/CallerCount.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.metrics;
+
+import java.util.List;
+
+public interface CallerCount {
+
+ String getHash();
+ List<String> getCaller();
+ long getCount();
+ long incCount();
+ long getTotalTime();
+ long addTime(long time);
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/java/org/apache/unomi/metrics/Metric.java
----------------------------------------------------------------------
diff --git a/metrics/src/main/java/org/apache/unomi/metrics/Metric.java b/metrics/src/main/java/org/apache/unomi/metrics/Metric.java
index 556fb20..7965340 100644
--- a/metrics/src/main/java/org/apache/unomi/metrics/Metric.java
+++ b/metrics/src/main/java/org/apache/unomi/metrics/Metric.java
@@ -28,6 +28,6 @@ public interface Metric {
long getTotalTime();
long addTotalTime(long time);
- Map<String,CalleeCount> getCalleeCounts();
+ Map<String,CallerCount> getCallerCounts();
}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/java/org/apache/unomi/metrics/MetricsService.java
----------------------------------------------------------------------
diff --git a/metrics/src/main/java/org/apache/unomi/metrics/MetricsService.java b/metrics/src/main/java/org/apache/unomi/metrics/MetricsService.java
index 5fd0d3c..5ad1a60 100644
--- a/metrics/src/main/java/org/apache/unomi/metrics/MetricsService.java
+++ b/metrics/src/main/java/org/apache/unomi/metrics/MetricsService.java
@@ -18,17 +18,26 @@ package org.apache.unomi.metrics;
import java.util.Map;
+/**
+ * This is the main interface for the metrics service, that makes it possible to count calls, callers and accumulated
+ * times for sections of code.
+ */
public interface MetricsService {
+ /**
+ * Enables or disables the metrics service.
+ * @param activated if true the metrics service will be activated, false will deactivate it and clear any exists
+ * in-memory metrics
+ */
void setActivated(boolean activated);
boolean isActivated();
- Map<String,Boolean> getCalleesStatus();
+ Map<String,Boolean> getCallersStatus();
- void setCalleeActivated(String timerName, boolean activated);
+ void setCallerActivated(String timerName, boolean activated);
- boolean isCalleeActivated(String timerName);
+ boolean isCallerActivated(String timerName);
Map<String,Metric> getMetrics();
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/java/org/apache/unomi/metrics/commands/CalleeStatusCommand.java
----------------------------------------------------------------------
diff --git a/metrics/src/main/java/org/apache/unomi/metrics/commands/CalleeStatusCommand.java b/metrics/src/main/java/org/apache/unomi/metrics/commands/CalleeStatusCommand.java
deleted file mode 100644
index 5aec628..0000000
--- a/metrics/src/main/java/org/apache/unomi/metrics/commands/CalleeStatusCommand.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.unomi.metrics.commands;
-
-import org.apache.karaf.shell.commands.Argument;
-import org.apache.karaf.shell.commands.Command;
-import org.apache.karaf.shell.commands.Option;
-import org.apache.karaf.shell.table.Row;
-import org.apache.karaf.shell.table.ShellTable;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-@Command(scope = "metrics", name = "callee-status", description = "This command will list all the callee configurations, or change the callee status of a specific metric")
-public class CalleeStatusCommand extends MetricsCommandSupport {
-
- @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
- boolean noFormat;
-
- @Argument(index = 0, name = "metricName", description = "The identifier for the metric", required = false, multiValued = false)
- String metricName;
-
- @Argument(index = 1, name = "status", description = "The new status for the metric's callee tracing", required = false, multiValued = false)
- Boolean metricStatus;
-
- @Override
- protected Object doExecute() throws Exception {
- if (metricName != null && metricStatus != null) {
- metricsService.setCalleeActivated(metricName, metricStatus);
- System.out.println("Metric callees " + metricName + " set to " + metricStatus);
- return null;
- }
- Map<String,Boolean> calleesStatus = metricsService.getCalleesStatus();
- ShellTable shellTable = new ShellTable();
- shellTable.column("Metric");
- shellTable.column("Activated");
-
- for (Map.Entry<String,Boolean> calleeStatusEntry : calleesStatus.entrySet()) {
- List<Object> rowData = new ArrayList<Object>();
- rowData.add(calleeStatusEntry.getKey());
- rowData.add(calleeStatusEntry.getValue() ? "x" : "");
- Row row = shellTable.addRow();
- row.addContent(rowData);
- }
-
- shellTable.print(System.out, !noFormat);
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/java/org/apache/unomi/metrics/commands/CallerStatusCommand.java
----------------------------------------------------------------------
diff --git a/metrics/src/main/java/org/apache/unomi/metrics/commands/CallerStatusCommand.java b/metrics/src/main/java/org/apache/unomi/metrics/commands/CallerStatusCommand.java
new file mode 100644
index 0000000..ddb571f
--- /dev/null
+++ b/metrics/src/main/java/org/apache/unomi/metrics/commands/CallerStatusCommand.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.metrics.commands;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+import org.apache.karaf.shell.table.Row;
+import org.apache.karaf.shell.table.ShellTable;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Command(scope = "metrics", name = "caller-status", description = "This command will list all the caller configurations, or change the caller status of a specific metric")
+public class CallerStatusCommand extends MetricsCommandSupport {
+
+ @Option(name = "--no-format", description = "Disable table rendered output", required = false, multiValued = false)
+ boolean noFormat;
+
+ @Argument(index = 0, name = "metricName", description = "The identifier for the metric", required = false, multiValued = false)
+ String metricName;
+
+ @Argument(index = 1, name = "status", description = "The new status for the metric's caller tracing", required = false, multiValued = false)
+ Boolean metricStatus;
+
+ @Override
+ protected Object doExecute() throws Exception {
+ if (metricName != null && metricStatus != null) {
+ metricsService.setCallerActivated(metricName, metricStatus);
+ System.out.println("Metric callers " + metricName + " set to " + metricStatus);
+ return null;
+ }
+ Map<String,Boolean> callersStatus = metricsService.getCallersStatus();
+ ShellTable shellTable = new ShellTable();
+ shellTable.column("Metric");
+ shellTable.column("Activated");
+
+ for (Map.Entry<String,Boolean> callerStatusEntry : callersStatus.entrySet()) {
+ List<Object> rowData = new ArrayList<Object>();
+ rowData.add(callerStatusEntry.getKey());
+ rowData.add(callerStatusEntry.getValue() ? "x" : "");
+ Row row = shellTable.addRow();
+ row.addContent(rowData);
+ }
+
+ shellTable.print(System.out, !noFormat);
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/java/org/apache/unomi/metrics/commands/ListCommand.java
----------------------------------------------------------------------
diff --git a/metrics/src/main/java/org/apache/unomi/metrics/commands/ListCommand.java b/metrics/src/main/java/org/apache/unomi/metrics/commands/ListCommand.java
index 861bb3c..824ed3e 100644
--- a/metrics/src/main/java/org/apache/unomi/metrics/commands/ListCommand.java
+++ b/metrics/src/main/java/org/apache/unomi/metrics/commands/ListCommand.java
@@ -18,12 +18,10 @@ package org.apache.unomi.metrics.commands;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
-import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.apache.karaf.shell.table.Row;
import org.apache.karaf.shell.table.ShellTable;
import org.apache.unomi.common.DataTable;
import org.apache.unomi.metrics.Metric;
-import org.apache.unomi.metrics.MetricsService;
import java.util.ArrayList;
import java.util.List;
@@ -47,7 +45,7 @@ public class ListCommand extends MetricsCommandSupport {
String[] headers = {
"Name",
- "Callees",
+ "Callers",
"Count",
"Time [ms]"
};
@@ -55,7 +53,7 @@ public class ListCommand extends MetricsCommandSupport {
DataTable dataTable = new DataTable();
for (Map.Entry<String,Metric> metricEntry : metrics.entrySet()) {
Metric metric = metricEntry.getValue();
- dataTable.addRow(metric.getName(), metric.getCalleeCounts().size(), metric.getTotalCount(), metric.getTotalTime());
+ dataTable.addRow(metric.getName(), metric.getCallerCounts().size(), metric.getTotalCount(), metric.getTotalTime());
}
dataTable.sort(new DataTable.SortCriteria(3, DataTable.SortOrder.DESCENDING),
new DataTable.SortCriteria(2, DataTable.SortOrder.DESCENDING),
@@ -67,10 +65,10 @@ public class ListCommand extends MetricsCommandSupport {
}
ShellTable shellTable = new ShellTable();
- shellTable.column("Name");
- shellTable.column("Callees");
- shellTable.column("Count");
- shellTable.column("Time [ms]");
+
+ for (String header : headers) {
+ shellTable.column(header);
+ }
for (DataTable.Row dataTableRow :dataTable.getRows()) {
List<Object> rowData = new ArrayList<Object>();
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/java/org/apache/unomi/metrics/commands/ViewCommand.java
----------------------------------------------------------------------
diff --git a/metrics/src/main/java/org/apache/unomi/metrics/commands/ViewCommand.java b/metrics/src/main/java/org/apache/unomi/metrics/commands/ViewCommand.java
index 295f1dc..b3cefe8 100644
--- a/metrics/src/main/java/org/apache/unomi/metrics/commands/ViewCommand.java
+++ b/metrics/src/main/java/org/apache/unomi/metrics/commands/ViewCommand.java
@@ -37,7 +37,7 @@ public class ViewCommand extends MetricsCommandSupport{
return null;
}
// by default pretty printer will use spaces between array values, we change this to linefeeds to make
- // the callee values easier to read.
+ // the caller values easier to read.
DefaultPrettyPrinter defaultPrettyPrinter = new DefaultPrettyPrinter();
defaultPrettyPrinter = defaultPrettyPrinter.withArrayIndenter(DefaultIndenter.SYSTEM_LINEFEED_INSTANCE);
String jsonMetric = CustomObjectMapper.getObjectMapper().writer(defaultPrettyPrinter).writeValueAsString(metric);
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/java/org/apache/unomi/metrics/internal/CalleeCountImpl.java
----------------------------------------------------------------------
diff --git a/metrics/src/main/java/org/apache/unomi/metrics/internal/CalleeCountImpl.java b/metrics/src/main/java/org/apache/unomi/metrics/internal/CalleeCountImpl.java
deleted file mode 100644
index 14f6094..0000000
--- a/metrics/src/main/java/org/apache/unomi/metrics/internal/CalleeCountImpl.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.unomi.metrics.internal;
-
-import org.apache.unomi.metrics.CalleeCount;
-
-import java.util.List;
-import java.util.concurrent.atomic.AtomicLong;
-
-public class CalleeCountImpl implements CalleeCount {
-
- private String hash;
- private List<String> callee;
- private AtomicLong count = new AtomicLong();
- private AtomicLong totalTime = new AtomicLong();
-
- public CalleeCountImpl(String hash, List<String> callee) {
- this.hash = hash;
- this.callee = callee;
- }
-
- @Override
- public String getHash() {
- return hash;
- }
-
- @Override
- public List<String> getCallee() {
- return callee;
- }
-
- @Override
- public long getCount() {
- return count.get();
- }
-
- @Override
- public long incCount() {
- return count.incrementAndGet();
- }
-
- @Override
- public long getTotalTime() {
- return totalTime.get();
- }
-
- @Override
- public long addTime(long time) {
- return totalTime.addAndGet(time);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/java/org/apache/unomi/metrics/internal/CallerCountImpl.java
----------------------------------------------------------------------
diff --git a/metrics/src/main/java/org/apache/unomi/metrics/internal/CallerCountImpl.java b/metrics/src/main/java/org/apache/unomi/metrics/internal/CallerCountImpl.java
new file mode 100644
index 0000000..31d5a55
--- /dev/null
+++ b/metrics/src/main/java/org/apache/unomi/metrics/internal/CallerCountImpl.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.unomi.metrics.internal;
+
+import org.apache.unomi.metrics.CallerCount;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
+
+public class CallerCountImpl implements CallerCount {
+
+ private String hash;
+ private List<String> caller;
+ private AtomicLong count = new AtomicLong();
+ private AtomicLong totalTime = new AtomicLong();
+
+ public CallerCountImpl(String hash, List<String> caller) {
+ this.hash = hash;
+ this.caller = caller;
+ }
+
+ @Override
+ public String getHash() {
+ return hash;
+ }
+
+ @Override
+ public List<String> getCaller() {
+ return caller;
+ }
+
+ @Override
+ public long getCount() {
+ return count.get();
+ }
+
+ @Override
+ public long incCount() {
+ return count.incrementAndGet();
+ }
+
+ @Override
+ public long getTotalTime() {
+ return totalTime.get();
+ }
+
+ @Override
+ public long addTime(long time) {
+ return totalTime.addAndGet(time);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/java/org/apache/unomi/metrics/internal/MetricImpl.java
----------------------------------------------------------------------
diff --git a/metrics/src/main/java/org/apache/unomi/metrics/internal/MetricImpl.java b/metrics/src/main/java/org/apache/unomi/metrics/internal/MetricImpl.java
index 76d6bf5..d836ab6 100644
--- a/metrics/src/main/java/org/apache/unomi/metrics/internal/MetricImpl.java
+++ b/metrics/src/main/java/org/apache/unomi/metrics/internal/MetricImpl.java
@@ -16,19 +16,18 @@
*/
package org.apache.unomi.metrics.internal;
-import org.apache.unomi.metrics.CalleeCount;
+import org.apache.unomi.metrics.CallerCount;
import org.apache.unomi.metrics.Metric;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicLong;
public class MetricImpl implements Metric {
private String name;
private long totalCount = 0L;
private long totalTime = 0L;
- private Map<String,CalleeCount> calleeCounts = new ConcurrentHashMap<String, CalleeCount>();
+ private Map<String,CallerCount> callerCounts = new ConcurrentHashMap<String, CallerCount>();
public MetricImpl(String name) {
this.name = name;
@@ -60,7 +59,7 @@ public class MetricImpl implements Metric {
}
@Override
- public Map<String, CalleeCount> getCalleeCounts() {
- return calleeCounts;
+ public Map<String, CallerCount> getCallerCounts() {
+ return callerCounts;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/java/org/apache/unomi/metrics/internal/MetricsServiceImpl.java
----------------------------------------------------------------------
diff --git a/metrics/src/main/java/org/apache/unomi/metrics/internal/MetricsServiceImpl.java b/metrics/src/main/java/org/apache/unomi/metrics/internal/MetricsServiceImpl.java
index ea16ad3..1a7688a 100644
--- a/metrics/src/main/java/org/apache/unomi/metrics/internal/MetricsServiceImpl.java
+++ b/metrics/src/main/java/org/apache/unomi/metrics/internal/MetricsServiceImpl.java
@@ -16,7 +16,7 @@
*/
package org.apache.unomi.metrics.internal;
-import org.apache.unomi.metrics.CalleeCount;
+import org.apache.unomi.metrics.CallerCount;
import org.apache.unomi.metrics.Metric;
import org.apache.unomi.metrics.MetricsService;
@@ -29,7 +29,7 @@ public class MetricsServiceImpl implements MetricsService {
boolean activated = false;
Map<String,Metric> metrics = new ConcurrentHashMap<String,Metric>();
- Map<String,Boolean> calleesStatus = new ConcurrentHashMap<>();
+ Map<String,Boolean> callersStatus = new ConcurrentHashMap<>();
public void setActivated(boolean activated) {
this.activated = activated;
@@ -65,7 +65,7 @@ public class MetricsServiceImpl implements MetricsService {
}
metric.incTotalCount();
metric.addTotalTime(totalTime);
- if (isCalleeActivated(timerName)) {
+ if (isCallerActivated(timerName)) {
StackTraceElement[] stackTraceElements = new Throwable().getStackTrace();
List<String> stackTraces = new ArrayList<String>();
if (stackTraceElements != null && stackTraceElements.length > 2) {
@@ -74,43 +74,43 @@ public class MetricsServiceImpl implements MetricsService {
stackTraces.add(String.valueOf(stackTraceElements[i]));
}
String stackTraceHash = Integer.toString(stackTraces.hashCode());
- CalleeCount calleeCount = metric.getCalleeCounts().get(stackTraceHash);
- if (calleeCount == null) {
- calleeCount = new CalleeCountImpl(stackTraceHash, stackTraces);
- calleeCount.incCount();
- calleeCount.addTime(totalTime);
- metric.getCalleeCounts().put(stackTraceHash, calleeCount);
+ CallerCount callerCount = metric.getCallerCounts().get(stackTraceHash);
+ if (callerCount == null) {
+ callerCount = new CallerCountImpl(stackTraceHash, stackTraces);
+ callerCount.incCount();
+ callerCount.addTime(totalTime);
+ metric.getCallerCounts().put(stackTraceHash, callerCount);
} else {
- calleeCount.incCount();
- calleeCount.addTime(totalTime);
+ callerCount.incCount();
+ callerCount.addTime(totalTime);
}
}
}
}
@Override
- public Map<String, Boolean> getCalleesStatus() {
- return calleesStatus;
+ public Map<String, Boolean> getCallersStatus() {
+ return callersStatus;
}
@Override
- public void setCalleeActivated(String timerName, boolean activated) {
+ public void setCallerActivated(String timerName, boolean activated) {
if (!activated) {
- if (calleesStatus.containsKey(timerName)) {
- calleesStatus.remove(timerName);
+ if (callersStatus.containsKey(timerName)) {
+ callersStatus.remove(timerName);
}
} else {
- calleesStatus.put(timerName, true);
+ callersStatus.put(timerName, true);
}
}
@Override
- public boolean isCalleeActivated(String timerName) {
- if (calleesStatus.containsKey(timerName)) {
- return calleesStatus.get(timerName);
+ public boolean isCallerActivated(String timerName) {
+ if (callersStatus.containsKey(timerName)) {
+ return callersStatus.get(timerName);
}
- if (calleesStatus.containsKey("*")) {
- return calleesStatus.get("*");
+ if (callersStatus.containsKey("*")) {
+ return callersStatus.get("*");
}
return false;
}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/metrics/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/metrics/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 7e3b58b..3a08888 100644
--- a/metrics/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/metrics/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -67,7 +67,7 @@
</shell:action>
</shell:command>
<shell:command>
- <shell:action class="org.apache.unomi.metrics.commands.CalleeStatusCommand">
+ <shell:action class="org.apache.unomi.metrics.commands.CallerStatusCommand">
<shell:property name="metricsService" ref="metricsServiceImpl" />
</shell:action>
</shell:command>
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/53ea767d/metrics/src/test/java/org/apache/unomi/metrics/internal/MetricsServiceTest.java
----------------------------------------------------------------------
diff --git a/metrics/src/test/java/org/apache/unomi/metrics/internal/MetricsServiceTest.java b/metrics/src/test/java/org/apache/unomi/metrics/internal/MetricsServiceTest.java
index b293599..033d0e6 100644
--- a/metrics/src/test/java/org/apache/unomi/metrics/internal/MetricsServiceTest.java
+++ b/metrics/src/test/java/org/apache/unomi/metrics/internal/MetricsServiceTest.java
@@ -24,7 +24,10 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
-import java.util.concurrent.*;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
@@ -79,32 +82,32 @@ public class MetricsServiceTest {
assertEquals("Metrics should be empty", 0, metricsService.getMetrics().size());
System.out.println("Free memory=" + humanReadableByteCount(Runtime.getRuntime().freeMemory(), false));
- System.out.println("Testing with metrics activated (but no callees)...");
+ System.out.println("Testing with metrics activated (but no callers)...");
todo.clear();
metricsService.setActivated(true);
- assertEquals("Callees should be completely empty", metricsService.getCalleesStatus().size(), 0);
+ assertEquals("Callers should be completely empty", metricsService.getCallersStatus().size(), 0);
long withMetricsStartTime = System.currentTimeMillis();
for (int i = 0; i < workerCount; i++) {
todo.add(new Worker(metricsService, "worker-" + i, 1000+ random.nextInt(1000)));
}
answers = executorService.invokeAll(todo);
long withMetricsTotalTime = System.currentTimeMillis() - withMetricsStartTime;
- System.out.println("Total time with metrics (no callees) =" + withMetricsTotalTime + "ms");
+ System.out.println("Total time with metrics (no callers) =" + withMetricsTotalTime + "ms");
assertEquals("Metrics count is not correct", workerCount, metricsService.getMetrics().size());
System.out.println("Free memory=" + humanReadableByteCount(Runtime.getRuntime().freeMemory(), false));
- System.out.println("Testing with metrics activated (all callees activated)...");
+ System.out.println("Testing with metrics activated (all callers activated)...");
todo.clear();
metricsService.setActivated(true);
- metricsService.setCalleeActivated("*", true);
- assertNotEquals("Callees should not be completely empty", metricsService.getCalleesStatus().size(), 0);
- long withMetricsAndCalleesStartTime = System.currentTimeMillis();
+ metricsService.setCallerActivated("*", true);
+ assertNotEquals("Callers should not be completely empty", metricsService.getCallersStatus().size(), 0);
+ long withMetricsAndCallersStartTime = System.currentTimeMillis();
for (int i = 0; i < workerCount; i++) {
todo.add(new Worker(metricsService, "worker-" + i, 1000+ random.nextInt(1000)));
}
answers = executorService.invokeAll(todo);
- long withMetricsAndCalleesTotalTime = System.currentTimeMillis() - withMetricsAndCalleesStartTime;
- System.out.println("Total time with metrics (with callees)=" + withMetricsAndCalleesTotalTime + "ms");
+ long withMetricsAndCallersTotalTime = System.currentTimeMillis() - withMetricsAndCallersStartTime;
+ System.out.println("Total time with metrics (with callers)=" + withMetricsAndCallersTotalTime + "ms");
assertEquals("Metrics count is not correct", workerCount, metricsService.getMetrics().size());
System.out.println("Free memory=" + humanReadableByteCount(Runtime.getRuntime().freeMemory(), false));
}