• 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   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_; }
threads()44   int threads() const { return threads_; }
45 
set_pid(pid_t pid)46   void set_pid(pid_t pid) { pid_ = pid; }
47 
48 private:
49   std::string comm_;
50   uid_t uid_;
51   gid_t gid_;
52   pid_t pid_;
53   pid_t ppid_;
54 
55   uint64_t cpu_delay_count_;
56   uint64_t cpu_delay_ns_;
57 
58   uint64_t block_io_delay_count_;
59   uint64_t block_io_delay_ns_;
60 
61   uint64_t swap_in_delay_count_;
62   uint64_t swap_in_delay_ns_;
63 
64   uint64_t reclaim_delay_count_;
65   uint64_t reclaim_delay_ns_;
66 
67   uint64_t total_delay_ns_;
68 
69   uint64_t cpu_time_real_;
70   uint64_t cpu_time_virtual_;
71 
72   uint64_t read_bytes_;
73   uint64_t write_bytes_;
74   uint64_t read_write_bytes_;
75   uint64_t cancelled_write_bytes_;
76 
77   int threads_;
78 };
79 
80 class TaskstatsSocket {
81 public:
82   TaskstatsSocket();
83   bool Open();
84   void Close();
85 
86   bool GetPidStats(int, TaskStatistics&);
87   bool GetTgidStats(int, TaskStatistics&);
88 private:
89   bool GetStats(int, int, TaskStatistics& stats);
90   std::unique_ptr<nl_sock, void(*)(nl_sock*)> nl_;
91   int family_id_;
92 };
93 
94 #endif // _IOTOP_TASKSTATS_H
95