LinuxProcData.h
Go to the documentation of this file.
1 #ifndef art_Utilities_LinuxProcData_h
2 #define art_Utilities_LinuxProcData_h
3 
4 //===================================================================
5 //
6 // LinuxProcData
7 //
8 //-----------------------------------------------
9 //
10 // This is a helper class for storing information that is available
11 // via 'cat /proc/PID/stat'. As of SLF6.5 (Ramsey), the values from
12 // that command correspond to (see 'man 5 proc'):
13 //
14 // Property type C++ type
15 // ===============================================
16 // 1. pid %d int
17 // 2. comm %s char[400]
18 // 3. state %c char
19 // 4. ppid %d int
20 // 5. pgrp %d int
21 // 6. session %d int
22 // 7. tty_nr %d int
23 // 8. tpgid %d int
24 // 9. flags %u unsigned
25 // 10. minflt %lu unsigned long
26 // 11. cminflt %lu unsigned long
27 // 12. majflt %lu unsigned long
28 // 13. cmajflt %lu unsigned long
29 // 14. utime %lu unsigned long
30 // 15. stime %lu unsigned long
31 // 16. cutime %ld long
32 // 17. cstime %ld long
33 // 18. priority %ld long
34 // 19. nice %ld long
35 // 20. num_threads %ld long
36 // 21. itrealvalue %ld long
37 // 22. starttime %llu unsigned long long
38 // 23. vsize %lu unsigned long
39 // 24. rss %ld long
40 // 25. rsslim %lu unsigned long
41 // 26. startcode %lu unsigned long
42 // 27. endcode %lu unsigned long
43 // 28. startstack %lu unsigned long
44 // 29. kstkesp %lu unsigned long
45 // 30. kstkeip %lu unsigned long
46 // 31. signal %lu unsigned long
47 // 32. blocked %lu unsigned long
48 // 33. sigignore %lu unsigned long
49 // 34. sigcatch %lu unsigned long
50 // 35. wchan %lu unsigned long
51 // 36. nswap %lu unsigned long
52 // 37. cnswap %lu unsigned long
53 // 38. exit_signal %d int
54 // 39. processor %d int
55 // 40. rt_priority %u unsigned
56 // 41. policy %u unsigned
57 // 42. delayacct_blkio_ticks %llu unsigned long long
58 // 43. guest_time %lu unsigned long
59 // 44. cguest_time %ld long
60 //
61 // Currently, we are interested only in 'vsize' and 'rss'.
62 //
63 //===================================================================
64 
65 #include <sstream>
66 #include <tuple>
67 #include <type_traits>
68 
69 namespace art {
70 
71  struct LinuxProcData {
72 
73  // supported procfs types
75 
76  // aliases
77  struct proc_type {};
78  struct vsize_t : proc_type {
79  using value_type = unsigned long;
80  explicit vsize_t(value_type const v) : value{v} {}
82  };
83 
84  struct rss_t : proc_type {
85  using value_type = long;
86  explicit rss_t(value_type const v) : value{v} {}
88  };
89 
90  using proc_tuple = std::tuple<vsize_t, rss_t>;
91 
92  static auto
94  rss_t::value_type const rss = {})
95  {
96  return proc_tuple{vsize_t{vsize}, rss_t{rss}};
97  }
98 
99  template <typename T>
102  {
103  // Info from proc is in bytes; convert to base-10 MB.
104  return std::get<T>(t).value / MB;
105  }
106 
107  // constants
108  static constexpr double KB{1000.};
109  static constexpr double KiB{1.024 * KB};
110  static constexpr double MB{KB * KB};
111  static constexpr double MiB{KiB * KiB};
112  };
113 
114 } // namespace art
115 #endif /* art_Utilities_LinuxProcData_h */
116 
117 // Local variables:
118 // mode:c++
119 // End:
vsize_t(value_type const v)
Definition: LinuxProcData.h:80
static std::enable_if_t< std::is_base_of< proc_type, T >::value, double > getValueInMB(proc_tuple const &t)
static constexpr double KiB
static constexpr double KB
static constexpr double MiB
std::tuple< vsize_t, rss_t > proc_tuple
Definition: LinuxProcData.h:90
static constexpr double MB
rss_t(value_type const v)
Definition: LinuxProcData.h:86
static auto make_proc_tuple(vsize_t::value_type const vsize={}, rss_t::value_type const rss={})
Definition: LinuxProcData.h:93