diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aa5a7a1..f63ee11 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,41 +16,54 @@ jobs: fail-fast: false matrix: configuration: - - Debug - Release arch: - - x86 - x64 + - arm64 include: - - configuration: Debug - config: debug - configuration: Release config: release steps: - name: Check out files - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v3.5.3 with: submodules: true fetch-depth: 0 # NOTE - If LFS ever starts getting used during builds, switch this to true! lfs: false - - name: Install dependencies (x86) - if: matrix.arch == 'x86' + - name: Install crossbuild tools (arm64) + if: matrix.arch == 'arm64' run: | - sudo dpkg --add-architecture i386 sudo apt-get update - sudo apt-get -y install gcc-multilib g++-multilib + sudo apt-get install crossbuild-essential-arm64 -y + + - name: Install Premake5 + uses: abel0b/setup-premake@v2.2 + with: + version: "5.0.0-beta2" + - name: Generate project files - run: ./generate.sh + run: premake5 gmake2 - name: Set up problem matching uses: ammaraskar/gcc-problem-matcher@master + - name: Set up CC environment variable + if: matrix.arch == 'arm64' + run: | + echo "CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV + + - name: Set up CXX environment variable + if: matrix.arch == 'arm64' + run: | + echo "CXX=aarch64-linux-gnu-g++" >> $GITHUB_ENV + - name: Build ${{matrix.configuration}} ${{matrix.arch}} binaries run: | pushd build make config=${{matrix.config}}_${{matrix.arch}} -j$(nproc) + - name: Upload ${{matrix.configuration}} ${{matrix.arch}} binaries uses: actions/upload-artifact@v3.1.2 with: diff --git a/generate.sh b/generate.sh deleted file mode 100755 index ae910e0..0000000 --- a/generate.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -./tools/premake5-linux gmake2 diff --git a/premake5.lua b/premake5.lua index c8faabe..082b523 100644 --- a/premake5.lua +++ b/premake5.lua @@ -6,7 +6,7 @@ targetdir "%{wks.location}/bin/%{cfg.platform}/%{cfg.buildcfg}" configurations {"Debug", "Release"} -platforms {"x86", "x64"} +platforms {"x86", "x64", "arm64"} filter "platforms:x86" architecture "x86" @@ -16,7 +16,9 @@ filter "platforms:x64" architecture "x86_64" filter {} -buildoptions {"-std=gnu11"} +filter "platforms:arm64" +architecture "ARM64" +filter {} symbols "On" staticruntime "On" @@ -25,20 +27,18 @@ warnings "Extra" characterset "ASCII" if os.istarget("linux") then - buildoptions {"-pthread"} - linkoptions {"-pthread"} + buildoptions "-pthread" + linkoptions "-pthread" end if os.getenv("CI") then - defines {"CI"} + defines "CI" end -flags {"NoIncrementalLink", "NoMinimalRebuild", "MultiProcessorCompile", "No64BitChecks"} - filter "configurations:Release" optimize "Speed" - defines {"NDEBUG"} - flags {"FatalCompileWarnings"} + defines "NDEBUG" + flags "FatalCompileWarnings" filter {} filter "configurations:Debug" @@ -48,7 +48,9 @@ filter {} project "MonitorRam" kind "ConsoleApp" + language "C" +cdialect "gnu89" targetname "MonitorRam" diff --git a/src/main.c b/src/main.c index 8b71d2a..680fa71 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ -#include #include +#include #include #include "common.h" @@ -14,7 +14,6 @@ void sigint_handler(int a) { int main(int argc, char* argv[]) { if (argc < 2) { - printf("Name of the program is missing\n"); printf("Usage: \n"); return 2; } diff --git a/src/monitor.c b/src/monitor.c index 846cbcf..0d0fc3d 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -1,14 +1,15 @@ +#include +#include #include #include #include -#include -#include #include +#include "monitor.h" + #include "common.h" #include "utils.h" -#include "monitor.h" #define MAX_MEMORY 1048576 #define MAX_TRACK_SIZE 30 @@ -96,7 +97,7 @@ static int is_process_wild(int curr_real_mem, int peak_real_mem, "KiB\ncurr_virt_mem:%d KiB\npeak_virt_mem:%d KiB\n", id, curr_real_mem, peak_real_mem, curr_virt_mem, peak_virt_mem); - if (result != 0) { + if (result) { fprintf(fp, "Error while terminating process: %d\n", id); fprintf(fp, "Error message: %s\n", strerror(errno)); } @@ -111,7 +112,7 @@ int setup(const char* pid) { char* command = va("pgrep %s", pid); FILE* file = popen(command, "r"); - if (file == NULL) { + if (!file) { perror("popen"); return 1; } @@ -128,7 +129,7 @@ int setup(const char* pid) { ++i; } - if (i == 0) { + if (!i) { printf("No process was found\n"); pclose(file); return 1; @@ -140,13 +141,11 @@ int setup(const char* pid) { int analyse() { int i; FILE* status; - int curr_real_mem = 0, peak_real_mem = 0, curr_virt_mem = 0, - peak_virt_mem = 0; for (i = 0; i < MAX_TRACK_SIZE && processes[i].active == 1; ++i) { char* command = va("cat /proc/%d/status", processes[i].id); status = popen(command, "r"); - if (status == NULL) { + if (!status) { perror("popen"); pclose(status); return 1; @@ -156,6 +155,9 @@ int analyse() { printf("Checking %d\n", processes[i].id); #endif + int curr_real_mem = 0, peak_real_mem = 0, curr_virt_mem = 0, + peak_virt_mem = 0; + check_status(status, &curr_real_mem, &peak_real_mem, &curr_virt_mem, &peak_virt_mem); if (is_process_wild(curr_real_mem, peak_real_mem, curr_virt_mem, @@ -164,7 +166,6 @@ int analyse() { } pclose(status); - curr_real_mem = 0, peak_real_mem = 0, curr_virt_mem = 0, peak_virt_mem = 0; } return 0; diff --git a/src/utils.c b/src/utils.c index 90b13b5..84685c3 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1,23 +1,24 @@ -#include #include -#include +#include #include "utils.h" #define VA_BUFFER_COUNT 4 #define VA_BUFFER_SIZE 4096 -thread_local struct { +struct va_info_s { char va_string[VA_BUFFER_COUNT][VA_BUFFER_SIZE]; int index; -} va_info_t; +}; + +static __thread struct va_info_s va_provider; char* va(const char* fmt, ...) { va_list ap; - int index = va_info_t.index; - va_info_t.index = (va_info_t.index + 1) % VA_BUFFER_COUNT; - char* buf = va_info_t.va_string[index]; + int index = va_provider.index; + va_provider.index = (va_provider.index + 1) % VA_BUFFER_COUNT; + char* buf = va_provider.va_string[index]; va_start(ap, fmt); vsnprintf(buf, VA_BUFFER_SIZE, fmt, ap); diff --git a/tools/premake5-linux b/tools/premake5-linux deleted file mode 100755 index bcb51ce..0000000 Binary files a/tools/premake5-linux and /dev/null differ