Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Nov 21, 2014
2 parents e4c9572 + e76024e commit 50cb86a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 28 deletions.
Expand Up @@ -20,6 +20,7 @@
import com.evolveum.midpoint.util.logging.TraceManager;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -38,22 +39,17 @@
* */
public class MethodUsageStatistics {

/* LOGGER */
private static Trace LOGGER = TraceManager.getTrace(ProfilingDataManager.class);

/* Attributes - member */
private long min = Long.MAX_VALUE;
private long max = 0;
private long mean = 0;
private long processTimeMean = 0;
private long usageCount = 1;
private long currentTopTenMin = Long.MAX_VALUE;
private String subsystem;
private List<ProfilingDataLog> slowestMethodList = new ArrayList<ProfilingDataLog>();
private List<ProfilingDataLog> slowestMethodList = Collections.synchronizedList(new ArrayList<ProfilingDataLog>());

/*
* Constructor
* */
public MethodUsageStatistics(ProfilingDataLog logEvent, String subsystem){
long estTime = logEvent.getEstimatedTime();

Expand All @@ -64,9 +60,8 @@ public MethodUsageStatistics(ProfilingDataLog logEvent, String subsystem){
this.subsystem = subsystem;
this.mean = estTime;

} //MethodUsageStatistics
}

/* GETTERS AND SETTERS */
public long getProcessTimeMean() {
return processTimeMean;
}
Expand Down Expand Up @@ -131,7 +126,6 @@ public void setSlowestMethodList(List<ProfilingDataLog> slowestMethodList) {
this.slowestMethodList = slowestMethodList;
}

/* BEHAVIOR */
public synchronized void update(ProfilingDataLog logEvent){
long currentEst = logEvent.getEstimatedTime();

Expand All @@ -144,25 +138,16 @@ public synchronized void update(ProfilingDataLog logEvent){
calculateMeanIterative(currentEst);
usageCount++;

} //update
}

/*
* Calculate mean iterative
* */
private void calculateMeanIterative(long currentEst){
this.mean += (currentEst - this.mean)/this.usageCount;
}

/*
* Updates the list holding processing est time values
* */
public void updateProcessTimeList(long est){
this.processTimeMean += (est - this.processTimeMean)/this.usageCount;
}

/*
* Appends method usage statistics to log file
* */
public void appendToLogger(){
ProfilingDataLog log = this.slowestMethodList.get(0);

Expand All @@ -173,12 +158,8 @@ public void appendToLogger(){
for(ProfilingDataLog l: this.slowestMethodList)
l.appendToLogger();

} //appendToLogger
}

/* STATIC HELPER METHODS */
/*
* Formats execution time
* */
private static String formatExecutionTime(long est){
StringBuilder sb = new StringBuilder();

Expand All @@ -195,6 +176,5 @@ private static String formatExecutionTime(long est){
sb.append(" ms.");

return sb.toString();
} //formatExecutionTime

}
}
Expand Up @@ -221,7 +221,7 @@ private static long minutesToMillis(int minutes){
return (long)(minutes*60*1000);
}

private void updateOverallStatistics(Map<String, MethodUsageStatistics> logMap, ProfilingDataLog eventLog, String key, String subsystem){
private synchronized void updateOverallStatistics(Map<String, MethodUsageStatistics> logMap, ProfilingDataLog eventLog, String key, String subsystem){
if(!logMap.containsKey(key)){
eventLog.setArgs(prepareArguments(eventLog.args));
logMap.put(key, new MethodUsageStatistics(eventLog, subsystem));
Expand Down Expand Up @@ -280,7 +280,7 @@ private ProfilingDataLog prepareProfilingDataLog(String className, String method
return new ProfilingDataLog(className, methodName, eTime, timestamp, args);
}

private static List<ProfilingDataLog> sort(List<ProfilingDataLog> list){
private synchronized static List<ProfilingDataLog> sort(List<ProfilingDataLog> list){
Collections.sort(list, arrayComparator);
return list;
}
Expand Down

0 comments on commit 50cb86a

Please sign in to comment.