13 #ifndef __STOUT_OS_OSX_HPP__ 14 #define __STOUT_OS_OSX_HPP__ 18 #error "stout/os/osx.hpp is only available on OSX systems." 23 #include <sys/sysctl.h> 24 #include <sys/types.h> 48 return Error(
"Failed to get process via sysctl: " + processes.
error());
49 }
else if (processes->size() != 1) {
78 int argc = *((
int*) args->data());
94 std::vector<std::string> tokens =
97 if (!tokens.empty()) {
102 }
else if (argc > 1) {
109 tokens.erase(tokens.begin());
115 if (static_cast<size_t>(argc) <= tokens.size()) {
116 tokens.erase(tokens.begin() + argc, tokens.end());
120 if (tokens.size() > 0) {
140 int size = proc_pidinfo(pid, PROC_PIDTASKINFO, 0, &task,
sizeof(task));
144 int session = getsid(pid);
146 if (size !=
sizeof(task)) {
147 return Process(process.kp_proc.p_pid,
148 process.kp_eproc.e_ppid,
149 process.kp_eproc.e_pgid,
154 command.
getOrElse(std::string(process.kp_proc.p_comm)),
155 process.kp_proc.p_stat & SZOMB);
157 return Process(process.kp_proc.p_pid,
158 process.kp_eproc.e_ppid,
159 process.kp_eproc.e_pgid,
161 Bytes(task.pti_resident_size),
164 command.
getOrElse(std::string(process.kp_proc.p_comm)),
165 process.kp_proc.p_stat & SZOMB);
181 if (processes.isError()) {
182 return Error(processes.error());
185 std::set<pid_t> result;
186 foreach (
const kinfo_proc& process, processes.get()) {
187 result.insert(process.kp_proc.p_pid);
203 memory.total =
Bytes(totalMemory.
get());
209 unsigned int freeCount;
210 size_t length =
sizeof(freeCount);
213 "vm.page_free_count",
220 memory.free =
Bytes(freeCount * pageSize);
222 struct xsw_usage
usage;
223 length =
sizeof(
struct xsw_usage);
232 memory.totalSwap =
Bytes(
usage.xsu_total * pageSize);
233 memory.freeSwap =
Bytes(
usage.xsu_avail * pageSize);
240 #endif // __STOUT_OS_OSX_HPP__ Definition: errorbase.hpp:36
T getOrElse(U &&u) const &
Definition: option.hpp:133
Try< Bytes > size(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:130
T & get()&
Definition: try.hpp:80
std::stringstream & join(std::stringstream &stream, const std::string &separator, T &&...args)
Definition: strings.hpp:307
Try< std::list< Process > > processes()
Definition: os.hpp:184
size_t pagesize()
Definition: pagesize.hpp:24
Definition: errorbase.hpp:50
Definition: posix_signalhandler.hpp:23
Try< std::string > string() const
Definition: sysctl.hpp:188
DWORD pid_t
Definition: windows.hpp:181
std::vector< std::string > tokenize(const std::string &s, const std::string &delims, const Option< size_t > &maxTokens=None())
Definition: strings.hpp:139
Try< ResourceStatistics > usage(pid_t pid, bool mem=true, bool cpus=true)
Table table(const Option< size_t > &length=None()) const
Definition: sysctl.hpp:229
bool isSome() const
Definition: try.hpp:77
Integer integer() const
Definition: sysctl.hpp:182
static Try error(const E &e)
Definition: try.hpp:43
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
bool isError() const
Definition: try.hpp:78
Definition: executor.hpp:48
Definition: sysctl.hpp:59
Definition: duration.hpp:165
Try< Memory > memory()
Definition: freebsd.hpp:78
Try< std::set< pid_t > > pids()
Definition: freebsd.hpp:62