Compare commits

..

1 commit

Author SHA1 Message Date
463e4ed570 feat: added libproc2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-11-13 16:39:04 +01:00
21 changed files with 94 additions and 149 deletions

View file

@ -1,9 +1,9 @@
# SPDX-FileCopyrightText: 2025 Tobias Schmidl # SPDX-FileCopyrightText: 2023 Tobias Schmidl
# #
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
--- ---
BasedOnStyle: Microsoft BasedOnStyle: Mozilla
AlwaysBreakTemplateDeclarations: true
IndentWidth: 4 IndentWidth: 4
... ...
# vim: set filetype=yaml:

View file

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025 Tobias Schmidl # SPDX-FileCopyrightText: 2023 Tobias Schmidl
# #
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
--- ---

View file

@ -1,54 +0,0 @@
// SPDX-FileCopyrightText: 2025 Tobias Schmidl
//
// SPDX-License-Identifier: AGPL-3.0-or-later
//
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "glimpses-devcontainer",
"image": "mcr.microsoft.com/devcontainers/cpp:1",
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers-extra/features/cmake:1": {},
"ghcr.io/devcontainers-extra/features/pre-commit:2": {},
"ghcr.io/devcontainers/features/common-utils:2": {
"username": "vscode",
"uid": "${localEnv:UID}",
"gid": "${localEnv:GID}"
},
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/python:1": {}
},
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
"settings": {},
"extensions": [
"editorconfig.editorconfig",
"elagil.pre-commit-helper",
"llvm-vs-code-extensions.vscode-clangd",
"ms-vscode.cmake-tools",
"ms-vscode.cpptools",
"streetsidesoftware.code-spell-checker",
"vivaxy.vscode-conventional-commits"
]
}
},
"containerEnv": {
"CC": "clang",
"CXX": "clang++",
"CMAKE_BUILD_PARALLEL_LEVEL": "${localEnv:NUMBER_OF_PROCESSORS}",
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++",
"CMAKE_EXPORT_COMPILE_COMMANDS": "1",
"CMAKE_PREFIX_PATH": "/usr/local/cmake"
},
"mounts": [
"source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,readonly",
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
],
"workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind",
"workspaceFolder": "${localWorkspaceFolder}"
}

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2025 Tobias Schmidl SPDX-FileCopyrightText: 2023 Tobias Schmidl
SPDX-License-Identifier: AGPL-3.0-or-later SPDX-License-Identifier: AGPL-3.0-or-later

View file

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025 Tobias Schmidl # SPDX-FileCopyrightText: 2023 Tobias Schmidl
# #
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later

2
.gitignore vendored
View file

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025 Tobias Schmidl # SPDX-FileCopyrightText: 2023 Tobias Schmidl
# #
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later

View file

@ -1,10 +1,10 @@
# SPDX-FileCopyrightText: 2025 Tobias Schmidl # SPDX-FileCopyrightText: 2023 Tobias Schmidl
# #
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
--- ---
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0 rev: v4.4.0
hooks: hooks:
- id: check-yaml - id: check-yaml
- id: end-of-file-fixer - id: end-of-file-fixer
@ -13,7 +13,7 @@ repos:
- id: check-ast - id: check-ast
- id: check-byte-order-marker - id: check-byte-order-marker
- repo: https://github.com/fsfe/reuse-tool - repo: https://github.com/fsfe/reuse-tool
rev: v5.0.2 rev: v2.1.0
hooks: hooks:
- id: reuse - id: reuse
- repo: https://github.com/cheshirekow/cmake-format-precommit - repo: https://github.com/cheshirekow/cmake-format-precommit
@ -31,22 +31,14 @@ repos:
- id: clang-format - id: clang-format
- id: clang-tidy - id: clang-tidy
- repo: https://github.com/editorconfig-checker/editorconfig-checker.python - repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: '3.2.1' rev: '2.7.2'
hooks: hooks:
- id: editorconfig-checker - id: editorconfig-checker
alias: ec alias: ec
stages: [pre-commit] stages: [commit]
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck
- repo: https://github.com/compilerla/conventional-pre-commit - repo: https://github.com/compilerla/conventional-pre-commit
rev: v4.2.0 rev: v2.4.0
hooks: hooks:
- id: conventional-pre-commit - id: conventional-pre-commit
stages: [commit-msg] stages: [commit-msg]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.45.0
hooks:
- id: markdownlint
... ...

View file

@ -1,12 +1,11 @@
{ {
"recommendations": [ "recommendations": [
"cschlosser.doxdocgen", "bbenoist.doxygen",
"editorconfig.editorconfig", "editorconfig.editorconfig",
"elagil.pre-commit-helper", "elagil.pre-commit-helper",
"llvm-vs-code-extensions.vscode-clangd",
"ms-vscode.cmake-tools", "ms-vscode.cmake-tools",
"ms-vscode.cpptools", "ms-vscode.cpptools",
"streetsidesoftware.code-spell-checker", "vivaxy.vscode-conventional-commits",
"vivaxy.vscode-conventional-commits" "xaver.clang-format",
] ]
} }

View file

@ -1,3 +1,3 @@
SPDX-FileCopyrightText: 2025 Tobias Schmidl SPDX-FileCopyrightText: 2023 Tobias Schmidl
SPDX-License-Identifier: AGPL-3.0-or-later SPDX-License-Identifier: AGPL-3.0-or-later

16
.woodpecker.yml Normal file
View file

@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2023 Tobias Schmidl
#
# SPDX-License-Identifier: AGPL-3.0-or-later
---
steps:
editor-config:
image: mstruebing/editorconfig-checker
group: lint
reuse:
image: fsfe/reuse:latest
group: lint
...

View file

@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025 Tobias Schmidl # SPDX-FileCopyrightText: 2023 Tobias Schmidl
# #
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
@ -18,11 +18,17 @@ endif()
# ---- Add dependencies via CPM ---- # ---- Add dependencies via CPM ----
# see https://github.com/TheLartians/CPM.cmake for more info # see https://github.com/TheLartians/CPM.cmake for more info
include(cmake/get_cpm.cmake) include(cmake/CPM.cmake)
# PackageProject.cmake will be used to make our target installable # PackageProject.cmake will be used to make our target installable
CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.8.0") CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.8.0")
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBPROC2 REQUIRED IMPORTED_TARGET libproc2>=4.0.0)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBPROC2 REQUIRED IMPORTED_TARGET libproc2>=4.0.0)
# CPMAddPackage( NAME fmt GIT_TAG 9.1.0 GITHUB_REPOSITORY fmtlib/fmt OPTIONS "FMT_INSTALL YES" # create an installable target ) # CPMAddPackage( NAME fmt GIT_TAG 9.1.0 GITHUB_REPOSITORY fmtlib/fmt OPTIONS "FMT_INSTALL YES" # create an installable target )
# ---- Add source files ---- # ---- Add source files ----
@ -57,5 +63,5 @@ packageProject(
INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION} INCLUDE_DESTINATION include/${PROJECT_NAME}-${PROJECT_VERSION}
VERSION_HEADER "${VERSION_HEADER_LOCATION}" VERSION_HEADER "${VERSION_HEADER_LOCATION}"
COMPATIBILITY SameMajorVersion COMPATIBILITY SameMajorVersion
DEPENDENCIES "" DEPENDENCIES "${LIBPROC2}"
) )

View file

@ -1,5 +1,5 @@
<!-- <!--
SPDX-FileCopyrightText: 2025 Tobias Schmidl SPDX-FileCopyrightText: 2023 Tobias Schmidl
SPDX-License-Identifier: AGPL-3.0-or-later SPDX-License-Identifier: AGPL-3.0-or-later
--> -->
@ -9,3 +9,5 @@ SPDX-License-Identifier: AGPL-3.0-or-later
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://pre-commit.com/) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://pre-commit.com/)
T.B.D. T.B.D.
libproc2-dev
pkg-config

View file

@ -2,8 +2,8 @@
# #
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors # SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
set(CPM_DOWNLOAD_VERSION 0.42.0) set(CPM_DOWNLOAD_VERSION 0.38.5)
set(CPM_HASH_SUM "2020b4fc42dba44817983e06342e682ecfc3d2f484a581f11cc5731fbe4dce8a") set(CPM_HASH_SUM "192aa0ccdc57dfe75bd9e4b176bf7fb5692fd2b3e3f7b09c74856fc39572b31c")
if(CPM_SOURCE_CACHE) if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")

View file

@ -10,7 +10,7 @@ if(NOT PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
return() return()
endif() endif()
include(${CMAKE_CURRENT_LIST_DIR}/get_cpm.cmake) include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake)
# enables sanitizers support using the the `USE_SANITIZER` flag available values are: Address, Memory, MemoryWithOrigins, Undefined, Thread, # enables sanitizers support using the the `USE_SANITIZER` flag available values are: Address, Memory, MemoryWithOrigins, Undefined, Thread,
# Leak, 'Address;Undefined' # Leak, 'Address;Undefined'

View file

@ -8,9 +8,9 @@ project(GlimpsesDocs)
# ---- Dependencies ---- # ---- Dependencies ----
include(../cmake/get_cpm.cmake) include(../cmake/CPM.cmake)
CPMAddPackage("gh:mosra/m.css#0a460a7a9973a41db48f735e7b49e4da9a876325") CPMAddPackage("gh:mosra/m.css#a0d292ec311b97fefd21e93cdefb60f88d19ede6")
CPMAddPackage(NAME Glimpses SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..) CPMAddPackage(NAME Glimpses SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
# ---- Doxygen variables ---- # ---- Doxygen variables ----

View file

@ -4,39 +4,22 @@
#pragma once #pragma once
#include <cstdint>
#include <map>
#include <string> #include <string>
#include "glimpses/version.h" namespace glimpses {
namespace glimpses /**
{ * @brief A class for saying hello in multiple languages
*/
/** @brief A class for saying retrieving system information */
class Glimpses class Glimpses
{ {
public: public:
/** @brief Type for representing the number of CPU cores. */
using CPUCount = uint32_t;
/** @brief Type for representing a set of CPU cores, mapped by their names. */
using CPUSet = std::map<std::string, CPUCount>;
/** @brief Maximum number of CPU cores supported by Glimpses. */
constexpr static CPUCount MAX_CPU_COUNT = 1024;
/** @brief Version of the Glimpses library. */
constexpr static const char *VERSION = GLIMPSES_VERSION;
/** @brief Creates a new glimpses */
Glimpses();
/** /**
* @brief Returns the number of CPU cores available on the system. * @brief Creates a new glimpses
* @return The number of CPU cores available on the system. * @param name the name to greet
*/ */
CPUSet getCPUCount() const; Glimpses();
}; };
} // namespace glimpses } // namespace glimpses

View file

@ -3,25 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-or-later // SPDX-License-Identifier: AGPL-3.0-or-later
#include <glimpses/glimpses.hpp> #include <glimpses/glimpses.hpp>
#include <sched.h> #include <libproc2/pids.h>
#include <thread>
#include <unistd.h>
using namespace glimpses; using namespace glimpses;
Glimpses::Glimpses() Glimpses::Glimpses() {}
{
}
Glimpses::CPUSet Glimpses::getCPUCount() const
{
cpu_set_t cpuset;
auto minmax = [](int64_t min, int64_t value, int64_t max) -> CPUCount {
return std::min(std::max(value, min), max);
};
sched_getaffinity(0, sizeof(cpuset), &cpuset);
return CPUSet{{"configured", minmax(0, sysconf(_SC_NPROCESSORS_CONF), MAX_CPU_COUNT)},
{"logical", minmax(0, std::thread::hardware_concurrency(), MAX_CPU_COUNT)},
{"online", minmax(0, sysconf(_SC_NPROCESSORS_ONLN), MAX_CPU_COUNT)},
{"allowed", minmax(0, CPU_COUNT(&cpuset), MAX_CPU_COUNT)}};
}

View file

@ -12,7 +12,7 @@ include(../cmake/tools.cmake)
# ---- Dependencies ---- # ---- Dependencies ----
include(../cmake/get_cpm.cmake) include(../cmake/CPM.cmake)
CPMAddPackage(NAME Glimpses SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..) CPMAddPackage(NAME Glimpses SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..)

View file

@ -16,10 +16,10 @@ include(../cmake/tools.cmake)
# ---- Dependencies ---- # ---- Dependencies ----
include(../cmake/get_cpm.cmake) include(../cmake/CPM.cmake)
CPMAddPackage(NAME Catch2 GITHUB_REPOSITORY catchorg/Catch2 VERSION 3.8.1) # CPMAddPackage("gh:doctest/doctest@2.4.9")
CPMAddPackage("gh:TheLartians/Format.cmake@1.8.3") CPMAddPackage("gh:TheLartians/Format.cmake@1.7.3")
if(TEST_INSTALLED_VERSION) if(TEST_INSTALLED_VERSION)
find_package(Glimpses REQUIRED) find_package(Glimpses REQUIRED)
@ -31,7 +31,11 @@ endif()
file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp) file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)
add_executable(${PROJECT_NAME} ${sources}) add_executable(${PROJECT_NAME} ${sources})
target_link_libraries(${PROJECT_NAME} Catch2::Catch2WithMain Glimpses::Glimpses) target_link_libraries(
${PROJECT_NAME}
# doctest::doctest
Glimpses::Glimpses
)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
# enable compiler warnings # enable compiler warnings
@ -48,9 +52,6 @@ endif()
enable_testing() enable_testing()
include(CTest)
add_test(GlimpsesTests GlimpsesTests)
# Note: doctest and similar testing frameworks can automatically configure CMake tests. For other testing frameworks add the tests target # Note: doctest and similar testing frameworks can automatically configure CMake tests. For other testing frameworks add the tests target
# instead: add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) # instead: add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME})

View file

@ -2,21 +2,24 @@
// //
// SPDX-License-Identifier: AGPL-3.0-or-later // SPDX-License-Identifier: AGPL-3.0-or-later
#include <catch2/catch_test_macros.hpp>
#include <glimpses/glimpses.hpp> #include <glimpses/glimpses.hpp>
#include <glimpses/version.h> #include <glimpses/version.h>
#include <string> #include <string>
/*
TEST_CASE("Glimpses") {
using namespace greeter;
TEST_CASE("CPU count") Glimpses greeter("Tests");
{
glimpses::Glimpses glimpses{}; CHECK(greeter.greet(LanguageCode::EN) == "Hello, Tests!");
CHECK(greeter.greet(LanguageCode::DE) == "Hallo Tests!");
CHECK(glimpses.getCPUCount().size() > 0); CHECK(greeter.greet(LanguageCode::ES) == "¡Hola Tests!");
CHECK(greeter.greet(LanguageCode::FR) == "Bonjour Tests!");
} }
/* TEST_CASE("Glimpses version") {
TEST_CASE("Glimpses version") { static_assert(std::string_view(GREETER_VERSION) == std::string_view("0.1.0")); static_assert(std::string_view(GREETER_VERSION) == std::string_view("1.0"));
CHECK(std::string(GREETER_VERSION) == std::string("1.0")); CHECK(std::string(GREETER_VERSION) == std::string("1.0"));
} }
*/ */

14
test/source/main.cpp Normal file
View file

@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2023 Tobias Schmidl
//
// SPDX-License-Identifier: AGPL-3.0-or-later
#if 0
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#endif
int
main()
{
return 0;
}