Skip to content

Commit

Permalink
performance statistics manager now uses volatile for enablement inste…
Browse files Browse the repository at this point in the history
…ad of atomic
  • Loading branch information
taburet committed Oct 24, 2016
1 parent c150433 commit a4f6f8c
Showing 1 changed file with 34 additions and 35 deletions.
Expand Up @@ -123,7 +123,7 @@ public class OPerformanceStatisticManager {
/**
* Indicates whether gathering of performance data for whole system is switched on/off.
*/
private final AtomicBoolean enabled = new AtomicBoolean(false);
private volatile boolean enabled = false;

/**
* Indicates whether gathering of performance data for single thread is switched on/off.
Expand Down Expand Up @@ -330,7 +330,7 @@ private ODiskWriteAheadLog getWriteAheadLog() {
public void startThreadMonitoring() {
switchLock.acquireWriteLock();
try {
if (enabled.get())
if (enabled)
throw new IllegalStateException("Monitoring is already started on system level and can not be started on thread level");

enabledForCurrentThread.set(true);
Expand Down Expand Up @@ -363,13 +363,13 @@ public OSessionStoragePerformanceStatistic stopThreadMonitoring() {
public void startMonitoring() {
switchLock.acquireWriteLock();
try {
if (!statistics.isEmpty() && !enabled.get())
if (!statistics.isEmpty() && !enabled)
throw new IllegalStateException("Monitoring is already started on thread level and can not be started on system level");

enabled.set(true);

deadThreadsStatistic = null;
postMeasurementStatistic = null;

enabled = true;
} finally {
switchLock.releaseWriteLock();
}
Expand All @@ -381,7 +381,7 @@ public void startMonitoring() {
public void stopMonitoring() {
switchLock.acquireWriteLock();
try {
enabled.set(false);
enabled = false;

final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
final Map<String, PerformanceCountersHolder> componentCountersHolder = new HashMap<String, PerformanceCountersHolder>();
Expand Down Expand Up @@ -497,12 +497,12 @@ public Set<String> getComponentNames() {
* <code>null</code> if none of both methods {@link #startMonitoring()} or {@link #startThreadMonitoring()} are called.
*/
public OSessionStoragePerformanceStatistic getSessionPerformanceStatistic() {
if (!enabled.get() && !enabledForCurrentThread.get())
if (!enabled && !enabledForCurrentThread.get())
return null;

switchLock.acquireReadLock();
try {
if (!enabled.get() && !enabledForCurrentThread.get())
if (!enabled && !enabledForCurrentThread.get())
return null;

final Thread currentThread = Thread.currentThread();
Expand All @@ -512,8 +512,7 @@ public OSessionStoragePerformanceStatistic getSessionPerformanceStatistic() {
return performanceStatistic;
}

performanceStatistic = new OSessionStoragePerformanceStatistic(intervalBetweenSnapshots,
enabled.get() ? cleanUpInterval : -1);
performanceStatistic = new OSessionStoragePerformanceStatistic(intervalBetweenSnapshots, enabled ? cleanUpInterval : -1);

statistics.put(currentThread, performanceStatistic);

Expand All @@ -536,7 +535,7 @@ public OSessionStoragePerformanceStatistic getSessionPerformanceStatistic() {
public long getAmountOfPagesPerOperation(String componentName) {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final PerformanceCountersHolder componentCountersHolder = ComponentType.GENERAL.newCountersHolder();
fetchComponentCounters(componentName, componentCountersHolder);
return componentCountersHolder.getAmountOfPagesPerOperation();
Expand All @@ -563,7 +562,7 @@ public long getAmountOfPagesPerOperation(String componentName) {
public int getCacheHits() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
fetchSystemCounters(countersHolder);
return countersHolder.getCacheHits();
Expand Down Expand Up @@ -591,7 +590,7 @@ public int getCacheHits() {
public int getCacheHits(String componentName) {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
fetchComponentCounters(componentName, countersHolder);
return countersHolder.getCacheHits();
Expand All @@ -618,7 +617,7 @@ public int getCacheHits(String componentName) {
public long getCommitTime() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
fetchSystemCounters(countersHolder);
return countersHolder.getCommitTime();
Expand All @@ -641,7 +640,7 @@ public long getCommitTime() {
public long getReadSpeedFromCacheInPages() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
fetchSystemCounters(countersHolder);
return countersHolder.getReadSpeedFromCacheInPages();
Expand Down Expand Up @@ -670,7 +669,7 @@ public long getReadSpeedFromCacheInPages() {
public long getReadSpeedFromCacheInPages(String componentName) {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
fetchComponentCounters(componentName, countersHolder);
return countersHolder.getReadSpeedFromCacheInPages();
Expand Down Expand Up @@ -698,7 +697,7 @@ public long getReadSpeedFromCacheInPages(String componentName) {
public long getReadSpeedFromFileInPages() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
fetchSystemCounters(countersHolder);
return countersHolder.getReadSpeedFromFileInPages();
Expand Down Expand Up @@ -727,7 +726,7 @@ public long getReadSpeedFromFileInPages() {
public long getReadSpeedFromFileInPages(String componentName) {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
fetchComponentCounters(componentName, countersHolder);
return countersHolder.getReadSpeedFromFileInPages();
Expand All @@ -754,7 +753,7 @@ public long getReadSpeedFromFileInPages(String componentName) {
public long getWriteSpeedInCacheInPages() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
fetchSystemCounters(countersHolder);
return countersHolder.getWriteSpeedInCacheInPages();
Expand Down Expand Up @@ -784,7 +783,7 @@ public long getWriteSpeedInCacheInPages() {
public long getWriteSpeedInCacheInPages(String componentName) {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final PerformanceCountersHolder countersHolder = ComponentType.GENERAL.newCountersHolder();
fetchComponentCounters(componentName, countersHolder);
return countersHolder.getWriteSpeedInCacheInPages();
Expand All @@ -811,7 +810,7 @@ public long getWriteSpeedInCacheInPages(String componentName) {
public long getWriteCachePagesPerFlush() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
WritCacheCountersHolder holder = fetchWriteCacheCounters();
if (holder != null)
return holder.getPagesPerFlush();
Expand Down Expand Up @@ -840,7 +839,7 @@ public long getWriteCachePagesPerFlush() {
public long getWriteCacheFlushOperationsTime() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
WritCacheCountersHolder holder = fetchWriteCacheCounters();
if (holder != null)
return holder.getFlushOperationsTime();
Expand Down Expand Up @@ -869,7 +868,7 @@ public long getWriteCacheFlushOperationsTime() {
public long getWriteCacheFuzzyCheckpointTime() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
WritCacheCountersHolder holder = fetchWriteCacheCounters();
if (holder != null)
return holder.getFuzzyCheckpointTime();
Expand Down Expand Up @@ -897,7 +896,7 @@ public long getWriteCacheFuzzyCheckpointTime() {
public long getFullCheckpointTime() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
StorageCountersHolder holder = fetchStorageCounters();
if (holder != null)
return holder.getFullCheckpointTime();
Expand Down Expand Up @@ -925,7 +924,7 @@ public long getFullCheckpointTime() {
public long getFullCheckpointCount() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
fullCheckpointCount = storage.getFullCheckpointCount();
return fullCheckpointCount;
} else {
Expand All @@ -942,7 +941,7 @@ public long getFullCheckpointCount() {
public long getReadCacheSize() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final O2QCache cache = gerReadCache();
if (cache != null)
readCacheSize = cache.getUsedMemory();
Expand All @@ -963,7 +962,7 @@ public long getWriteCacheSize() {
switchLock.acquireReadLock();
try {

if (enabled.get()) {
if (enabled) {
final OWOWCache cache = getWowCache();
if (cache != null) {
writeCacheSize = cache.getWriteCacheSize();
Expand All @@ -984,7 +983,7 @@ public long getWriteCacheSize() {
public long getExclusiveWriteCacheSize() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final OWOWCache cache = getWowCache();
if (cache != null) {
exclusiveWriteCacheSize = cache.getExclusiveWriteCacheSize();
Expand All @@ -1006,7 +1005,7 @@ public long getExclusiveWriteCacheSize() {
public long getWriteCacheOverflowCount() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final OWOWCache cache = getWowCache();
if (cache != null) {
writeCacheOverflowCount = cache.getCacheOverflowCount();
Expand All @@ -1027,7 +1026,7 @@ public long getWriteCacheOverflowCount() {
public long getWALSize() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final ODiskWriteAheadLog wal = getWriteAheadLog();
if (wal != null) {
walSize = wal.size();
Expand All @@ -1049,7 +1048,7 @@ public long getWALSize() {
public long getWALCacheOverflowCount() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final ODiskWriteAheadLog wal = getWriteAheadLog();
if (wal != null)
walCacheOverflowCount = wal.getCacheOverflowCount();
Expand All @@ -1069,7 +1068,7 @@ public long getWALCacheOverflowCount() {
public long getWALLogRecordTime() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final WALCountersHolder holder = fetchWALCounters();
if (holder != null)
return holder.getLogTime();
Expand Down Expand Up @@ -1098,7 +1097,7 @@ public long getWALLogRecordTime() {
public long getWALStartAOLogRecordTime() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final WALCountersHolder holder = fetchWALCounters();
if (holder != null)
return holder.getStartAOTime();
Expand Down Expand Up @@ -1127,7 +1126,7 @@ public long getWALStartAOLogRecordTime() {
public long getWALStopAOLogRecordTime() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final WALCountersHolder holder = fetchWALCounters();
if (holder != null)
return holder.getStopAOTime();
Expand Down Expand Up @@ -1155,7 +1154,7 @@ public long getWALStopAOLogRecordTime() {
public long getWALFlushTime() {
switchLock.acquireReadLock();
try {
if (enabled.get()) {
if (enabled) {
final WALCountersHolder holder = fetchWALCounters();

if (holder != null)
Expand Down

0 comments on commit a4f6f8c

Please sign in to comment.