mirror of
https://github.com/diamante0018/MonitorRam.git
synced 2025-05-09 22:14:54 +00:00
build: arm64 / c89 (#2)
This commit is contained in:
parent
e5081680ab
commit
2521e83c98
33
.github/workflows/build.yml
vendored
33
.github/workflows/build.yml
vendored
@ -16,41 +16,54 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
configuration:
|
configuration:
|
||||||
- Debug
|
|
||||||
- Release
|
- Release
|
||||||
arch:
|
arch:
|
||||||
- x86
|
|
||||||
- x64
|
- x64
|
||||||
|
- arm64
|
||||||
include:
|
include:
|
||||||
- configuration: Debug
|
|
||||||
config: debug
|
|
||||||
- configuration: Release
|
- configuration: Release
|
||||||
config: release
|
config: release
|
||||||
steps:
|
steps:
|
||||||
- name: Check out files
|
- name: Check out files
|
||||||
uses: actions/checkout@v3.5.2
|
uses: actions/checkout@v3.5.3
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
# NOTE - If LFS ever starts getting used during builds, switch this to true!
|
# NOTE - If LFS ever starts getting used during builds, switch this to true!
|
||||||
lfs: false
|
lfs: false
|
||||||
|
|
||||||
- name: Install dependencies (x86)
|
- name: Install crossbuild tools (arm64)
|
||||||
if: matrix.arch == 'x86'
|
if: matrix.arch == 'arm64'
|
||||||
run: |
|
run: |
|
||||||
sudo dpkg --add-architecture i386
|
|
||||||
sudo apt-get update
|
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
|
- name: Generate project files
|
||||||
run: ./generate.sh
|
run: premake5 gmake2
|
||||||
|
|
||||||
- name: Set up problem matching
|
- name: Set up problem matching
|
||||||
uses: ammaraskar/gcc-problem-matcher@master
|
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
|
- name: Build ${{matrix.configuration}} ${{matrix.arch}} binaries
|
||||||
run: |
|
run: |
|
||||||
pushd build
|
pushd build
|
||||||
make config=${{matrix.config}}_${{matrix.arch}} -j$(nproc)
|
make config=${{matrix.config}}_${{matrix.arch}} -j$(nproc)
|
||||||
|
|
||||||
- name: Upload ${{matrix.configuration}} ${{matrix.arch}} binaries
|
- name: Upload ${{matrix.configuration}} ${{matrix.arch}} binaries
|
||||||
uses: actions/upload-artifact@v3.1.2
|
uses: actions/upload-artifact@v3.1.2
|
||||||
with:
|
with:
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
./tools/premake5-linux gmake2
|
|
20
premake5.lua
20
premake5.lua
@ -6,7 +6,7 @@ targetdir "%{wks.location}/bin/%{cfg.platform}/%{cfg.buildcfg}"
|
|||||||
|
|
||||||
configurations {"Debug", "Release"}
|
configurations {"Debug", "Release"}
|
||||||
|
|
||||||
platforms {"x86", "x64"}
|
platforms {"x86", "x64", "arm64"}
|
||||||
|
|
||||||
filter "platforms:x86"
|
filter "platforms:x86"
|
||||||
architecture "x86"
|
architecture "x86"
|
||||||
@ -16,7 +16,9 @@ filter "platforms:x64"
|
|||||||
architecture "x86_64"
|
architecture "x86_64"
|
||||||
filter {}
|
filter {}
|
||||||
|
|
||||||
buildoptions {"-std=gnu11"}
|
filter "platforms:arm64"
|
||||||
|
architecture "ARM64"
|
||||||
|
filter {}
|
||||||
|
|
||||||
symbols "On"
|
symbols "On"
|
||||||
staticruntime "On"
|
staticruntime "On"
|
||||||
@ -25,20 +27,18 @@ warnings "Extra"
|
|||||||
characterset "ASCII"
|
characterset "ASCII"
|
||||||
|
|
||||||
if os.istarget("linux") then
|
if os.istarget("linux") then
|
||||||
buildoptions {"-pthread"}
|
buildoptions "-pthread"
|
||||||
linkoptions {"-pthread"}
|
linkoptions "-pthread"
|
||||||
end
|
end
|
||||||
|
|
||||||
if os.getenv("CI") then
|
if os.getenv("CI") then
|
||||||
defines {"CI"}
|
defines "CI"
|
||||||
end
|
end
|
||||||
|
|
||||||
flags {"NoIncrementalLink", "NoMinimalRebuild", "MultiProcessorCompile", "No64BitChecks"}
|
|
||||||
|
|
||||||
filter "configurations:Release"
|
filter "configurations:Release"
|
||||||
optimize "Speed"
|
optimize "Speed"
|
||||||
defines {"NDEBUG"}
|
defines "NDEBUG"
|
||||||
flags {"FatalCompileWarnings"}
|
flags "FatalCompileWarnings"
|
||||||
filter {}
|
filter {}
|
||||||
|
|
||||||
filter "configurations:Debug"
|
filter "configurations:Debug"
|
||||||
@ -48,7 +48,9 @@ filter {}
|
|||||||
|
|
||||||
project "MonitorRam"
|
project "MonitorRam"
|
||||||
kind "ConsoleApp"
|
kind "ConsoleApp"
|
||||||
|
|
||||||
language "C"
|
language "C"
|
||||||
|
cdialect "gnu89"
|
||||||
|
|
||||||
targetname "MonitorRam"
|
targetname "MonitorRam"
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -14,7 +14,6 @@ void sigint_handler(int a) {
|
|||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
printf("Name of the program is missing\n");
|
|
||||||
printf("Usage: <name of the program>\n");
|
printf("Usage: <name of the program>\n");
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
|
#include <errno.h>
|
||||||
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "monitor.h"
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "monitor.h"
|
|
||||||
|
|
||||||
#define MAX_MEMORY 1048576
|
#define MAX_MEMORY 1048576
|
||||||
#define MAX_TRACK_SIZE 30
|
#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",
|
"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);
|
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 while terminating process: %d\n", id);
|
||||||
fprintf(fp, "Error message: %s\n", strerror(errno));
|
fprintf(fp, "Error message: %s\n", strerror(errno));
|
||||||
}
|
}
|
||||||
@ -111,7 +112,7 @@ int setup(const char* pid) {
|
|||||||
|
|
||||||
char* command = va("pgrep %s", pid);
|
char* command = va("pgrep %s", pid);
|
||||||
FILE* file = popen(command, "r");
|
FILE* file = popen(command, "r");
|
||||||
if (file == NULL) {
|
if (!file) {
|
||||||
perror("popen");
|
perror("popen");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -128,7 +129,7 @@ int setup(const char* pid) {
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == 0) {
|
if (!i) {
|
||||||
printf("No process was found\n");
|
printf("No process was found\n");
|
||||||
pclose(file);
|
pclose(file);
|
||||||
return 1;
|
return 1;
|
||||||
@ -140,13 +141,11 @@ int setup(const char* pid) {
|
|||||||
int analyse() {
|
int analyse() {
|
||||||
int i;
|
int i;
|
||||||
FILE* status;
|
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) {
|
for (i = 0; i < MAX_TRACK_SIZE && processes[i].active == 1; ++i) {
|
||||||
char* command = va("cat /proc/%d/status", processes[i].id);
|
char* command = va("cat /proc/%d/status", processes[i].id);
|
||||||
status = popen(command, "r");
|
status = popen(command, "r");
|
||||||
if (status == NULL) {
|
if (!status) {
|
||||||
perror("popen");
|
perror("popen");
|
||||||
pclose(status);
|
pclose(status);
|
||||||
return 1;
|
return 1;
|
||||||
@ -156,6 +155,9 @@ int analyse() {
|
|||||||
printf("Checking %d\n", processes[i].id);
|
printf("Checking %d\n", processes[i].id);
|
||||||
#endif
|
#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,
|
check_status(status, &curr_real_mem, &peak_real_mem, &curr_virt_mem,
|
||||||
&peak_virt_mem);
|
&peak_virt_mem);
|
||||||
if (is_process_wild(curr_real_mem, peak_real_mem, curr_virt_mem,
|
if (is_process_wild(curr_real_mem, peak_real_mem, curr_virt_mem,
|
||||||
@ -164,7 +166,6 @@ int analyse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pclose(status);
|
pclose(status);
|
||||||
curr_real_mem = 0, peak_real_mem = 0, curr_virt_mem = 0, peak_virt_mem = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
15
src/utils.c
15
src/utils.c
@ -1,23 +1,24 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <threads.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#define VA_BUFFER_COUNT 4
|
#define VA_BUFFER_COUNT 4
|
||||||
#define VA_BUFFER_SIZE 4096
|
#define VA_BUFFER_SIZE 4096
|
||||||
|
|
||||||
thread_local struct {
|
struct va_info_s {
|
||||||
char va_string[VA_BUFFER_COUNT][VA_BUFFER_SIZE];
|
char va_string[VA_BUFFER_COUNT][VA_BUFFER_SIZE];
|
||||||
int index;
|
int index;
|
||||||
} va_info_t;
|
};
|
||||||
|
|
||||||
|
static __thread struct va_info_s va_provider;
|
||||||
|
|
||||||
char* va(const char* fmt, ...) {
|
char* va(const char* fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
int index = va_info_t.index;
|
int index = va_provider.index;
|
||||||
va_info_t.index = (va_info_t.index + 1) % VA_BUFFER_COUNT;
|
va_provider.index = (va_provider.index + 1) % VA_BUFFER_COUNT;
|
||||||
char* buf = va_info_t.va_string[index];
|
char* buf = va_provider.va_string[index];
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vsnprintf(buf, VA_BUFFER_SIZE, fmt, ap);
|
vsnprintf(buf, VA_BUFFER_SIZE, fmt, ap);
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user