|
25 | 25 |
|
26 | 26 | #include "config.h" |
27 | 27 | #include <wtf/MemoryPressureHandler.h> |
| 28 | +#include <gpumem.h> |
28 | 29 |
|
29 | 30 | #if OS(LINUX) |
30 | 31 | #include <unistd.h> |
@@ -91,21 +92,11 @@ static bool isWebProcess() |
91 | 92 |
|
92 | 93 | static size_t memoryFootprintVideo() |
93 | 94 | { |
94 | | - if (!isWebProcess() || s_GPUMemoryFile.isEmpty()) |
95 | | - return 0; |
96 | | - |
97 | | - FILE* file = fopen(s_GPUMemoryFile.utf8().data(), "r"); |
98 | | - if (!file) |
99 | | - return 0; |
100 | | - |
101 | | - char* buffer = nullptr; |
102 | | - size_t size = 0; |
| 95 | + uint32_t totalMemory = 0, availableMemory = 0; |
103 | 96 | size_t footprint = 0; |
104 | | - if (getline(&buffer, &size, file) != -1) |
105 | | - sscanf(buffer, "%u", &footprint); |
106 | | - |
107 | | - free(buffer); |
108 | | - fclose(file); |
| 97 | + if (gpumem_video_memory_total(&totalMemory) == 0 && gpumem_video_memory_available(0, &availableMemory) == 0) { |
| 98 | + footprint = (totalMemory - availableMemory); |
| 99 | + } |
109 | 100 |
|
110 | 101 | return footprint; |
111 | 102 | } |
@@ -322,7 +313,10 @@ void MemoryPressureHandler::measurementTimerFired() |
322 | 313 | static size_t footprintPeak = 0; |
323 | 314 | if (footprintPeak < footprint) |
324 | 315 | footprintPeak = footprint; |
325 | | - RELEASE_LOG(MemoryPressure, "Current memory footprint: %zu MB, peak: %zu MB, video footprint: %zu MB", footprint / MB, footprintPeak / MB, footprintVideo / MB); |
| 316 | + if (isWebProcess()) |
| 317 | + RELEASE_LOG(MemoryPressure, "Current memory footprint: %zu MB, peak: %zu MB, video footprint: %zu MB", footprint / MB, footprintPeak / MB, footprintVideo / MB); |
| 318 | + else |
| 319 | + RELEASE_LOG(MemoryPressure, "Current memory footprint: %zu MB, peak: %zu MB", footprint / MB, footprintPeak / MB); |
326 | 320 | auto killThreshold = thresholdForMemoryKill(MemoryType::Normal); |
327 | 321 | auto killThresholdVideo = thresholdForMemoryKill(MemoryType::Video); |
328 | 322 | if ((killThreshold && footprint >= *killThreshold) || (killThresholdVideo && footprintVideo >= *killThresholdVideo)) { |
|
0 commit comments