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