14#include "llvm/ADT/ScopeExit.h"
15#include "llvm/Support/Error.h"
40 fds.fd = open(
"/proc/pressure/memory", O_RDWR |
O_NONBLOCK);
45 auto cleanup = llvm::make_scope_exit([&]() { close(fds.fd); });
48 const char trig[] =
"some 50000 2000000";
49 if (write(fds.fd, trig, strlen(trig) + 1) < 0)
55 if (fds.revents & POLLERR)
57 if (fds.revents & POLLPRI)
64 HANDLE low_memory_notification =
65 CreateMemoryResourceNotification(LowMemoryResourceNotification);
66 if (!low_memory_notification)
70 if (WaitForSingleObject(low_memory_notification,
g_timeout) ==
81 llvm::Expected<HostThread> memory_monitor_thread =
84 if (memory_monitor_thread) {
88 "failed to launch host thread: {0}");
105#if !defined(__APPLE__)
107 return std::make_unique<MemoryMonitorPoll>(callback);
#define LLDB_LOG_ERROR(log, error,...)
MemoryMonitor(Callback callback)
std::atomic< bool > m_done
lldb::thread_result_t MonitorThread()
static constexpr uint32_t g_timeout
HostThread m_memory_monitor_thread
MemoryMonitor(Callback callback)
static std::unique_ptr< MemoryMonitor > Create(Callback callback)
std::function< void()> Callback
static llvm::Expected< HostThread > LaunchThread(llvm::StringRef name, std::function< lldb::thread_result_t()> thread_function, size_t min_stack_byte_size=0)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.