Skip to content

Commit

Permalink
Created bug-fix branch for stats store
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrook authored and darkv committed Nov 30, 2012
1 parent 4febb1c commit fab851e
Showing 1 changed file with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
import er.extensions.eof.ERXObjectStoreCoordinator;
import er.extensions.foundation.ERXProperties;
import er.extensions.statistics.store.ERXDumbStatisticsStoreListener;
import er.extensions.statistics.store.IERXStatisticsStoreListener;
import er.extensions.statistics.store.ERXEmptyRequestDescription;
import er.extensions.statistics.store.ERXNormalRequestDescription;
import er.extensions.statistics.store.IERXRequestDescription;
import er.extensions.statistics.store.IERXStatisticsStoreListener;

/**
* Enhances the normal stats store with a bunch of useful things which get
Expand Down Expand Up @@ -123,14 +123,30 @@ protected void endTimer(WOContext aContext, String aString) {
requestTime = System.currentTimeMillis() - time();
}

Thread currentThread = Thread.currentThread();
Map<Thread, StackTraceElement[]> traces = _fatalTraces.remove(currentThread);
Map<Thread, String> names = _fatalTracesNames.remove(currentThread);
if (traces == null) {
traces = _errorTraces.remove(currentThread);
names = _errorTracesNames.remove(currentThread);
}
if (traces == null) {
traces = _warnTraces.remove(currentThread);
names = _warnTracesNames.remove(currentThread);
}

synchronized (_requestThreads) {
_requestThreads.remove(Thread.currentThread());
}

// Don't get the traces string if we have already logged all
// of the stacks within the last 10s. All of this logging
// could just makes it worse for an application that is
// already struggling.
String trace = " - (skipped stack traces)";
long currentTime = System.currentTimeMillis();
if (currentTime - _lastLog > 10000) {
trace = stringFromTraces();
trace = stringFromTracesAndNames(traces, names);
_lastLog = currentTime;
}

Expand All @@ -152,29 +168,6 @@ else if (requestTime > _maximumRequestWarnTime) {
}
}

private String stringFromTraces() {
String result;
Thread currentThread = Thread.currentThread();
Map<Thread, StackTraceElement[]> traces = _fatalTraces.remove(currentThread);
Map<Thread, String> names = _fatalTracesNames.remove(currentThread);
if (traces == null) {
traces = _errorTraces.remove(currentThread);
names = _errorTracesNames.remove(currentThread);
}
if (traces == null) {
traces = _warnTraces.remove(currentThread);
names = _warnTracesNames.remove(currentThread);
}

result = stringFromTracesAndNames(traces, names);

synchronized (_requestThreads) {
_requestThreads.remove(Thread.currentThread());
}

return result;
}

private String stringFromTracesAndNames(Map<Thread, StackTraceElement[]> traces, Map<Thread, String> names) {
String trace = null;
if (traces != null) {
Expand Down

0 comments on commit fab851e

Please sign in to comment.