Compare commits

...

2 Commits

Author SHA1 Message Date
1f63f81979 feat: ultimate dev container 2025-03-22 15:18:26 +01:00
81c509081f
build: update Premake5 (#3) 2025-03-22 12:28:03 +01:00
9 changed files with 211 additions and 6 deletions

55
.devcontainer/Dockerfile Normal file
View File

@ -0,0 +1,55 @@
FROM ubuntu:noble
# Official workaround for "groupadd: GID '1000' already exists"
RUN userdel -r ubuntu
# Set non-interactive mode for apt-get
ENV DEBIAN_FRONTEND=noninteractive
# Install basic dependencies for compilation
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
gcc-multilib \
g++-multilib \
make \
wget \
unzip \
git \
gdb \
libc6-dbg \
valgrind \
strace \
clang-format \
python3 python3-pip python3-venv \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Create a virtual environment and install colour-valgrind
RUN python3 -m venv /opt/venv && \
/opt/venv/bin/pip install colour-valgrind
# Add the virtual environment to PATH for all users
ENV PATH="/opt/venv/bin:$PATH"
# Download and install Premake5
RUN wget https://github.com/premake/premake-core/releases/download/v5.0.0-beta5/premake-5.0.0-beta5-linux.tar.gz \
&& tar -xvf premake-5.0.0-beta5-linux.tar.gz \
&& mv premake5 /usr/local/bin/ \
&& chmod +x /usr/local/bin/premake5 \
&& rm premake-5.0.0-beta5-linux.tar.gz
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
#
# [Optional] Add sudo support. Omit if you don't need to install software after connecting.
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
USER $USERNAME

View File

@ -0,0 +1,32 @@
{
"name": "MonitorRam Dev Container",
"build": {
"context": "..",
"dockerfile": "./Dockerfile"
},
"capAdd": [
"SYS_PTRACE"
],
"securityOpt": [
"seccomp=unconfined"
],
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools-extension-pack"
],
"settings": {
"C_Cpp.clang_format_style": "file",
"C_Cpp.formatting": "clangFormat",
"editor.formatOnSave": true
}
}
},
"runArgs": [
"--network=host"
],
"forwardPorts": [
3000
],
"remoteUser": "vscode"
}

View File

@ -14,7 +14,7 @@ concurrency:
cancel-in-progress: true cancel-in-progress: true
env: env:
PREMAKE_VERSION: "5.0.0-beta2" PREMAKE_VERSION: "5.0.0-beta5"
jobs: jobs:
build-linux: build-linux:
@ -47,12 +47,12 @@ jobs:
sudo apt-get install crossbuild-essential-arm64 -y sudo apt-get install crossbuild-essential-arm64 -y
- name: Install Premake5 - name: Install Premake5
uses: diamante0018/setup-premake@master uses: diamante0018/setup-premake@v0.0.2
with: with:
version: ${{ env.PREMAKE_VERSION }} version: ${{ env.PREMAKE_VERSION }}
- name: Generate project files - name: Generate project files
run: premake5 gmake2 run: premake5 gmake
- name: Set up problem matching - name: Set up problem matching
uses: ammaraskar/gcc-problem-matcher@master uses: ammaraskar/gcc-problem-matcher@master

51
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,51 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "GDB Debug (Debug Build)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/bin/x64/Debug/MonitorRam",
"args": [
""
], // Arguments to pass to your program
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb", // Path to gdb inside the container
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build-debug" // Task to build the Debug version
},
{
"name": "GDB Debug (Release Build)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/bin/x64/Release/MonitorRam",
"args": [
""
], // Arguments to pass to your program
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build-release" // Task to build the Release version
}
]
}

54
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,54 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "generate-makefiles",
"type": "shell",
"command": "premake5",
"args": [
"gmake"
], // Generate Makefiles
"group": {
"kind": "build",
"isDefault": false
},
"problemMatcher": []
},
{
"label": "build-debug",
"type": "shell",
"command": "make",
"args": [
"-C",
"build",
"config=debug_x64"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
],
"dependsOn": "generate-makefiles"
},
{
"label": "build-release",
"type": "shell",
"command": "make",
"args": [
"-C",
"build",
"config=release_x64"
],
"group": {
"kind": "build",
"isDefault": false
},
"problemMatcher": [
"$gcc"
],
"dependsOn": "generate-makefiles"
}
]
}

View File

@ -1,6 +1,6 @@
BSD 3-Clause License BSD 3-Clause License
Copyright (c) 2022, Edoardo Sanguineti Copyright (c) 2025, diamante0018
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View File

@ -38,7 +38,7 @@ end
filter "configurations:Release" filter "configurations:Release"
optimize "Size" optimize "Size"
defines "NDEBUG" defines "NDEBUG"
flags "FatalCompileWarnings" fatalwarnings "All"
filter {} filter {}
filter "configurations:Debug" filter "configurations:Debug"

View File

@ -1,5 +1,6 @@
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include "common.h" #include "common.h"
@ -19,7 +20,12 @@ int main(int argc, char* argv[]) {
} }
struct sigaction act; struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_handler = sigint_handler; act.sa_handler = sigint_handler;
sigemptyset(&act.sa_mask); // Initialize the signal mask to empty
act.sa_flags = 0; // Set flags to 0
sigaction(SIGINT, &act, NULL); sigaction(SIGINT, &act, NULL);
int result = setup(argv[1]); int result = setup(argv[1]);

View File

@ -1,3 +1,4 @@
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
@ -108,6 +109,13 @@ static int is_process_wild(int curr_real_mem, int peak_real_mem,
} }
int setup(const char* pid) { int setup(const char* pid) {
assert(pid);
if (*pid == '\0') {
printf("Invalid PID\n");
return 1;
}
memset(&processes, 0, sizeof(processes)); memset(&processes, 0, sizeof(processes));
char* command = va("pgrep %s", pid); char* command = va("pgrep %s", pid);
@ -147,7 +155,6 @@ int analyse() {
status = popen(command, "r"); status = popen(command, "r");
if (!status) { if (!status) {
perror("popen"); perror("popen");
pclose(status);
return 1; return 1;
} }