File: task.h

package info (click to toggle)
android-platform-tools 34.0.5-12
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 150,900 kB
  • sloc: cpp: 805,786; java: 293,500; ansic: 128,288; xml: 127,491; python: 41,481; sh: 14,245; javascript: 9,665; cs: 3,846; asm: 2,049; makefile: 1,917; yacc: 440; awk: 368; ruby: 183; sql: 140; perl: 88; lex: 67
file content (83 lines) | stat: -rw-r--r-- 2,290 bytes parent folder | download | duplicates (5)
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
#ifndef ANDROID_DVR_PERFORMANCED_TASK_H_
#define ANDROID_DVR_PERFORMANCED_TASK_H_

#include <sys/types.h>

#include <array>
#include <cstdio>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include <android-base/unique_fd.h>

#include "unique_file.h"

namespace android {
namespace dvr {

// Task provides access to task-related information from the procfs
// pseudo-filesystem.
class Task {
 public:
  explicit Task(pid_t task_id);

  bool IsValid() const { return task_fd_.get() >= 0; }
  explicit operator bool() const { return IsValid(); }

  pid_t task_id() const { return task_id_; }
  std::string name() const { return name_; }
  pid_t thread_group_id() const { return thread_group_id_; }
  pid_t parent_process_id() const { return parent_process_id_; }
  size_t thread_count() const { return thread_count_; }
  uint32_t cpus_allowed_mask() const { return cpus_allowed_mask_; }
  const std::string& cpus_allowed_list() const { return cpus_allowed_list_; }
  const std::array<int, 4>& user_id() const { return user_id_; }
  const std::array<int, 4>& group_id() const { return group_id_; }

  // Indices into user and group id arrays.
  enum {
    kUidReal = 0,
    kUidEffective,
    kUidSavedSet,
    kUidFilesystem,
  };

  std::string GetCpuSetPath() const;

 private:
  pid_t task_id_;
  base::unique_fd task_fd_;

  // Fields read from /proc/<task_id_>/status.
  std::string name_;
  pid_t thread_group_id_;
  pid_t parent_process_id_;
  std::array<int, 4> user_id_;
  std::array<int, 4> group_id_;
  size_t thread_count_;
  uint32_t cpus_allowed_mask_;
  std::string cpus_allowed_list_;

  // Opens the file /proc/<task_id_>/|name| and returns the open file
  // descriptor.
  base::unique_fd OpenTaskFile(const std::string& name) const;

  // Similar to OpenTaskFile() but returns a file pointer.
  UniqueFile OpenTaskFilePointer(const std::string& name) const;

  // Reads the field named |field| from /proc/<task_id_>/status.
  std::string GetStatusField(const std::string& field) const;

  // Reads a subset of the fields in /proc/<task_id_>/status.
  void ReadStatusFields();

  Task(const Task&) = delete;
  void operator=(const Task&) = delete;
};

}  // namespace dvr
}  // namespace android

#endif  // ANDROID_DVR_PERFORMANCED_TASK_H_