Skip to content

Commit

Permalink
Add Invocation.Kind badges, add caret to indicate desc ordering
Browse files Browse the repository at this point in the history
- specify column width for invocation trees
  • Loading branch information
mkouba committed Feb 23, 2021
1 parent 2a33fb6 commit 525855a
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Timestamp <i class="fas fa-caret-down"></i></th>
<th scope="col">Event Type</th>
<th scope="col">Qualifiers</th>
<th scope="col">Timestamp</th>
</tr>
</thead>
<tbody>
{#for event in info:eventsMonitor.lastEvents.orEmpty}
<tr>
<td>{count}.</td>
<td>
{event.timestamp}
</td>
<td>
<code>{event.type}</code>
</td>
Expand All @@ -54,9 +57,6 @@
</ul>
{/when}
</td>
<td>
{event.timestamp}
</td>
</tr>
{/for}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Start</th>
<th scope="col">Tree</th>
<th scope="col">Start <i class="fas fa-caret-down"></i></th>
<th scope="col" style="width:70%;">Invocations</th>
</tr>
</thead>
<tbody>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{#when it.kind}
{#is PRODUCER}
<span class="badge badge-success">Producer</span>
{#is DISPOSER}
<span class="badge badge-danger">Disposer</span>
{#is OBSERVER}
<span class="badge badge-secondary">Observer</span>
{/when}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
{#if next}├─{#else}└─{/if}
{/if}
{#if it.children}
<span class="caret" title="{it.method}"><code>{it.methodInfo}</code></span> {#duration it useBadge=true /}
<span class="caret" title="{it.method}"><code>{it.methodInfo}</code></span> {#duration it /}{#kind it /}
<ul class="nested">
{#each it.children}
{#tree it root=false next=hasNext /}
{/each}
</ul>
{#else}
<span title="{it.method}"><code>{it.methodInfo}</code></span> {#duration it /}
<span title="{it.method}"><code>{it.methodInfo}</code></span> {#duration it /}{#kind it /}
{/if}
</li>
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,26 @@
public class Invocation {

private final InjectableBean<?> interceptedBean;

/**
* Start time in ms
*/
private final long start;

/**
* Duration in ns
*/
private final long duration;

private final Method method;

private final Kind kind;
private final List<Invocation> children;

Invocation(InjectableBean<?> interceptedBean, long start, long duration,
Method method, List<Invocation> children) {
Method method, Kind kind, List<Invocation> children) {
this.interceptedBean = interceptedBean;
this.start = start;
this.duration = duration;
this.method = method;
this.children = children;
this.kind = kind;
}

public InjectableBean<?> getInterceptedBean() {
Expand Down Expand Up @@ -71,19 +69,33 @@ public List<Invocation> getChildren() {
return children;
}

public Kind getKind() {
return kind;
}

@Override
public String toString() {
return kind + " invocation of " + method;
}

public enum Kind {

BUSINESS,
PRODUCER,
DISPOSER,
OBSERVER

}

static class Builder {

private InjectableBean<?> interceptedBean;

private long start;

private long duration;

private Method method;

private List<Builder> children;

private Builder parent;
private Kind kind;

Builder newChild() {
Invocation.Builder child = new Builder();
Expand Down Expand Up @@ -111,6 +123,11 @@ Builder setMethod(Method method) {
return this;
}

Builder setKind(Kind kind) {
this.kind = kind;
return this;
}

Builder getParent() {
return parent;
}
Expand All @@ -135,7 +152,7 @@ Invocation build() {
invocations.add(builder.build());
}
}
return new Invocation(interceptedBean, start, duration, method, invocations);
return new Invocation(interceptedBean, start, duration, method, kind, invocations);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package io.quarkus.arc.runtime.devconsole;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import javax.annotation.Priority;
import javax.enterprise.event.Observes;
import javax.enterprise.event.ObservesAsync;
import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Intercepted;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
Expand All @@ -12,6 +19,7 @@
import io.quarkus.arc.InjectableBean;
import io.quarkus.arc.ManagedContext;
import io.quarkus.arc.runtime.devconsole.Invocation.Builder;
import io.quarkus.arc.runtime.devconsole.Invocation.Kind;

@Priority(Interceptor.Priority.LIBRARY_BEFORE)
@Monitored
Expand All @@ -32,10 +40,11 @@ public Object monitor(InvocationContext context) throws Exception {
ManagedContext requestContext = Arc.container().requestContext();
if (requestContext.isActive()) {
InvocationTree tree = invocationTree.get();
return proceed(tree.invocationStarted(bean, context.getMethod()), context, requestContext, tree);
return proceed(tree.invocationStarted(bean, context.getMethod(), getKind(context)), context, requestContext, tree);
} else {
return proceed(
new Builder().setInterceptedBean(bean).setMethod(context.getMethod()).setStart(System.currentTimeMillis()),
new Builder().setInterceptedBean(bean).setMethod(context.getMethod()).setKind(getKind(context))
.setStart(System.currentTimeMillis()),
context, requestContext, null);
}
}
Expand All @@ -57,4 +66,27 @@ Object proceed(Invocation.Builder builder, InvocationContext context, ManagedCon
return result;
}

Invocation.Kind getKind(InvocationContext ctx) {
// This will only work for "unmodified" discovered types
Method method = ctx.getMethod();
if (!method.getReturnType().equals(Void.TYPE) && method.isAnnotationPresent(Produces.class)) {
return Kind.PRODUCER;
} else if (method.getParameterCount() > 0) {
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
if (parameterAnnotations.length > 0) {
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
Class<? extends Annotation> type = annotation.annotationType();
if (Observes.class.equals(type) || ObservesAsync.class.equals(type)) {
return Kind.OBSERVER;
} else if (Disposes.class.equals(type)) {
return Kind.DISPOSER;
}
}
}
}
}
return Kind.BUSINESS;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class InvocationTree {
// A request scoped bean should not be invoked concurrently, however it can be invoked on a different thread
private volatile Invocation.Builder current;

Invocation.Builder invocationStarted(InjectableBean<?> bean, Method method) {
Invocation.Builder invocationStarted(InjectableBean<?> bean, Method method, Invocation.Kind kind) {
Invocation.Builder builder = this.current;
if (builder == null) {
// Entry point
Expand All @@ -29,6 +29,7 @@ Invocation.Builder invocationStarted(InjectableBean<?> bean, Method method) {
builder.setStart(System.currentTimeMillis());
builder.setInterceptedBean(bean);
builder.setMethod(method);
builder.setKind(kind);
this.current = builder;
return builder;
}
Expand Down

0 comments on commit 525855a

Please sign in to comment.