2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.dom.broker.impl;
10 import java.util.concurrent.atomic.AtomicLong;
12 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
13 import org.opendaylight.controller.sal.core.api.data.DataStore;
14 import org.opendaylight.yangtools.concepts.Delegator;
15 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
19 public class DataStoreStatsWrapper implements Delegator<DataStore>, DataStore {
21 private final DataStore delegate;
23 private AtomicLong cfgReadCount = new AtomicLong();
24 private AtomicLong cfgReadTimeTotal = new AtomicLong();
26 private AtomicLong operReadCount = new AtomicLong();
27 private AtomicLong operReadTimeTotal = new AtomicLong();
29 private AtomicLong requestCommitCount = new AtomicLong();
30 private AtomicLong requestCommitTimeTotal = new AtomicLong();
32 public DataStoreStatsWrapper(DataStore store) {
37 public DataStore getDelegate() {
42 public CompositeNode readConfigurationData(YangInstanceIdentifier path) {
43 cfgReadCount.incrementAndGet();
44 final long startTime = System.nanoTime();
46 return delegate.readConfigurationData(path);
48 final long endTime = System.nanoTime();
49 final long runTime = endTime - startTime;
50 cfgReadTimeTotal.addAndGet(runTime);
55 public CompositeNode readOperationalData(YangInstanceIdentifier path) {
56 operReadCount.incrementAndGet();
57 final long startTime = System.nanoTime();
59 return delegate.readOperationalData(path);
61 final long endTime = System.nanoTime();
62 final long runTime = endTime - startTime;
63 operReadTimeTotal.addAndGet(runTime);
67 public DataCommitTransaction<YangInstanceIdentifier, CompositeNode> requestCommit(
68 DataModification<YangInstanceIdentifier, CompositeNode> modification) {
69 requestCommitCount.incrementAndGet();
70 final long startTime = System.nanoTime();
72 return delegate.requestCommit(modification);
74 final long endTime = System.nanoTime();
75 final long runTime = endTime - startTime;
76 requestCommitTimeTotal.addAndGet(runTime);
81 public boolean containsConfigurationPath(YangInstanceIdentifier path) {
82 return delegate.containsConfigurationPath(path);
85 public Iterable<YangInstanceIdentifier> getStoredConfigurationPaths() {
86 return delegate.getStoredConfigurationPaths();
89 public Iterable<YangInstanceIdentifier> getStoredOperationalPaths() {
90 return delegate.getStoredOperationalPaths();
93 public boolean containsOperationalPath(YangInstanceIdentifier path) {
94 return delegate.containsOperationalPath(path);
97 public final long getConfigurationReadCount() {
98 return cfgReadCount.get();
101 public final long getOperationalReadCount() {
102 return operReadCount.get();
105 public final long getRequestCommitCount() {
106 return requestCommitCount.get();
109 public final double getConfigurationReadTotalTime() {
110 return cfgReadTimeTotal.get() / 1000.0d;
113 public final double getOperationalReadTotalTime() {
114 return operReadTimeTotal.get() / 1000.0d;
117 public final double getRequestCommitTotalTime() {
118 return requestCommitTimeTotal.get() / 1000.0d;
121 public final double getConfigurationReadAverageTime() {
122 long readCount = cfgReadCount.get();
126 return getConfigurationReadTotalTime() / readCount;
129 public final double getOperationalReadAverageTime() {
130 long readCount = operReadCount.get();
134 return getOperationalReadTotalTime() / readCount;
137 public final double getRequestCommitAverageTime() {
138 long count = requestCommitCount.get();
142 return getRequestCommitTotalTime() / count;