internal_aix.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (c) 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // This file contains internal routines that are called by other files in
  5. // base/process/.
  6. #ifndef BASE_PROCESS_INTERNAL_AIX_H_
  7. #define BASE_PROCESS_INTERNAL_AIX_H_
  8. #include <stddef.h>
  9. #include <stdint.h>
  10. #include <unistd.h>
  11. #include "base/files/file_path.h"
  12. namespace base {
  13. namespace internalAIX {
  14. // "/proc"
  15. extern const char kProcDir[];
  16. // "psinfo"
  17. extern const char kStatFile[];
  18. // Returns a FilePath to "/proc/pid".
  19. base::FilePath GetProcPidDir(pid_t pid);
  20. // Take a /proc directory entry named |d_name|, and if it is the directory for
  21. // a process, convert it to a pid_t.
  22. // Returns 0 on failure.
  23. // e.g. /proc/self/ will return 0, whereas /proc/1234 will return 1234.
  24. pid_t ProcDirSlotToPid(const char* d_name);
  25. // Reads /proc/<pid>/stat into |buffer|. Returns true if the file can be read
  26. // and is non-empty.
  27. bool ReadProcStats(pid_t pid, std::string* buffer);
  28. // Takes |stats_data| and populates |proc_stats| with the values split by
  29. // spaces. Taking into account the 2nd field may, in itself, contain spaces.
  30. // Returns true if successful.
  31. bool ParseProcStats(const std::string& stats_data,
  32. std::vector<std::string>* proc_stats);
  33. // Fields from /proc/<pid>/psinfo.
  34. // If the ordering ever changes, carefully review functions that use these
  35. // values.
  36. // For AIX this is the bare minimum that we need. Most of the commented out
  37. // fields can still be extracted but currently none of these are required.
  38. enum ProcStatsFields {
  39. VM_COMM = 1, // Filename of executable, without parentheses.
  40. // VM_STATE = 2, // Letter indicating the state of the process.
  41. VM_PPID = 3, // PID of the parent.
  42. VM_PGRP = 4, // Process group id.
  43. // VM_UTIME = 13, // Time scheduled in user mode in clock ticks.
  44. // VM_STIME = 14, // Time scheduled in kernel mode in clock ticks.
  45. // VM_NUMTHREADS = 19, // Number of threads.
  46. // VM_STARTTIME = 21, // The time the process started in clock ticks.
  47. // VM_VSIZE = 22, // Virtual memory size in bytes.
  48. // VM_RSS = 23, // Resident Set Size in pages.
  49. };
  50. // Reads the |field_num|th field from |proc_stats|. Returns 0 on failure.
  51. // This version does not handle the first 3 values, since the first value is
  52. // simply |pid|, and the next two values are strings.
  53. int64_t GetProcStatsFieldAsInt64(const std::vector<std::string>& proc_stats,
  54. ProcStatsFields field_num);
  55. // Same as GetProcStatsFieldAsInt64(), but for size_t values.
  56. size_t GetProcStatsFieldAsSizeT(const std::vector<std::string>& proc_stats,
  57. ProcStatsFields field_num);
  58. // Convenience wrapper around GetProcStatsFieldAsInt64(), ParseProcStats() and
  59. // ReadProcStats(). See GetProcStatsFieldAsInt64() for details.
  60. int64_t ReadProcStatsAndGetFieldAsInt64(pid_t pid, ProcStatsFields field_num);
  61. // Same as ReadProcStatsAndGetFieldAsInt64() but for size_t values.
  62. size_t ReadProcStatsAndGetFieldAsSizeT(pid_t pid, ProcStatsFields field_num);
  63. } // namespace internal
  64. } // namespace base
  65. #endif // BASE_PROCESS_INTERNAL_AIX_H_