Skip to content

Commit

Permalink
Remove debug prints
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Apr 8, 2024
1 parent fd6d207 commit 6bc370a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 72 deletions.
25 changes: 1 addition & 24 deletions arc-core/src/arc/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import arc.func.*;
import arc.struct.*;
import arc.util.*;

import java.util.*;

Expand All @@ -13,33 +12,18 @@ public class Events{
private static class Handler<T>{ // FINISHME: Pool these maybe? I doubt it's needed though
private int id = ++lastId;
private final Cons<T> cons;
private final String trace;

Handler(Cons<T> cons){
this.cons = cons;
trace = null;
}

Handler(Cons<T> cons, String trace){
this.cons = cons;
this.trace = trace;
}
}

public static Class<?> debugType;

private static final ObjectMap<Object, Seq<Handler<?>>> events = new ObjectMap<>();

/** Handle an event by class. */
public static <T> void on(Class<T> type, Cons<T> listener){
String trace = null;
if(type == debugType){
StackTraceElement[] st = Thread.currentThread().getStackTrace();
StringBuilder sb = new StringBuilder();
for (int i = 2; i < st.length; i++) sb.append(st[i].toString()).append('\n');
trace = sb.toString();
}
events.get(type, () -> new Seq<>(Handler.class)).add(new Handler<>(listener, trace));
events.get(type, () -> new Seq<>(Handler.class)).add(new Handler<>(listener));
}

/** Handle an event by class. Returns an id */
Expand Down Expand Up @@ -95,24 +79,17 @@ public static <T> void fire(T type){

public static <T> void fire(Class<?> ctype, T type){
Seq<Handler<?>> listeners = events.get(ctype);
boolean dbg = ctype == debugType;

if(listeners != null){
Iterator<Handler<T>> it = listeners.<Handler<T>>as().iterator();
long tot = Time.nanos();
while(it.hasNext()){
Handler<T> listener = it.next();
if(listener.id == -1){
it.remove();
continue;
}
long start = Time.nanos();
listener.cons.get(type);
if (dbg) {
Log.info("Event listener in @ms. Trace:\n@", Time.millisSinceNanos(start), listener.trace);
}
}
if (dbg) Log.info("Event fired in @ms", Time.millisSinceNanos(tot));
}
}

Expand Down
49 changes: 1 addition & 48 deletions arc-core/src/arc/util/Threads.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,47 +44,7 @@ public static void awaitAll(Seq<Future<?>> futures){
* @param threads the number of threads */
public static ExecutorService executor(@Nullable String name, int threads){
final AtomicInteger num = new AtomicInteger();
if (!"Main Executor".equals(name) || threads != OS.cores) return Executors.newFixedThreadPool(threads, r -> newThread(r, threads == 1 ? name : name + "-" + num.incrementAndGet(), true));
return new ThreadPoolExecutor(threads, threads,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(){
@Override
public void put(Runnable o) throws InterruptedException {
super.put(o);
queued.incrementAndGet();
}

@Override
public boolean offer(Runnable o, long timeout, TimeUnit unit) throws InterruptedException {
boolean r = super.offer(o, timeout, unit);
if (r) queued.incrementAndGet();
return r;
}

@Override
public boolean offer(Runnable o) {
boolean r = super.offer(o);
if (r) queued.incrementAndGet();
return r;
}
},
r -> newThread(r, name + "-" + num.incrementAndGet(), true)) {
@Override
protected void afterExecute(Runnable r, Throwable t) {
queued.decrementAndGet();
done.incrementAndGet();
}
{
daemon("Main Executor Watcher", () -> {
startTime = Time.millis();
while(true) {
printStats(queued.get(), done.get());
sleep(10);
}
});
prestartAllCoreThreads();
}
};
return Executors.newFixedThreadPool(threads, r -> newThread(r, threads == 1 ? name : name + "-" + num.incrementAndGet(), true));
}

private static final AtomicInteger queued = new AtomicInteger(), done = new AtomicInteger();
Expand All @@ -96,13 +56,6 @@ private static void printStats(int numQueued, int numDone) {
System.out.println(Strings.format("@q | @d | @t", numQueued, numDone, Time.timeSinceMillis(startTime)));
}

private static void getTrace() {
StackTraceElement[] st = Thread.currentThread().getStackTrace();
StringBuilder sb = new StringBuilder();
for (int i = 3; i < st.length; i++) sb.append(st[i].toString()).append('\n');
Log.info(sb.toString());
}

/** @see #executor(String, int) */
public static ExecutorService executor(int threads){
return executor(null, threads);
Expand Down

0 comments on commit 6bc370a

Please sign in to comment.