internal_aix.h 3.2 KB

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