1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
// Copyright (C) 2015 The Android Open Source Project
//
// Licensed 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.
#include <memory>
#include <string>
#include <stdint.h>
#ifndef _IOTOP_TASKSTATS_H
#define _IOTOP_TASKSTATS_H
struct nl_sock;
struct taskstats;
class TaskStatistics {
public:
explicit TaskStatistics(const taskstats&);
TaskStatistics() = default;
TaskStatistics(const TaskStatistics&) = default;
void AddPidToTgid(const TaskStatistics&);
TaskStatistics Update(const TaskStatistics&);
pid_t pid() const { return pid_; }
const std::string& comm() const { return comm_; }
uint64_t read() const { return read_bytes_; }
uint64_t write() const { return write_bytes_; }
uint64_t read_write() const { return read_write_bytes_; }
uint64_t delay_io() const { return block_io_delay_ns_; }
uint64_t delay_swap() const { return swap_in_delay_ns_; }
uint64_t delay_sched() const { return cpu_delay_ns_; }
uint64_t delay_mem() const { return reclaim_delay_ns_; }
uint64_t delay_total() const { return total_delay_ns_; }
uint64_t majflt() const { return majflt_; }
uint64_t minflt() const { return minflt_; }
uint64_t faults() const { return majflt_ + minflt_; }
int threads() const { return threads_; }
void set_pid(pid_t pid) { pid_ = pid; }
private:
std::string comm_;
uid_t uid_;
gid_t gid_;
pid_t pid_;
pid_t ppid_;
uint64_t cpu_delay_count_;
uint64_t cpu_delay_ns_;
uint64_t block_io_delay_count_;
uint64_t block_io_delay_ns_;
uint64_t swap_in_delay_count_;
uint64_t swap_in_delay_ns_;
uint64_t reclaim_delay_count_;
uint64_t reclaim_delay_ns_;
uint64_t total_delay_ns_;
uint64_t cpu_time_real_;
uint64_t cpu_time_virtual_;
uint64_t majflt_;
uint64_t minflt_;
uint64_t read_bytes_;
uint64_t write_bytes_;
uint64_t read_write_bytes_;
uint64_t cancelled_write_bytes_;
int threads_;
};
class TaskstatsSocket {
public:
TaskstatsSocket();
bool Open();
void Close();
bool GetPidStats(int, TaskStatistics&);
bool GetTgidStats(int, TaskStatistics&);
private:
bool GetStats(int, int, TaskStatistics& stats);
std::unique_ptr<nl_sock, void(*)(nl_sock*)> nl_;
int family_id_;
};
#endif // _IOTOP_TASKSTATS_H
|