exceptionfactory commented on code in PR #6156:
URL: https://github.com/apache/nifi/pull/6156#discussion_r910370087


##########
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/diagnostics/bootstrap/tasks/ProcessorTimingDiagnosticTask.java:
##########
@@ -0,0 +1,228 @@
+/*
+ * 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.nifi.diagnostics.bootstrap.tasks;
+
+import org.apache.nifi.controller.ProcessorNode;
+import org.apache.nifi.controller.flow.FlowManager;
+import org.apache.nifi.controller.repository.FlowFileEvent;
+import org.apache.nifi.controller.repository.FlowFileEventRepository;
+import org.apache.nifi.controller.repository.RepositoryStatusReport;
+import org.apache.nifi.diagnostics.DiagnosticTask;
+import org.apache.nifi.diagnostics.DiagnosticsDumpElement;
+import org.apache.nifi.diagnostics.StandardDiagnosticsDumpElement;
+import org.apache.nifi.processor.DataUnit;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+
+public class ProcessorTimingDiagnosticTask implements DiagnosticTask {
+    private final FlowFileEventRepository eventRepo;
+    private final FlowManager flowManager;
+
+    //                                                     | Proc ID    | Proc 
Name  | Proc Type  | Group Name | Proc Secs | CPU Secs  | %CPU used by Proc |
+    private static final String PROCESSOR_TIMING_FORMAT = "| %1$-36.36s | 
%2$-36.36s | %3$-36.36s | %4$-36.36s | %5$15.15s | %6$27.27s | %7$25.25s | " +
+    //   Read Secs | Write Secs| Commit Sec | GC millis | MB Read    | MB 
Write   |
+        "%8$16.16s | %9$16.16s | %10$20.20s | %11$13.13s | %12$11.11s | 
%13$11.11s |";
+
+    public ProcessorTimingDiagnosticTask(final FlowFileEventRepository 
flowFileEventRepository, final FlowManager flowManager) {
+        this.eventRepo = flowFileEventRepository;
+        this.flowManager = flowManager;
+    }
+
+    @Override
+    public DiagnosticsDumpElement captureDump(final boolean verbose) {
+        final List<String> details = new ArrayList<>();
+
+        final RepositoryStatusReport statusReport = 
eventRepo.reportTransferEvents(System.currentTimeMillis());
+        final Map<String, FlowFileEvent> eventsByComponentId = 
statusReport.getReportEntries();
+
+        final List<ProcessorTiming> timings = new ArrayList<>();
+        eventsByComponentId.entrySet().stream()
+            .map(entry -> getTiming(entry.getKey(), entry.getValue()))
+            .filter(Objects::nonNull)
+            .forEach(timings::add); // create ArrayList and add here instead 
of .collect(toList()) because arraylist allows us to sort
+
+        // Sort based on the Processor CPU time, highest CPU usage first
+        
timings.sort(Comparator.comparing(ProcessorTiming::getCpuNanos).reversed());
+
+        final DecimalFormat dataSizeFormat = new DecimalFormat("#,###,###.##");
+        final DecimalFormat percentageFormat = new DecimalFormat("##.##");
+        final NumberFormat secondsFormat = NumberFormat.getInstance();
+
+        long totalCpuNanos = 0L;
+        long totalProcNanos = 0L;
+        long totalReadNanos = 0L;
+        long totalWriteNanos = 0L;
+        long totalSessionCommitNanos = 0L;
+        long totalBytesRead = 0L;
+        long totalBytesWritten = 0L;
+        long totalGcNanos = 0L;
+
+        // Tally totals for all timing elements
+        for (final ProcessorTiming timing : timings) {
+            totalCpuNanos += timing.getCpuNanos();
+            totalProcNanos += timing.getProcessingNanos();
+            totalReadNanos += timing.getReadNanos();
+            totalWriteNanos += timing.getWriteNanos();
+            totalSessionCommitNanos += timing.getSessionCommitNanos();
+            totalBytesRead += timing.getBytesRead();
+            totalBytesWritten += timing.getBytesWritten();
+            totalGcNanos += timing.getGarbageCollectionNanos();
+        }
+
+        if (totalCpuNanos < 1) {
+            details.add("No Processor Timing Diagnostic information has been 
gathered.");
+            return new StandardDiagnosticsDumpElement("Processor Timing 
Diagnostics (Stats over last 5 minutes)", details);
+        }
+
+        details.add(String.format(PROCESSOR_TIMING_FORMAT, "Processor ID", 
"Processor Name", "Processor Type", "Process Group Name", "Processing Secs",
+            "CPU Secs (% time using CPU)", "Pct CPU Time Used by Proc", "Disk 
Read Secs", "Disk Write Secs", "Session Commit Secs", "GC Millis", "MB Read", 
"MB Written"));

Review Comment:
   Understanding the need to balance readability with length, the current 
headers and column width produce very long lines in the diagnostic output, 
making it difficult to read without a very high resolution screen.
   
   What do you think about using shorter names for most of the numeric fields, 
and then condensing the column width for those fields? Even the `Processor 
Type` field could be shortened, but the biggest gain would be for the numeric 
columns.  Perhaps using acronyms that could be listed prior to the tabular 
output?
   
   ```
   PS = Processing Seconds
   CSP = CPU Seconds and percent time using CPU
   PCTP = Percent CPU time used by Processor
   DR = Disk Read Seconds
   DW = Disk Write Seconds
   SC = Session Commit Seconds
   GC = Garbage Collection Milliseconds
   MR = Megabytes Read
   MW = Megabytes Written
   ``` 
   



-- 
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.

To unsubscribe, e-mail: issues-unsubscr...@nifi.apache.org

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

Reply via email to