2 * Copyright 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __MEMTRACK_H__
18 #define __MEMTRACK_H__
20 #include <sys/types.h>
26 #define DEFAULT_SLEEP_DELAY_SECONDS 5
27 #define NS_PER_SEC 1000000000LL
31 FileData(char *filename, char *buffer, size_t buffer_len);
34 // Get the PSS information from the file data. If there are no more
35 // PSS values to be found, return false.
36 bool getPss(size_t *pss);
38 // Check if there is at least bytes available in the file data.
39 bool isAvail(size_t bytes);
61 std::vector<int> pids;
63 typedef std::map<std::string, process_info_t> processes_t;
68 std::vector<int> pids;
70 typedef std::map<std::string, cur_process_info_t> cur_processes_t;
77 // Get the information about a single process.
78 bool getInformation(int pid, char *pid_str, size_t pid_str_len);
80 // Scan all of the running processes.
83 // Dump the information about all of the processes in the system to the log.
87 static const size_t kBufferLen = 4096;
88 static const size_t kCmdNameLen = 1024;
90 static const char *kProc;
91 static const size_t kProcLen = 6;
93 static const char *kCmdline;
94 static const size_t kCmdlineLen = 9; // Includes \0 at end of string.
96 static const char *kSmaps;
97 static const size_t kSmapsLen = 7; // Includes \0 at end of string.
99 static const char *kStatus;
100 static const size_t kStatusLen = 8; // Includes \0 at end of string.
102 static const size_t kInitialEntries = 1000;
104 char proc_file_[PATH_MAX];
105 char buffer_[kBufferLen];
107 char cmd_name_[kCmdNameLen];
109 // Minimize a need for a lot of allocations by keeping our maps and
110 // lists in this object.
112 cur_processes_t cur_;
113 std::vector<const process_info_t *> list_;
115 // Compute a running average.
116 static inline void computeAvg(double *running_avg, size_t cur_avg,
117 size_t num_samples) {
118 *running_avg = (*running_avg/(num_samples+1))*num_samples
119 + (double)cur_avg/(num_samples+1);
123 #endif // __MEMTRACK_H__