forked from Chicken-Bones/NotEnoughItems
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fd9aad
commit e5c0247
Showing
6 changed files
with
75 additions
and
17 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
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
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 codechicken.nei.util; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import codechicken.core.TaskProfiler; | ||
|
||
public class AsyncTaskProfiler extends TaskProfiler { | ||
|
||
public ThreadLocal<TaskProfiler> threadedProfiler = ThreadLocal.withInitial(TaskProfiler::new); | ||
|
||
public Map<String, Long> times = new ConcurrentHashMap<>(); | ||
|
||
public void start(String section) { | ||
threadedProfiler.get().start(section); | ||
} | ||
|
||
public void end() { | ||
threadedProfiler.get().end(); | ||
times.putAll(threadedProfiler.get().times); | ||
} | ||
|
||
@Override | ||
public List<ProfilerResult> getResults() { | ||
ArrayList<ProfilerResult> results = new ArrayList<>(times.size()); | ||
long totalTime = times.values().stream().reduce(0L, Long::sum); | ||
for (Entry<String, Long> e : times.entrySet()) | ||
results.add(new ProfilerResult(e.getKey(), e.getValue(), totalTime)); | ||
return results; | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
if (threadedProfiler.get().currentSection != null) threadedProfiler.get().end(); | ||
threadedProfiler.get().clear(); | ||
times.clear(); | ||
} | ||
|
||
public void clearCurrent() { | ||
if (threadedProfiler.get().currentSection != null) threadedProfiler.get().end(); | ||
threadedProfiler.get().clear(); | ||
} | ||
} |
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