You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/01/19 09:55:27 UTC

[GitHub] [ignite-extensions] NSAmelchev opened a new pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

NSAmelchev opened a new pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite-extensions] nizhikov commented on a change in pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40#discussion_r565094349



##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/PerformanceStatisticsPrinter.java
##########
@@ -0,0 +1,232 @@
+/*
+ * 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.performancestatistics;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.performancestatistics.handlers.PrintHandler;
+import org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsReader;
+import org.apache.ignite.internal.processors.performancestatistics.OperationType;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
+import static java.util.Collections.singletonList;
+import static java.util.stream.Collectors.joining;
+
+/**
+ * Performance statistics printer.
+ */
+public class PerformanceStatisticsPrinter {
+    /**
+     * @param args Program arguments or '-h' to get usage help.
+     */
+    public static void main(String... args) throws Exception {
+        Parameters params = parseArguments(args);
+
+        validateParameters(params);
+
+        PrintStream ps = printStream(params.outFile);
+
+        try {
+            new FilePerformanceStatisticsReader(
+                new PrintHandler(ps, params.ops, params.from, params.to,params.cacheIds))
+                .read(singletonList(new File(params.statFileOrDir)));
+        }
+        finally {
+            if (params.outFile != null)
+                ps.close();
+        }
+    }
+
+    /**
+     * Parses arguments or print help.
+     *
+     * @param args Arguments to parse.
+     * @return Program arguments.
+     */
+    private static Parameters parseArguments(String[] args) {
+        if (args == null || args.length == 0 || "--help".equalsIgnoreCase(args[0]) || "-h".equalsIgnoreCase(args[0]))
+            printHelp();
+
+        Parameters params = new Parameters();
+
+        Iterator<String> iter = Arrays.asList(args).iterator();
+
+        params.statFileOrDir = iter.next();
+
+        while (iter.hasNext()) {
+            String arg = iter.next();
+
+            if ("--out".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected output file name");
+
+                params.outFile = iter.next();
+            }
+            else if ("--ops".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected operation types");
+
+                String[] ops = iter.next().split(",");
+
+                A.ensure(ops.length > 0, "Expected at least one operation");
+
+                params.ops = new BitSet();
+
+                for (String op : ops) {
+                    OperationType opType = enumIgnoreCase(op, OperationType.class);
+
+                    A.ensure(opType != null, "Unknown operation type [op=" + op + ']');
+
+                    params.ops.set(opType.id());
+                }
+            }
+            else if ("--from".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected time from");
+
+                params.from = Long.parseLong(iter.next());
+            }
+            else if ("--to".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected time to");
+
+                params.to = Long.parseLong(iter.next());
+            }
+            else if ("--caches".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected cache names");
+
+                String[] caches = iter.next().split(",");
+
+                A.ensure(caches.length > 0, "Expected at least one cache name");
+
+                params.cacheIds = Arrays.stream(caches).map(CU::cacheId).collect(Collectors.toSet());
+            }
+            else
+                throw new IllegalArgumentException("Unknown command: " + arg);
+        }
+
+        return params;
+    }
+
+    /** Prints help. */
+    private static void printHelp() {
+        String ops = Arrays.stream(OperationType.values()).map(Enum::toString).collect(joining(", "));
+
+        System.out.println("The script is used to print performance statistics files to the console or file." +
+            U.nl() + U.nl() +
+            "Usage: print-statistics.sh path_to_files [--out out_file] [--ops op_types] " +
+            "[--from startTimeFrom] [--to startTimeTo] [--caches cache_names]" + U.nl() +
+            U.nl() +
+            "  path_to_files - Performance statistics file or files directory." + U.nl() +
+            "  out_file      - Output file." + U.nl() +
+            "  op_types      - Comma separated list of operation types to filter the output." + U.nl() +
+            "  from          - The minimum operation start time to filter the output." + U.nl() +
+            "  to            - The maximum operation start time to filter the output." + U.nl() +
+            "  cache_names   - Comma separated list of cache names to filter the output." + U.nl() +
+            U.nl() +
+            "Times must be specified in the Unix time format in milliseconds." + U.nl() +
+            "List of operation types: " + ops + '.');
+
+        System.exit(0);
+    }
+
+    /** @param params Validates parameters. */
+    private static void validateParameters(Parameters params) {
+        File statFiles = new File(params.statFileOrDir);
+
+        A.ensure(statFiles.exists(), "Performance statistics file or files directory does not exists");
+
+        if (params.outFile != null) {
+            File out = new File(params.outFile);
+
+            try {
+                boolean created = out.createNewFile();
+
+                if (!created) {

Review comment:
       Can we just append to the existing file?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite-extensions] nizhikov commented on a change in pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40#discussion_r565093673



##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/PerformanceStatisticsPrinter.java
##########
@@ -0,0 +1,232 @@
+/*
+ * 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.performancestatistics;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.performancestatistics.handlers.PrintHandler;
+import org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsReader;
+import org.apache.ignite.internal.processors.performancestatistics.OperationType;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
+import static java.util.Collections.singletonList;
+import static java.util.stream.Collectors.joining;
+
+/**
+ * Performance statistics printer.
+ */
+public class PerformanceStatisticsPrinter {
+    /**
+     * @param args Program arguments or '-h' to get usage help.
+     */
+    public static void main(String... args) throws Exception {
+        Parameters params = parseArguments(args);
+
+        validateParameters(params);
+
+        PrintStream ps = printStream(params.outFile);
+
+        try {
+            new FilePerformanceStatisticsReader(
+                new PrintHandler(ps, params.ops, params.from, params.to,params.cacheIds))
+                .read(singletonList(new File(params.statFileOrDir)));
+        }
+        finally {
+            if (params.outFile != null)
+                ps.close();
+        }
+    }
+
+    /**
+     * Parses arguments or print help.
+     *
+     * @param args Arguments to parse.
+     * @return Program arguments.
+     */
+    private static Parameters parseArguments(String[] args) {
+        if (args == null || args.length == 0 || "--help".equalsIgnoreCase(args[0]) || "-h".equalsIgnoreCase(args[0]))
+            printHelp();
+
+        Parameters params = new Parameters();
+
+        Iterator<String> iter = Arrays.asList(args).iterator();
+
+        params.statFileOrDir = iter.next();
+
+        while (iter.hasNext()) {
+            String arg = iter.next();
+
+            if ("--out".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected output file name");
+
+                params.outFile = iter.next();
+            }
+            else if ("--ops".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected operation types");
+
+                String[] ops = iter.next().split(",");
+
+                A.ensure(ops.length > 0, "Expected at least one operation");
+
+                params.ops = new BitSet();
+
+                for (String op : ops) {
+                    OperationType opType = enumIgnoreCase(op, OperationType.class);
+
+                    A.ensure(opType != null, "Unknown operation type [op=" + op + ']');
+
+                    params.ops.set(opType.id());
+                }
+            }
+            else if ("--from".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected time from");
+
+                params.from = Long.parseLong(iter.next());
+            }
+            else if ("--to".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected time to");
+
+                params.to = Long.parseLong(iter.next());
+            }
+            else if ("--caches".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected cache names");
+
+                String[] caches = iter.next().split(",");
+
+                A.ensure(caches.length > 0, "Expected at least one cache name");
+
+                params.cacheIds = Arrays.stream(caches).map(CU::cacheId).collect(Collectors.toSet());
+            }
+            else
+                throw new IllegalArgumentException("Unknown command: " + arg);
+        }
+
+        return params;
+    }
+
+    /** Prints help. */
+    private static void printHelp() {
+        String ops = Arrays.stream(OperationType.values()).map(Enum::toString).collect(joining(", "));
+
+        System.out.println("The script is used to print performance statistics files to the console or file." +
+            U.nl() + U.nl() +
+            "Usage: print-statistics.sh path_to_files [--out out_file] [--ops op_types] " +
+            "[--from startTimeFrom] [--to startTimeTo] [--caches cache_names]" + U.nl() +
+            U.nl() +
+            "  path_to_files - Performance statistics file or files directory." + U.nl() +
+            "  out_file      - Output file." + U.nl() +
+            "  op_types      - Comma separated list of operation types to filter the output." + U.nl() +
+            "  from          - The minimum operation start time to filter the output." + U.nl() +
+            "  to            - The maximum operation start time to filter the output." + U.nl() +
+            "  cache_names   - Comma separated list of cache names to filter the output." + U.nl() +
+            U.nl() +
+            "Times must be specified in the Unix time format in milliseconds." + U.nl() +
+            "List of operation types: " + ops + '.');
+
+        System.exit(0);
+    }
+
+    /** @param params Validates parameters. */
+    private static void validateParameters(Parameters params) {
+        File statFiles = new File(params.statFileOrDir);

Review comment:
       statFiles -> statFileOrDir




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite-extensions] NSAmelchev commented on a change in pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40#discussion_r565141137



##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/handlers/PrintHandler.java
##########
@@ -0,0 +1,250 @@
+/*
+ * 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.performancestatistics.handlers;
+
+import java.io.PrintStream;
+import java.util.BitSet;
+import java.util.Set;
+import java.util.UUID;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
+import org.apache.ignite.internal.processors.performancestatistics.OperationType;
+import org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsHandler;
+import org.apache.ignite.internal.util.GridIntIterator;
+import org.apache.ignite.internal.util.GridIntList;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.Nullable;
+
+import static com.fasterxml.jackson.core.io.CharTypes.appendQuoted;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_START;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.JOB;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.QUERY;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.QUERY_READS;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TASK;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TX_COMMIT;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TX_ROLLBACK;
+
+/**
+ * Handler to print performance statistics operations.
+ */
+public class PrintHandler implements PerformanceStatisticsHandler {
+    /** Json mapper. */
+    private static final ObjectMapper MAPPER = new ObjectMapper();
+
+    /** Print stream. */
+    private final PrintStream ps;
+
+    /** */
+    StringBuilder sb = new StringBuilder();

Review comment:
       Done.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite-extensions] nizhikov commented on a change in pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40#discussion_r562481490



##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/PerformanceStatisticsPrinter.java
##########
@@ -0,0 +1,225 @@
+/*
+ * 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.performancestatistics;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.performancestatistics.handlers.PrintHandler;
+import org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsReader;
+import org.apache.ignite.internal.processors.performancestatistics.OperationType;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
+import static java.util.Collections.singletonList;
+import static java.util.stream.Collectors.joining;
+
+/**
+ * Performance statistics printer.
+ */
+public class PerformanceStatisticsPrinter {
+    /**
+     * @param args Program arguments or '-h' to get usage help.
+     */
+    public static void main(String... args) throws Exception {
+        Parameters params = parseArguments(args);
+
+        validateParameters(params);
+
+        PrintStream ps;
+
+        if (params.outFile != null) {
+            try {
+                ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(params.outFile))));
+            }
+            catch (IOException e) {
+                throw new IllegalArgumentException("Cannot write to output file", e);
+            }
+        }
+        else
+            ps = System.out;

Review comment:
       Let's extract this to the separate method.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite-extensions] nizhikov commented on a change in pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40#discussion_r565106176



##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/handlers/PrintHandler.java
##########
@@ -0,0 +1,250 @@
+/*
+ * 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.performancestatistics.handlers;
+
+import java.io.PrintStream;
+import java.util.BitSet;
+import java.util.Set;
+import java.util.UUID;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
+import org.apache.ignite.internal.processors.performancestatistics.OperationType;
+import org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsHandler;
+import org.apache.ignite.internal.util.GridIntIterator;
+import org.apache.ignite.internal.util.GridIntList;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.Nullable;
+
+import static com.fasterxml.jackson.core.io.CharTypes.appendQuoted;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_START;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.JOB;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.QUERY;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.QUERY_READS;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TASK;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TX_COMMIT;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TX_ROLLBACK;
+
+/**
+ * Handler to print performance statistics operations.
+ */
+public class PrintHandler implements PerformanceStatisticsHandler {
+    /** Json mapper. */
+    private static final ObjectMapper MAPPER = new ObjectMapper();
+
+    /** Print stream. */
+    private final PrintStream ps;
+
+    /** */
+    StringBuilder sb = new StringBuilder();

Review comment:
       Let's get rid of `sb` and append all changes directly to the print stream.
   




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite-extensions] NSAmelchev commented on a change in pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40#discussion_r562631739



##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/PerformanceStatisticsPrinter.java
##########
@@ -0,0 +1,225 @@
+/*
+ * 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.performancestatistics;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.performancestatistics.handlers.PrintHandler;
+import org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsReader;
+import org.apache.ignite.internal.processors.performancestatistics.OperationType;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
+import static java.util.Collections.singletonList;
+import static java.util.stream.Collectors.joining;
+
+/**
+ * Performance statistics printer.
+ */
+public class PerformanceStatisticsPrinter {
+    /**
+     * @param args Program arguments or '-h' to get usage help.
+     */
+    public static void main(String... args) throws Exception {
+        Parameters params = parseArguments(args);
+
+        validateParameters(params);
+
+        PrintStream ps;
+
+        if (params.outFile != null) {
+            try {
+                ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(params.outFile))));
+            }
+            catch (IOException e) {
+                throw new IllegalArgumentException("Cannot write to output file", e);
+            }
+        }
+        else
+            ps = System.out;
+
+        try {
+            PrintHandler hnd = new PrintHandler(ps, params.ops, params.from, params.to, params.cacheIds);

Review comment:
       Done.

##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/PerformanceStatisticsPrinter.java
##########
@@ -0,0 +1,225 @@
+/*
+ * 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.performancestatistics;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.performancestatistics.handlers.PrintHandler;
+import org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsReader;
+import org.apache.ignite.internal.processors.performancestatistics.OperationType;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
+import static java.util.Collections.singletonList;
+import static java.util.stream.Collectors.joining;
+
+/**
+ * Performance statistics printer.
+ */
+public class PerformanceStatisticsPrinter {
+    /**
+     * @param args Program arguments or '-h' to get usage help.
+     */
+    public static void main(String... args) throws Exception {
+        Parameters params = parseArguments(args);
+
+        validateParameters(params);
+
+        PrintStream ps;
+
+        if (params.outFile != null) {
+            try {
+                ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(params.outFile))));
+            }
+            catch (IOException e) {
+                throw new IllegalArgumentException("Cannot write to output file", e);
+            }
+        }
+        else
+            ps = System.out;

Review comment:
       Done.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite-extensions] NSAmelchev merged pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

Posted by GitBox <gi...@apache.org>.
NSAmelchev merged pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite-extensions] NSAmelchev commented on a change in pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40#discussion_r565212098



##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/handlers/PrintHandler.java
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.performancestatistics.handlers;
+
+import java.io.PrintStream;
+import java.util.BitSet;
+import java.util.Set;
+import java.util.UUID;
+import com.fasterxml.jackson.databind.node.TextNode;
+import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
+import org.apache.ignite.internal.processors.performancestatistics.OperationType;
+import org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsHandler;
+import org.apache.ignite.internal.util.GridIntIterator;
+import org.apache.ignite.internal.util.GridIntList;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_START;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.JOB;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.QUERY;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.QUERY_READS;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TASK;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TX_COMMIT;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TX_ROLLBACK;
+
+/**
+ * Handler to print performance statistics operations.
+ */
+public class PrintHandler implements PerformanceStatisticsHandler {
+    /** Print stream. */
+    private final PrintStream ps;
+
+    /** Operation types. */
+    @Nullable private final BitSet ops;
+
+    /** Start time from. */
+    private final long from;
+
+    /** Start time to. */
+    private final long to;
+
+    /** Cache identifiers to filter the output. */
+    @Nullable private final Set<Integer> cacheIds;
+
+    /**
+     * @param ps Print stream.
+     * @param ops Set of operations to print.
+     * @param from The minimum operation start time to filter the output.
+     * @param to The maximum operation start time to filter the output.
+     * @param cacheIds Cache identifiers to filter the output.
+     */
+    public PrintHandler(PrintStream ps, @Nullable BitSet ops, long from, long to, @Nullable Set<Integer> cacheIds) {
+        this.ps = ps;
+        this.ops = ops;
+        this.from = from;
+        this.to = to;
+        this.cacheIds = cacheIds;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void cacheStart(UUID nodeId, int cacheId, String name) {
+        if (skip(CACHE_START, cacheId))
+            return;
+
+        ps.print("{\"op\":\"" + CACHE_START);
+        ps.print("\",\"nodeId\":\"");
+        ps.print(nodeId);
+        ps.print("\",\"cacheId\":");
+        ps.print(cacheId);
+        ps.print(",\"name\":");
+        ps.print(new TextNode(name));

Review comment:
       Done.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite-extensions] nizhikov commented on a change in pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40#discussion_r562481838



##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/PerformanceStatisticsPrinter.java
##########
@@ -0,0 +1,225 @@
+/*
+ * 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.performancestatistics;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.performancestatistics.handlers.PrintHandler;
+import org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsReader;
+import org.apache.ignite.internal.processors.performancestatistics.OperationType;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
+import static java.util.Collections.singletonList;
+import static java.util.stream.Collectors.joining;
+
+/**
+ * Performance statistics printer.
+ */
+public class PerformanceStatisticsPrinter {
+    /**
+     * @param args Program arguments or '-h' to get usage help.
+     */
+    public static void main(String... args) throws Exception {
+        Parameters params = parseArguments(args);
+
+        validateParameters(params);
+
+        PrintStream ps;
+
+        if (params.outFile != null) {
+            try {
+                ps = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(params.outFile))));
+            }
+            catch (IOException e) {
+                throw new IllegalArgumentException("Cannot write to output file", e);
+            }
+        }
+        else
+            ps = System.out;
+
+        try {
+            PrintHandler hnd = new PrintHandler(ps, params.ops, params.from, params.to, params.cacheIds);

Review comment:
       `hnd` variable can be inlined.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite-extensions] NSAmelchev commented on a change in pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

Posted by GitBox <gi...@apache.org>.
NSAmelchev commented on a change in pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40#discussion_r565101444



##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/PerformanceStatisticsPrinter.java
##########
@@ -0,0 +1,232 @@
+/*
+ * 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.performancestatistics;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.performancestatistics.handlers.PrintHandler;
+import org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsReader;
+import org.apache.ignite.internal.processors.performancestatistics.OperationType;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
+import static java.util.Collections.singletonList;
+import static java.util.stream.Collectors.joining;
+
+/**
+ * Performance statistics printer.
+ */
+public class PerformanceStatisticsPrinter {
+    /**
+     * @param args Program arguments or '-h' to get usage help.
+     */
+    public static void main(String... args) throws Exception {
+        Parameters params = parseArguments(args);
+
+        validateParameters(params);
+
+        PrintStream ps = printStream(params.outFile);
+
+        try {
+            new FilePerformanceStatisticsReader(
+                new PrintHandler(ps, params.ops, params.from, params.to,params.cacheIds))
+                .read(singletonList(new File(params.statFileOrDir)));
+        }
+        finally {
+            if (params.outFile != null)
+                ps.close();
+        }
+    }
+
+    /**
+     * Parses arguments or print help.
+     *
+     * @param args Arguments to parse.
+     * @return Program arguments.
+     */
+    private static Parameters parseArguments(String[] args) {
+        if (args == null || args.length == 0 || "--help".equalsIgnoreCase(args[0]) || "-h".equalsIgnoreCase(args[0]))
+            printHelp();
+
+        Parameters params = new Parameters();
+
+        Iterator<String> iter = Arrays.asList(args).iterator();
+
+        params.statFileOrDir = iter.next();
+
+        while (iter.hasNext()) {
+            String arg = iter.next();
+
+            if ("--out".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected output file name");
+
+                params.outFile = iter.next();
+            }
+            else if ("--ops".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected operation types");
+
+                String[] ops = iter.next().split(",");
+
+                A.ensure(ops.length > 0, "Expected at least one operation");
+
+                params.ops = new BitSet();
+
+                for (String op : ops) {
+                    OperationType opType = enumIgnoreCase(op, OperationType.class);
+
+                    A.ensure(opType != null, "Unknown operation type [op=" + op + ']');
+
+                    params.ops.set(opType.id());
+                }
+            }
+            else if ("--from".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected time from");
+
+                params.from = Long.parseLong(iter.next());
+            }
+            else if ("--to".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected time to");
+
+                params.to = Long.parseLong(iter.next());
+            }
+            else if ("--caches".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected cache names");
+
+                String[] caches = iter.next().split(",");
+
+                A.ensure(caches.length > 0, "Expected at least one cache name");
+
+                params.cacheIds = Arrays.stream(caches).map(CU::cacheId).collect(Collectors.toSet());
+            }
+            else
+                throw new IllegalArgumentException("Unknown command: " + arg);
+        }
+
+        return params;
+    }
+
+    /** Prints help. */
+    private static void printHelp() {
+        String ops = Arrays.stream(OperationType.values()).map(Enum::toString).collect(joining(", "));
+
+        System.out.println("The script is used to print performance statistics files to the console or file." +
+            U.nl() + U.nl() +
+            "Usage: print-statistics.sh path_to_files [--out out_file] [--ops op_types] " +
+            "[--from startTimeFrom] [--to startTimeTo] [--caches cache_names]" + U.nl() +
+            U.nl() +
+            "  path_to_files - Performance statistics file or files directory." + U.nl() +
+            "  out_file      - Output file." + U.nl() +
+            "  op_types      - Comma separated list of operation types to filter the output." + U.nl() +
+            "  from          - The minimum operation start time to filter the output." + U.nl() +
+            "  to            - The maximum operation start time to filter the output." + U.nl() +
+            "  cache_names   - Comma separated list of cache names to filter the output." + U.nl() +
+            U.nl() +
+            "Times must be specified in the Unix time format in milliseconds." + U.nl() +
+            "List of operation types: " + ops + '.');
+
+        System.exit(0);
+    }
+
+    /** @param params Validates parameters. */
+    private static void validateParameters(Parameters params) {
+        File statFiles = new File(params.statFileOrDir);

Review comment:
       Fixed.

##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/PerformanceStatisticsPrinter.java
##########
@@ -0,0 +1,232 @@
+/*
+ * 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.performancestatistics;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+import java.util.BitSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.internal.performancestatistics.handlers.PrintHandler;
+import org.apache.ignite.internal.processors.performancestatistics.FilePerformanceStatisticsReader;
+import org.apache.ignite.internal.processors.performancestatistics.OperationType;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
+import static java.util.Collections.singletonList;
+import static java.util.stream.Collectors.joining;
+
+/**
+ * Performance statistics printer.
+ */
+public class PerformanceStatisticsPrinter {
+    /**
+     * @param args Program arguments or '-h' to get usage help.
+     */
+    public static void main(String... args) throws Exception {
+        Parameters params = parseArguments(args);
+
+        validateParameters(params);
+
+        PrintStream ps = printStream(params.outFile);
+
+        try {
+            new FilePerformanceStatisticsReader(
+                new PrintHandler(ps, params.ops, params.from, params.to,params.cacheIds))
+                .read(singletonList(new File(params.statFileOrDir)));
+        }
+        finally {
+            if (params.outFile != null)
+                ps.close();
+        }
+    }
+
+    /**
+     * Parses arguments or print help.
+     *
+     * @param args Arguments to parse.
+     * @return Program arguments.
+     */
+    private static Parameters parseArguments(String[] args) {
+        if (args == null || args.length == 0 || "--help".equalsIgnoreCase(args[0]) || "-h".equalsIgnoreCase(args[0]))
+            printHelp();
+
+        Parameters params = new Parameters();
+
+        Iterator<String> iter = Arrays.asList(args).iterator();
+
+        params.statFileOrDir = iter.next();
+
+        while (iter.hasNext()) {
+            String arg = iter.next();
+
+            if ("--out".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected output file name");
+
+                params.outFile = iter.next();
+            }
+            else if ("--ops".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected operation types");
+
+                String[] ops = iter.next().split(",");
+
+                A.ensure(ops.length > 0, "Expected at least one operation");
+
+                params.ops = new BitSet();
+
+                for (String op : ops) {
+                    OperationType opType = enumIgnoreCase(op, OperationType.class);
+
+                    A.ensure(opType != null, "Unknown operation type [op=" + op + ']');
+
+                    params.ops.set(opType.id());
+                }
+            }
+            else if ("--from".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected time from");
+
+                params.from = Long.parseLong(iter.next());
+            }
+            else if ("--to".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected time to");
+
+                params.to = Long.parseLong(iter.next());
+            }
+            else if ("--caches".equalsIgnoreCase(arg)) {
+                A.ensure(iter.hasNext(), "Expected cache names");
+
+                String[] caches = iter.next().split(",");
+
+                A.ensure(caches.length > 0, "Expected at least one cache name");
+
+                params.cacheIds = Arrays.stream(caches).map(CU::cacheId).collect(Collectors.toSet());
+            }
+            else
+                throw new IllegalArgumentException("Unknown command: " + arg);
+        }
+
+        return params;
+    }
+
+    /** Prints help. */
+    private static void printHelp() {
+        String ops = Arrays.stream(OperationType.values()).map(Enum::toString).collect(joining(", "));
+
+        System.out.println("The script is used to print performance statistics files to the console or file." +
+            U.nl() + U.nl() +
+            "Usage: print-statistics.sh path_to_files [--out out_file] [--ops op_types] " +
+            "[--from startTimeFrom] [--to startTimeTo] [--caches cache_names]" + U.nl() +
+            U.nl() +
+            "  path_to_files - Performance statistics file or files directory." + U.nl() +
+            "  out_file      - Output file." + U.nl() +
+            "  op_types      - Comma separated list of operation types to filter the output." + U.nl() +
+            "  from          - The minimum operation start time to filter the output." + U.nl() +
+            "  to            - The maximum operation start time to filter the output." + U.nl() +
+            "  cache_names   - Comma separated list of cache names to filter the output." + U.nl() +
+            U.nl() +
+            "Times must be specified in the Unix time format in milliseconds." + U.nl() +
+            "List of operation types: " + ops + '.');
+
+        System.exit(0);
+    }
+
+    /** @param params Validates parameters. */
+    private static void validateParameters(Parameters params) {
+        File statFiles = new File(params.statFileOrDir);
+
+        A.ensure(statFiles.exists(), "Performance statistics file or files directory does not exists");
+
+        if (params.outFile != null) {
+            File out = new File(params.outFile);
+
+            try {
+                boolean created = out.createNewFile();
+
+                if (!created) {

Review comment:
       Done.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite-extensions] nizhikov commented on a change in pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40#discussion_r565244015



##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/util/Utils.java
##########
@@ -51,4 +56,43 @@ public static ArrayNode createArrayIfAbsent(String val, ObjectNode json) {
 
         return node;
     }
+
+    /**
+     * Prints JSON-escaped string to the stream.
+     *
+     * @param ps Print stream to write to.
+     * @param str String to print.

Review comment:
       Please, add @see annotation to the base method for this.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [ignite-extensions] nizhikov commented on a change in pull request #40: IGNITE-13888 Provide the utility to output performance statistics operations to the console

Posted by GitBox <gi...@apache.org>.
nizhikov commented on a change in pull request #40:
URL: https://github.com/apache/ignite-extensions/pull/40#discussion_r565149986



##########
File path: modules/performance-statistics-ext/src/main/java/org/apache/ignite/internal/performancestatistics/handlers/PrintHandler.java
##########
@@ -0,0 +1,256 @@
+/*
+ * 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.performancestatistics.handlers;
+
+import java.io.PrintStream;
+import java.util.BitSet;
+import java.util.Set;
+import java.util.UUID;
+import com.fasterxml.jackson.databind.node.TextNode;
+import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
+import org.apache.ignite.internal.processors.performancestatistics.OperationType;
+import org.apache.ignite.internal.processors.performancestatistics.PerformanceStatisticsHandler;
+import org.apache.ignite.internal.util.GridIntIterator;
+import org.apache.ignite.internal.util.GridIntList;
+import org.apache.ignite.lang.IgniteUuid;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.CACHE_START;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.JOB;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.QUERY;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.QUERY_READS;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TASK;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TX_COMMIT;
+import static org.apache.ignite.internal.processors.performancestatistics.OperationType.TX_ROLLBACK;
+
+/**
+ * Handler to print performance statistics operations.
+ */
+public class PrintHandler implements PerformanceStatisticsHandler {
+    /** Print stream. */
+    private final PrintStream ps;
+
+    /** Operation types. */
+    @Nullable private final BitSet ops;
+
+    /** Start time from. */
+    private final long from;
+
+    /** Start time to. */
+    private final long to;
+
+    /** Cache identifiers to filter the output. */
+    @Nullable private final Set<Integer> cacheIds;
+
+    /**
+     * @param ps Print stream.
+     * @param ops Set of operations to print.
+     * @param from The minimum operation start time to filter the output.
+     * @param to The maximum operation start time to filter the output.
+     * @param cacheIds Cache identifiers to filter the output.
+     */
+    public PrintHandler(PrintStream ps, @Nullable BitSet ops, long from, long to, @Nullable Set<Integer> cacheIds) {
+        this.ps = ps;
+        this.ops = ops;
+        this.from = from;
+        this.to = to;
+        this.cacheIds = cacheIds;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void cacheStart(UUID nodeId, int cacheId, String name) {
+        if (skip(CACHE_START, cacheId))
+            return;
+
+        ps.print("{\"op\":\"" + CACHE_START);
+        ps.print("\",\"nodeId\":\"");
+        ps.print(nodeId);
+        ps.print("\",\"cacheId\":");
+        ps.print(cacheId);
+        ps.print(",\"name\":");
+        ps.print(new TextNode(name));

Review comment:
       We should avoid the creation of intermediate objects just to create an escaped strings.




----------------------------------------------------------------
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:
users@infra.apache.org