OSDN Git Service

Merge "Inferno: A framegrapher based on simpleperf"
[android-x86/system-extras.git] / iotop / iotop.cpp
index 645490d..e2582e8 100644 (file)
@@ -22,7 +22,7 @@
 #include <unordered_map>
 #include <vector>
 
-#include <base/logging.h>
+#include <android-base/logging.h>
 
 #include "tasklist.h"
 #include "taskstats.h"
@@ -53,7 +53,7 @@ static void usage(char* myname) {
 }
 
 using Sorter = std::function<void(std::vector<TaskStatistics>&)>;
-static Sorter GetSorter(const std::string field) {
+static Sorter GetSorter(const std::string& field) {
   // Generic comparator
   static auto comparator = [](auto& lhs, auto& rhs, auto field, bool ascending) -> bool {
     auto a = (lhs.*field)();
@@ -247,20 +247,23 @@ int main(int argc, char* argv[]) {
         total_write += statistics.write();
         total_read_write += statistics.read_write();
 
-        if (n > 0) {
+        if (n == 0) {
+          continue;
+        } else if (n > 0) {
           n--;
-          printf("%6d %-16s %6" PRIu64 " %6" PRIu64 " %6" PRIu64 " %5.2f%% %5.2f%% %5.2f%% %5.2f%% %5.2f%%\n",
-              statistics.pid(),
-              statistics.comm().c_str(),
-              BytesToKB(statistics.read()) / delay_div,
-              BytesToKB(statistics.write()) / delay_div,
-              BytesToKB(statistics.read_write()) / delay_div,
-              TimeToTgidPercent(statistics.delay_io(), delay, statistics),
-              TimeToTgidPercent(statistics.delay_swap(), delay, statistics),
-              TimeToTgidPercent(statistics.delay_sched(), delay, statistics),
-              TimeToTgidPercent(statistics.delay_mem(), delay, statistics),
-              TimeToTgidPercent(statistics.delay_total(), delay, statistics));
         }
+
+        printf("%6d %-16s %6" PRIu64 " %6" PRIu64 " %6" PRIu64 " %5.2f%% %5.2f%% %5.2f%% %5.2f%% %5.2f%%\n",
+            statistics.pid(),
+            statistics.comm().c_str(),
+            BytesToKB(statistics.read()) / delay_div,
+            BytesToKB(statistics.write()) / delay_div,
+            BytesToKB(statistics.read_write()) / delay_div,
+            TimeToTgidPercent(statistics.delay_io(), delay, statistics),
+            TimeToTgidPercent(statistics.delay_swap(), delay, statistics),
+            TimeToTgidPercent(statistics.delay_sched(), delay, statistics),
+            TimeToTgidPercent(statistics.delay_mem(), delay, statistics),
+            TimeToTgidPercent(statistics.delay_total(), delay, statistics));
       }
       printf("%6s %-16s %6" PRIu64 " %6" PRIu64 " %6" PRIu64 "\n", "", "TOTAL",
           BytesToKB(total_read) / delay_div,