11package graphql ;
22
3+ import java .util .LinkedHashSet ;
34import java .util .Map ;
45import java .util .Set ;
56import java .util .concurrent .ConcurrentHashMap ;
7+ import java .util .concurrent .atomic .AtomicInteger ;
68
79@ ExperimentalApi
810public class ProfilerResult {
911
1012 public static String PROFILER_CONTEXT_KEY = "__GJ_PROFILER" ;
1113
12- private int fieldCount ;
14+ private final AtomicInteger totalDataFetcherInvocations = new AtomicInteger ();
15+ private final AtomicInteger totalPropertyDataFetcherInvocations = new AtomicInteger ();
1316
14- private int propertyDataFetcherCount ;
1517
1618 private final Set <String > fieldsFetched = ConcurrentHashMap .newKeySet ();
19+ private final Map <String , Integer > dataFetcherInvocationCount = new ConcurrentHashMap <>();
20+ private final Map <String , DataFetcherType > dataFetcherTypeMap = new ConcurrentHashMap <>();
1721
18- public static enum ResultType {
22+ public enum DataFetcherType {
23+ PROPERTY_DATA_FETCHER ,
24+ CUSTOM
25+ }
26+
27+ public enum ResultType {
1928 COMPLETABLE_FUTURE_COMPLETED ,
2029 COMPLETABLE_FUTURE_NOT_COMPLETED ,
2130 MATERIALIZED
@@ -24,14 +33,58 @@ public static enum ResultType {
2433
2534 private Map <String , ResultType > queryPathToResultType ;
2635
36+ void setDataFetcherType (String key , DataFetcherType dataFetcherType ) {
37+ dataFetcherTypeMap .putIfAbsent (key , dataFetcherType );
38+ totalDataFetcherInvocations .incrementAndGet ();
39+ if (dataFetcherType == DataFetcherType .PROPERTY_DATA_FETCHER ) {
40+ totalPropertyDataFetcherInvocations .incrementAndGet ();
41+ }
42+ }
43+
44+ void incrementDataFetcherInvocationCount (String key ) {
45+ dataFetcherInvocationCount .compute (key , (k , v ) -> v == null ? 1 : v + 1 );
46+ }
2747
28- public void addFieldFetched (String fieldPath ) {
48+ void addFieldFetched (String fieldPath ) {
2949 fieldsFetched .add (fieldPath );
3050 }
3151
52+
3253 public Set <String > getFieldsFetched () {
3354 return fieldsFetched ;
3455 }
3556
57+ public Set <String > getCustomDataFetcherFields () {
58+ Set <String > result = new LinkedHashSet <>(fieldsFetched );
59+ for (String field : fieldsFetched ) {
60+ if (dataFetcherTypeMap .get (field ) == DataFetcherType .CUSTOM ) {
61+ result .add (field );
62+ }
63+ }
64+ return result ;
65+ }
66+
67+ public Set <String > getPropertyDataFetcherFields () {
68+ Set <String > result = new LinkedHashSet <>(fieldsFetched );
69+ for (String field : fieldsFetched ) {
70+ if (dataFetcherTypeMap .get (field ) == DataFetcherType .PROPERTY_DATA_FETCHER ) {
71+ result .add (field );
72+ }
73+ }
74+ return result ;
75+ }
76+
77+
78+ public int getTotalDataFetcherInvocations () {
79+ return totalDataFetcherInvocations .get ();
80+ }
81+
82+ public int getTotalPropertyDataFetcherInvocations () {
83+ return totalPropertyDataFetcherInvocations .get ();
84+ }
85+
86+ public int getTotalCustomDataFetcherInvocations () {
87+ return totalDataFetcherInvocations .get () - totalPropertyDataFetcherInvocations .get ();
88+ }
3689
3790}
0 commit comments