samaitra commented on a change in pull request #16:
URL: https://github.com/apache/ignite-extensions/pull/16#discussion_r443254180



##########
File path: 
modules/profiling-ext/src/main/java/org/apache/ignite/internal/profiling/handlers/QueryHandler.java
##########
@@ -0,0 +1,278 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.profiling.handlers;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
+import org.apache.ignite.internal.profiling.util.OrderedFixedSizeStructure;
+import org.apache.ignite.internal.util.typedef.F;
+
+import static 
org.apache.ignite.internal.profiling.ProfilingFilesParser.currentNodeId;
+import static org.apache.ignite.internal.profiling.util.Utils.MAPPER;
+
+/**
+ * Builds JSON with aggregated query statistics.
+ *
+ * Example:
+ * <pre>
+ * {
+ *      $textOrCacheName : {
+ *          "count" : $executionsCount,
+ *          "duration" : $duration,
+ *          "logicalReads" : $logicalReads,
+ *          "physicalReads" : $physicalReads,
+ *          "failures" : $failures
+ *      }
+ * }
+ * </pre>
+ * Example of slowest queries:
+ * <pre>
+ * [
+ *  {
+ *      "text" : $textOrCacheName,
+ *      "startTime" : $startTime,
+ *      "duration" : $duration,
+ *      "nodeId" : $nodeId,
+ *      "logicalReads" : $logicalReads,
+ *      "physicalReads" : $physicalReads,
+ *      "success" : $success
+ *  }
+ * ]
+ * </pre>
+ */
+public class QueryHandler implements IgniteProfilingHandler {
+    /**  Queries results: queryType -> queryText -> aggregatedInfo. */
+    private final Map<GridCacheQueryType, Map<String, AggregatedQueryInfo>> 
aggrQuery =
+        new EnumMap<>(GridCacheQueryType.class);
+
+    /** Parsed reads: queryType -> queryNodeId -> queryId -> reads. */
+    private final Map<GridCacheQueryType, Map<UUID, Map<Long, long[]>>> 
readsById =
+        new EnumMap<>(GridCacheQueryType.class);
+
+    /** Structure to store top of slow SQL queries: queryType -> duration -> 
query. */
+    private final Map<GridCacheQueryType, OrderedFixedSizeStructure<Long, 
Query>> topSlow =
+        new EnumMap<>(GridCacheQueryType.class);
+
+    /** {@inheritDoc} */
+    @Override public void query(GridCacheQueryType type, String text, long id, 
long startTime,
+        long duration, boolean success) {
+        UUID queryNodeId = currentNodeId();
+
+        Query query = new Query(type, text, queryNodeId, id, startTime, 
duration, success);
+
+        OrderedFixedSizeStructure<Long, Query> tree = 
topSlow.computeIfAbsent(type,
+            t -> new OrderedFixedSizeStructure<>());

Review comment:
       can we rename `t` to a variable name

##########
File path: 
modules/profiling-ext/src/main/java/org/apache/ignite/internal/profiling/handlers/QueryHandler.java
##########
@@ -0,0 +1,278 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.profiling.handlers;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
+import org.apache.ignite.internal.profiling.util.OrderedFixedSizeStructure;
+import org.apache.ignite.internal.util.typedef.F;
+
+import static 
org.apache.ignite.internal.profiling.ProfilingFilesParser.currentNodeId;
+import static org.apache.ignite.internal.profiling.util.Utils.MAPPER;
+
+/**
+ * Builds JSON with aggregated query statistics.
+ *
+ * Example:
+ * <pre>
+ * {
+ *      $textOrCacheName : {
+ *          "count" : $executionsCount,
+ *          "duration" : $duration,
+ *          "logicalReads" : $logicalReads,
+ *          "physicalReads" : $physicalReads,
+ *          "failures" : $failures
+ *      }
+ * }
+ * </pre>
+ * Example of slowest queries:
+ * <pre>
+ * [
+ *  {
+ *      "text" : $textOrCacheName,
+ *      "startTime" : $startTime,
+ *      "duration" : $duration,
+ *      "nodeId" : $nodeId,
+ *      "logicalReads" : $logicalReads,
+ *      "physicalReads" : $physicalReads,
+ *      "success" : $success
+ *  }
+ * ]
+ * </pre>
+ */
+public class QueryHandler implements IgniteProfilingHandler {
+    /**  Queries results: queryType -> queryText -> aggregatedInfo. */
+    private final Map<GridCacheQueryType, Map<String, AggregatedQueryInfo>> 
aggrQuery =
+        new EnumMap<>(GridCacheQueryType.class);
+
+    /** Parsed reads: queryType -> queryNodeId -> queryId -> reads. */
+    private final Map<GridCacheQueryType, Map<UUID, Map<Long, long[]>>> 
readsById =
+        new EnumMap<>(GridCacheQueryType.class);
+
+    /** Structure to store top of slow SQL queries: queryType -> duration -> 
query. */
+    private final Map<GridCacheQueryType, OrderedFixedSizeStructure<Long, 
Query>> topSlow =
+        new EnumMap<>(GridCacheQueryType.class);
+
+    /** {@inheritDoc} */
+    @Override public void query(GridCacheQueryType type, String text, long id, 
long startTime,
+        long duration, boolean success) {
+        UUID queryNodeId = currentNodeId();
+
+        Query query = new Query(type, text, queryNodeId, id, startTime, 
duration, success);
+
+        OrderedFixedSizeStructure<Long, Query> tree = 
topSlow.computeIfAbsent(type,
+            t -> new OrderedFixedSizeStructure<>());
+
+        tree.put(duration, query);
+
+        AggregatedQueryInfo info = aggrQuery.computeIfAbsent(type, t -> new 
HashMap<>())
+            .computeIfAbsent(text, k -> new AggregatedQueryInfo());
+
+        info.merge(queryNodeId, id, duration, success);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void queryReads(GridCacheQueryType type, UUID 
queryNodeId, long id, long logicalReads,
+        long physicalReads) {
+
+        Map<Long, long[]> ids = readsById.computeIfAbsent(type, t -> new 
HashMap<>())
+            .computeIfAbsent(queryNodeId, k -> new HashMap<>());

Review comment:
       can we rename `k` to a variable




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to