blob: bbf7e9e22e8ad9cf18362b9b84ba07271cb730ef [file] [log] [blame]
Colin Cross646d0012015-09-03 17:56:39 -07001// 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
23struct nl_sock;
24struct taskstats;
25
26class TaskStatistics {
27public:
Chih-Hung Hsieh90653802016-08-02 11:19:23 -070028 explicit TaskStatistics(const taskstats&);
Colin Cross646d0012015-09-03 17:56:39 -070029 TaskStatistics() = default;
30 TaskStatistics(const TaskStatistics&) = default;
31 void AddPidToTgid(const TaskStatistics&);
32 TaskStatistics Update(const TaskStatistics&);
33
34 pid_t pid() const { return pid_; }
35 const std::string& comm() const { return comm_; }
36 uint64_t read() const { return read_bytes_; }
37 uint64_t write() const { return write_bytes_; }
38 uint64_t read_write() const { return read_write_bytes_; }
39 uint64_t delay_io() const { return block_io_delay_ns_; }
40 uint64_t delay_swap() const { return swap_in_delay_ns_; }
41 uint64_t delay_sched() const { return cpu_delay_ns_; }
42 uint64_t delay_mem() const { return reclaim_delay_ns_; }
43 uint64_t delay_total() const { return total_delay_ns_; }
44 int threads() const { return threads_; }
45
46 void set_pid(pid_t pid) { pid_ = pid; }
47
48private:
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
80class TaskstatsSocket {
81public:
82 TaskstatsSocket();
83 bool Open();
84 void Close();
85
86 bool GetPidStats(int, TaskStatistics&);
87 bool GetTgidStats(int, TaskStatistics&);
88private:
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