-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
work on adding timing instrumentation
- Loading branch information
1 parent
25df941
commit c9ac170
Showing
4 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/aj/com/mebigfatguy/fbcontrib/instrument/Timing.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.mebigfatguy.fbcontrib.instrument; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
|
||
import edu.umd.cs.findbugs.ba.ClassContext; | ||
|
||
@Aspect | ||
public class Timing { | ||
|
||
private static final Map<String, TimingInfo> timingInfo = new HashMap<>(); | ||
|
||
@Around("execution(* com.mebigfatguy.fbcontrib.detect.*.visitClassContext(..)) && args(classContext)") | ||
public Object timings(ProceedingJoinPoint joinPoint,ClassContext classContext) throws Throwable { | ||
long start = System.currentTimeMillis(); | ||
try { | ||
Object result = joinPoint.proceed(); | ||
return result; | ||
} finally { | ||
long delta = System.currentTimeMillis() - start; | ||
String detector = joinPoint.getSignature().getDeclaringTypeName(); | ||
TimingInfo info = timingInfo.get(detector); | ||
if (info == null) { | ||
info = new TimingInfo(); | ||
timingInfo.put(detector, info); | ||
} | ||
info.numberOfCalls++; | ||
info.totalTime += delta; | ||
if (delta > info.longestTime) { | ||
info.longestTime = delta; | ||
info.longestInput = classContext.getJavaClass().getClassName(); | ||
} | ||
} | ||
} | ||
|
||
class TimingInfo { | ||
long numberOfCalls; | ||
long totalTime; | ||
long longestTime; | ||
String longestInput; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters