Repository navigation
adding Profiler #3976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding Profiler #3976
Changes from 1 commit
0651b82
cc1de5e
eef80ec
15cf642
b7379ef
275eaac
cd002c0
b75a14d
450a9fc
5e9e713
b3515b7
1800f77
221b416
2ba4123
4008c11
f7e31e6
3e29da4
999bb2f
5dde0e3
4a47b9d
0b7c15b
e6faa18
0ab88da
8bcdef8
62f1e84
76cdbc1
ca618b4
535eb8e
a04f5cb
572090e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package graphql; | ||
|
|
||
| import graphql.execution.ResultPath; | ||
| import graphql.schema.DataFetcher; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| @Internal | ||
| @NullMarked | ||
| public interface Profiler { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a quick JavaDoc explaining what this does
Of course 1 sentence isn't enough, let's add a documentation link here when it's written
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an internal class btw |
||
|
|
||
|
|
||
| Profiler NO_OP = new Profiler() { | ||
| }; | ||
|
|
||
| default void start() { | ||
|
|
||
| } | ||
|
|
||
|
|
||
| default void rootFieldCount(int size) { | ||
|
|
||
| } | ||
|
|
||
| default void subSelectionCount(int size) { | ||
|
|
||
| } | ||
|
|
||
| default void fieldFetched(Object fetchedObject, DataFetcher<?> dataFetcher, ResultPath path) { | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package graphql; | ||
|
|
||
| import graphql.execution.ResultPath; | ||
| import graphql.schema.DataFetcher; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for this PR, but in the future, with more Profiler features you might want to introduce options to toggle sets of tracking on and off e.g. toggle DataLoader related tracking on and off |
||
| @Internal | ||
| @NullMarked | ||
| public class ProfilerImpl implements Profiler { | ||
|
|
||
| volatile long startTime; | ||
| volatile int rootFieldCount; | ||
|
|
||
| AtomicInteger propertyDataFetcherCount; | ||
|
|
||
| final Map<String, Integer> dataFetcherInvocationCount = new ConcurrentHashMap<>(); | ||
|
|
||
|
|
||
| final ProfilerResult profilerResult = new ProfilerResult(); | ||
|
|
||
| public ProfilerImpl(GraphQLContext graphQLContext) { | ||
| graphQLContext.put(ProfilerResult.PROFILER_CONTEXT_KEY, profilerResult); | ||
| } | ||
|
|
||
| @Override | ||
| public void start() { | ||
| startTime = System.nanoTime(); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public void rootFieldCount(int count) { | ||
| this.rootFieldCount = count; | ||
| } | ||
|
|
||
| @Override | ||
| public void fieldFetched(Object fetchedObject, DataFetcher<?> dataFetcher, ResultPath path) { | ||
| String key = String.join("/", path.getKeysOnly()); | ||
| profilerResult.addFieldFetched(key); | ||
|
|
||
| // dataFetcherInvocationCount.compute(key, (k, v) -> v == null ? 1 : v + 1); | ||
| // | ||
| // if (dataFetcher instanceof PropertyDataFetcher) { | ||
| // propertyDataFetcherCount.incrementAndGet(); | ||
| // } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package graphql; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| @ExperimentalApi | ||
| public class ProfilerResult { | ||
|
|
||
| public static String PROFILER_CONTEXT_KEY = "__GJ_PROFILER"; | ||
|
|
||
| private int fieldCount; | ||
|
|
||
| private int propertyDataFetcherCount; | ||
|
|
||
| private final Set<String> fieldsFetched = ConcurrentHashMap.newKeySet(); | ||
|
|
||
| public static enum ResultType { | ||
| COMPLETABLE_FUTURE_COMPLETED, | ||
| COMPLETABLE_FUTURE_NOT_COMPLETED, | ||
| MATERIALIZED | ||
|
|
||
| } | ||
|
|
||
| private Map<String, ResultType> queryPathToResultType; | ||
|
|
||
|
|
||
| public void addFieldFetched(String fieldPath) { | ||
| fieldsFetched.add(fieldPath); | ||
| } | ||
|
|
||
| public Set<String> getFieldsFetched() { | ||
| return fieldsFetched; | ||
| } | ||
|
|
||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For another PR, not this one
Can you add the toggle to
GraphQLUnusualConfigurationinstead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be discussed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be considered in another PR