Created
July 2, 2020 09:16
-
-
Save HadrienRenaud/91a791cc3020b36865045ea60c6c41cd to your computer and use it in GitHub Desktop.
Tracking memory usage in future creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This file just build and resolve many futures while mesuring memory usage | |
-- The memory consumption analysis is done following : | |
-- https://stackoverflow.com/a/47531152 | |
EMBED | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
END | |
-- Measures the current (and peak) resident and virtual memories | |
-- usage of your linux C process | |
fun printMemUsage(): unit | |
EMBED (unit) | |
int currRealMem; | |
int peakRealMem; | |
int currVirtMem; | |
int peakVirtMem; | |
// stores each word in status file | |
char buffer[1024] = ""; | |
// linux file contains this-process info | |
FILE* file = fopen("/proc/self/status", "r"); | |
// read the entire file | |
while (fscanf(file, " %1023s", buffer) == 1) { | |
if (strcmp(buffer, "VmRSS:") == 0) { | |
fscanf(file, " %d", &currRealMem); | |
} | |
if (strcmp(buffer, "VmHWM:") == 0) { | |
fscanf(file, " %d", &peakRealMem); | |
} | |
if (strcmp(buffer, "VmSize:") == 0) { | |
fscanf(file, " %d", &currVirtMem); | |
} | |
if (strcmp(buffer, "VmPeak:") == 0) { | |
fscanf(file, " %d", &peakVirtMem); | |
} | |
} | |
fclose(file); | |
printf("CRM: %d MB, PRM: %d MB, CVM: %d MB, PvM: %d MB", currRealMem / 1024, peakRealMem / 1024, currVirtMem / 1024, peakVirtMem / 1024); | |
END | |
end | |
active class A | |
def foo(): int | |
1 | |
end | |
end | |
active class Main | |
def main() : unit | |
val a = new A | |
val n = 10000000 | |
val n_100 = n / 100 | |
repeat i <- n do | |
get(a!foo()) | |
if i % n_100 == 0 then | |
print("Running ({}%) : ", i / n_100) | |
printMemUsage() | |
println("") | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment