Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0651b82
adding Profiler
andimarek May 19, 2025
cc1de5e
progress
andimarek May 19, 2025
eef80ec
track running time
andimarek May 20, 2025
15cf642
tracking datafetcher result types
andimarek May 20, 2025
b7379ef
operation details
andimarek May 20, 2025
275eaac
wip
andimarek May 21, 2025
cd002c0
dataloader tracking
andimarek May 21, 2025
b75a14d
Merge branch 'master' into profiler-2
andimarek May 26, 2025
450a9fc
track dataloader dispatch
andimarek May 26, 2025
5e9e713
track dataloader dispatch
andimarek May 27, 2025
b3515b7
Merge branch 'master' into profiler-2
andimarek Jun 3, 2025
1800f77
Merge branch 'master' into profiler-2
andimarek Jun 30, 2025
221b416
non nullable handling
andimarek Jul 1, 2025
2ba4123
Merge branch 'master' into profiler-2
andimarek Jul 8, 2025
4008c11
master merging
andimarek Jul 9, 2025
f7e31e6
wip
andimarek Jul 16, 2025
3e29da4
Merge branch 'master' into profiler-2
andimarek Jul 16, 2025
999bb2f
handle non null case
andimarek Jul 16, 2025
5dde0e3
handle non null case
andimarek Jul 16, 2025
4a47b9d
add Map specific summary methods
andimarek Jul 17, 2025
0b7c15b
collect instrumentations
andimarek Jul 17, 2025
e6faa18
manual dispatch collected
andimarek Jul 18, 2025
0ab88da
wip
andimarek Jul 18, 2025
8bcdef8
wip
andimarek Jul 18, 2025
62f1e84
improve naming
andimarek Jul 18, 2025
76cdbc1
stabilize test
andimarek Jul 18, 2025
ca618b4
wip
andimarek Jul 18, 2025
535eb8e
counting wrapped trivial data fetchers
andimarek Jul 18, 2025
a04f5cb
introspection fields
andimarek Jul 19, 2025
572090e
data fetcher type statistics
andimarek Jul 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wip
  • Loading branch information
andimarek committed May 21, 2025
commit 275eaac079cfc84c52bce072923e56850f8d0090
2 changes: 1 addition & 1 deletion src/main/java/graphql/GraphQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionI
EngineRunningState engineRunningState = new EngineRunningState(executionInput, profiler);
return engineRunningState.engineRun(() -> {
ExecutionInput executionInputWithId = ensureInputHasId(executionInput);
profiler.setExecutionId(executionInputWithId.getExecutionId());
profiler.executionInput(executionInputWithId);
engineRunningState.updateExecutionId(executionInputWithId.getExecutionId());

CompletableFuture<InstrumentationState> instrumentationStateCF = instrumentation.createStateAsync(new InstrumentationCreateStateParameters(this.graphQLSchema, executionInputWithId));
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/graphql/Profiler.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package graphql;

import graphql.execution.EngineRunningObserver;
import graphql.execution.ExecutionId;
import graphql.execution.ResultPath;
import graphql.language.OperationDefinition;
import graphql.schema.DataFetcher;
Expand All @@ -25,7 +24,7 @@ default void subSelectionCount(int size) {

}

default void setExecutionId(ExecutionId executionId) {
default void executionInput(ExecutionInput executionInput) {

}

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/graphql/ProfilerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import graphql.execution.EngineRunningObserver;
import graphql.execution.ExecutionId;
import graphql.execution.ResultPath;
import graphql.execution.instrumentation.dataloader.DataLoaderDispatchingContextKeys;
import graphql.language.OperationDefinition;
import graphql.schema.DataFetcher;
import graphql.schema.PropertyDataFetcher;
Expand All @@ -29,8 +30,10 @@ public ProfilerImpl(GraphQLContext graphQLContext) {
}

@Override
public void setExecutionId(ExecutionId executionId) {
profilerResult.setExecutionId(executionId);
public void executionInput(ExecutionInput executionInput) {
profilerResult.setExecutionId(executionInput.getExecutionId());
boolean dataLoaderChainingEnabled = executionInput.getGraphQLContext().getBoolean(DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_CHAINING, false);
profilerResult.setDataLoaderChainingEnabled(dataLoaderChainingEnabled);
}

@Override
Expand All @@ -55,7 +58,7 @@ public void fieldFetched(Object fetchedObject, DataFetcher<?> dataFetcher, Resul
} else {
dataFetcherResultType = ProfilerResult.DataFetcherResultType.MATERIALIZED;
}
profilerResult.setDataFetcherResultType(path.toString(), dataFetcherResultType);
profilerResult.setDataFetcherResultType(key, dataFetcherResultType);
}

profilerResult.setDataFetcherType(key, dataFetcherType);
Expand Down
39 changes: 33 additions & 6 deletions src/main/java/graphql/ProfilerResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public class ProfilerResult {
private final Map<String, Integer> dataFetcherInvocationCount = new ConcurrentHashMap<>();
private final Map<String, DataFetcherType> dataFetcherTypeMap = new ConcurrentHashMap<>();

// the key is the whole result key, not just the query path
private final Map<String, DataFetcherResultType> dataFetcherResultType = new ConcurrentHashMap<>();
private volatile String operationName;
private volatile String operationType;
private volatile boolean dataLoaderChainingEnabled;



public enum DataFetcherType {
Expand All @@ -47,6 +48,11 @@ public enum DataFetcherResultType {

// setters are package private to prevent exposure

void setDataLoaderChainingEnabled(boolean dataLoaderChainingEnabled) {
this.dataLoaderChainingEnabled = dataLoaderChainingEnabled;
}


void setDataFetcherType(String key, DataFetcherType dataFetcherType) {
dataFetcherTypeMap.putIfAbsent(key, dataFetcherType);
totalDataFetcherInvocations.incrementAndGet();
Expand All @@ -55,8 +61,8 @@ void setDataFetcherType(String key, DataFetcherType dataFetcherType) {
}
}

void setDataFetcherResultType(String resultPath, DataFetcherResultType fetchedType) {
dataFetcherResultType.put(resultPath, fetchedType);
void setDataFetcherResultType(String key, DataFetcherResultType fetchedType) {
dataFetcherResultType.putIfAbsent(key, fetchedType);
}

void incrementDataFetcherInvocationCount(String key) {
Expand Down Expand Up @@ -148,9 +154,7 @@ public Map<String, DataFetcherResultType> getDataFetcherResultType() {
return dataFetcherResultType;
}


@Override
public String toString() {
public String fullSummary() {
return "ProfilerResult{" +
"executionId=" + executionId +
", operation=" + operationType + ":" + operationName +
Expand All @@ -164,6 +168,29 @@ public String toString() {
", dataFetcherInvocationCount=" + dataFetcherInvocationCount +
", dataFetcherTypeMap=" + dataFetcherTypeMap +
", dataFetcherResultType=" + dataFetcherResultType +
", dataLoaderChainingEnabled=" + dataLoaderChainingEnabled +
'}';
}

public String shortSummary() {
return "ProfilerResult{" +
"executionId=" + executionId +
", operation=" + operationType + ":" + operationName +
", startTime=" + startTime +
", endTime=" + endTime +
", totalRunTime=" + (endTime - startTime) + "(" + (endTime - startTime) / 1_000_000 + "ms)" +
", engineTotalRunningTime=" + engineTotalRunningTime + "(" + engineTotalRunningTime / 1_000_000 + "ms)" +
", totalDataFetcherInvocations=" + totalDataFetcherInvocations +
", totalPropertyDataFetcherInvocations=" + totalPropertyDataFetcherInvocations +
", fieldsFetchedCount=" + fieldsFetched.size() +
", dataLoaderChainingEnabled=" + dataLoaderChainingEnabled +
'}';


}

@Override
public String toString() {
return shortSummary();
}
}
6 changes: 3 additions & 3 deletions src/test/groovy/graphql/ProfilerTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class ProfilerTest extends Specification {
given:
def sdl = '''
type Query {
foo: Foo
foo: [Foo]
}
type Foo {
id: String
Expand All @@ -144,7 +144,7 @@ class ProfilerTest extends Specification {
foo: { DataFetchingEnvironment dfe ->
return CompletableFuture.supplyAsync {
Thread.sleep(100)
return [id: "1", name: "foo"]
return [[id: "1", name: "foo"]]
}
} as DataFetcher],
Foo : [
Expand All @@ -164,7 +164,7 @@ class ProfilerTest extends Specification {
def profilerResult = ei.getGraphQLContext().get(ProfilerResult.PROFILER_CONTEXT_KEY) as ProfilerResult

then:
result.getData() == [foo: [id: "1", name: "foo"]]
result.getData() == [foo: [[id: "1", name: "foo"]]]
profilerResult.getDataFetcherResultType() == ["/foo/name": COMPLETABLE_FUTURE_COMPLETED, "/foo": COMPLETABLE_FUTURE_NOT_COMPLETED]


Expand Down