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