• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #pragma once
18 
19 #include <cstdint>
20 #include <map>
21 #include <ostream>
22 #include <set>
23 #include <string>
24 #include <vector>
25 
26 #include <meminfo/procmeminfo.h>
27 #include <processrecord.h>
28 
29 namespace android {
30 namespace smapinfo {
31 
32 // The user-specified order to sort processes.
33 enum class SortOrder { BY_PSS = 0, BY_RSS, BY_USS, BY_VSS, BY_SWAP, BY_OOMADJ };
34 
35 // Populates the input set with all pids present in the /proc directory. Only
36 // returns false if /proc could not be opened, returns true otherwise.
37 bool get_all_pids(std::set<pid_t>* pids);
38 
39 // Sorts processes provided in 'pids' by memory usage (or oomadj score) and
40 // prints them. Returns false in the following failure cases:
41 // a) system memory information could not be read,
42 // b) swap offsets could not be counted for some process,
43 // c) reset_wss is true but the working set for some process could not be reset.
44 bool run_procrank(uint64_t pgflags, uint64_t pgflags_mask, const std::set<pid_t>& pids,
45                   bool get_oomadj, bool get_wss, SortOrder sort_order, bool reverse_sort,
46                   std::map<pid_t, ProcessRecord>* processrecords_ptr, std::ostream& out,
47                   std::ostream& err);
48 
49 // Sorts libraries used by processes in 'pids' by memory usage and prints them.
50 // Returns false if any process's usage info could not be read.
51 bool run_librank(uint64_t pgflags, uint64_t pgflags_mask, const std::set<pid_t>& pids,
52                  const std::string& lib_prefix, bool all_libs,
53                  const std::vector<std::string>& excluded_libs, uint16_t mapflags_mask,
54                  android::meminfo::Format format, SortOrder sort_order, bool reverse_sort,
55                  std::map<pid_t, ProcessRecord>* processrecords_ptr, std::ostream& out,
56                  std::ostream& err);
57 
58 // Retrieves showmap information from the provided pid (or file) and prints it.
59 // Returns false if there are no maps associated with 'pid' or if the file
60 // denoted by 'filename' is malformed.
61 bool run_showmap(pid_t pid, const std::string& filename, bool terse, bool verbose, bool show_addr,
62                  bool quiet, android::meminfo::Format format,
63                  std::map<pid_t, ProcessRecord>* processrecords_ptr, std::ostream& out,
64                  std::ostream& err);
65 
66 // Runs procrank, librank, and showmap with a single read of smaps. Default
67 // arguments are used for all tools (except quiet output for showmap). This
68 // prints output that is specifically meant to be included in bug reports.
69 // Returns false only in the case that /proc could not be opened.
70 bool run_bugreport_procdump(std::ostream& out, std::ostream& err);
71 
72 }  // namespace smapinfo
73 }  // namespace android
74