• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2015 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <memory>
16 #include <string>
17 
18 #include <stdint.h>
19 
20 #ifndef _IOTOP_TASKSTATS_H
21 #define _IOTOP_TASKSTATS_H
22 
23 struct nl_sock;
24 struct taskstats;
25 
26 class TaskStatistics {
27 public:
28   explicit TaskStatistics(const taskstats&);
29   TaskStatistics() = default;
30   TaskStatistics(const TaskStatistics&) = default;
31   void AddPidToTgid(const TaskStatistics&);
32   TaskStatistics Update(const TaskStatistics&);
33 
pid()34   pid_t pid() const { return pid_; }
comm()35   const std::string& comm() const { return comm_; }
read()36   uint64_t read() const { return read_bytes_; }
write()37   uint64_t write() const { return write_bytes_; }
read_write()38   uint64_t read_write() const { return read_write_bytes_; }
delay_io()39   uint64_t delay_io() const { return block_io_delay_ns_; }
delay_swap()40   uint64_t delay_swap() const { return swap_in_delay_ns_; }
delay_sched()41   uint64_t delay_sched() const { return cpu_delay_ns_; }
delay_mem()42   uint64_t delay_mem() const { return reclaim_delay_ns_; }
delay_total()43   uint64_t delay_total() const { return total_delay_ns_; }
majflt()44   uint64_t majflt() const { return majflt_; }
minflt()45   uint64_t minflt() const { return minflt_; }
faults()46   uint64_t faults() const { return majflt_ + minflt_; }
threads()47   int threads() const { return threads_; }
48 
set_pid(pid_t pid)49   void set_pid(pid_t pid) { pid_ = pid; }
50 
51 private:
52   std::string comm_;
53   uid_t uid_;
54   gid_t gid_;
55   pid_t pid_;
56   pid_t ppid_;
57 
58   uint64_t cpu_delay_count_;
59   uint64_t cpu_delay_ns_;
60 
61   uint64_t block_io_delay_count_;
62   uint64_t block_io_delay_ns_;
63 
64   uint64_t swap_in_delay_count_;
65   uint64_t swap_in_delay_ns_;
66 
67   uint64_t reclaim_delay_count_;
68   uint64_t reclaim_delay_ns_;
69 
70   uint64_t total_delay_ns_;
71 
72   uint64_t cpu_time_real_;
73   uint64_t cpu_time_virtual_;
74 
75   uint64_t majflt_;
76   uint64_t minflt_;
77 
78   uint64_t read_bytes_;
79   uint64_t write_bytes_;
80   uint64_t read_write_bytes_;
81   uint64_t cancelled_write_bytes_;
82 
83   int threads_;
84 };
85 
86 class TaskstatsSocket {
87 public:
88   TaskstatsSocket();
89   bool Open();
90   void Close();
91 
92   bool GetPidStats(int, TaskStatistics&);
93   bool GetTgidStats(int, TaskStatistics&);
94 private:
95   bool GetStats(int, int, TaskStatistics& stats);
96   std::unique_ptr<nl_sock, void(*)(nl_sock*)> nl_;
97   int family_id_;
98 };
99 
100 #endif // _IOTOP_TASKSTATS_H
101