Use rpkg and system libraries if available
This commit is contained in:
parent
7cb0e96864
commit
397f4aa998
11 changed files with 148 additions and 130 deletions
|
@ -1,31 +0,0 @@
|
|||
%global debug_package %{nil}
|
||||
%define _build_id_links none
|
||||
|
||||
Name: procwatch
|
||||
Version: 0.9.7
|
||||
Release: 2%{?dist}
|
||||
Summary: Process watcher
|
||||
|
||||
License: GPLv3+
|
||||
URL: https://betaco.de/strom/procwatch
|
||||
Source0: procwatch.tar.zst
|
||||
|
||||
%description
|
||||
Monitor CPU usage of processes matching a regular expression pattern
|
||||
|
||||
%prep
|
||||
%autosetup -n procwatch
|
||||
|
||||
%build
|
||||
|
||||
%install
|
||||
install -m 0755 -vd %{buildroot}%{_bindir}
|
||||
install -m 0755 -vp %{name} %{buildroot}%{_bindir}/
|
||||
|
||||
%files
|
||||
%license LICENSE
|
||||
%{_bindir}/%{name}
|
||||
|
||||
%changelog
|
||||
* Wed Dec 06 2023 Thorsten Schubert <tschubert@bafh.org>
|
||||
- Initial package build
|
96
justfile
96
justfile
|
@ -4,7 +4,7 @@
|
|||
set positional-arguments := true
|
||||
|
||||
project := 'procwatch'
|
||||
arch := 'native'
|
||||
arch := 'x86-64-v3'
|
||||
pie := 'false'
|
||||
proot := justfile_directory()
|
||||
|
||||
|
@ -12,10 +12,11 @@ proot := justfile_directory()
|
|||
default:
|
||||
@just help
|
||||
|
||||
# Display this help
|
||||
help:
|
||||
@just --list
|
||||
|
||||
# watch for file modificatons and rebuild
|
||||
# Watch for file modificatons and rebuild
|
||||
watch:
|
||||
#!/usr/bin/env bash
|
||||
while :; do
|
||||
|
@ -38,7 +39,7 @@ watch:
|
|||
done
|
||||
done
|
||||
|
||||
# setup development environment
|
||||
# Setup debug build environment
|
||||
setup *args:
|
||||
@meson setup build \
|
||||
-Db_sanitize=address \
|
||||
|
@ -47,35 +48,37 @@ setup *args:
|
|||
-Dbench=true \
|
||||
{{ args }}
|
||||
|
||||
# enable debug allocation output
|
||||
# Enable debug allocation output
|
||||
enable-print-allocs:
|
||||
@meson configure build -Dcpp_args=-DPRINT_ALLOC
|
||||
|
||||
# disable debug allocation output
|
||||
# Disable debug allocation output
|
||||
disable-print-allocs:
|
||||
@meson configure build -Dcpp_args=
|
||||
|
||||
# build debug
|
||||
# Build debug
|
||||
build:
|
||||
@test -f build || just setup
|
||||
@ninja -v -C build all
|
||||
|
||||
# run all tests if any
|
||||
# Run all tests if any
|
||||
test:
|
||||
@ninja -v -C build test
|
||||
|
||||
# clean debug object files
|
||||
# Clean debug object files
|
||||
[no-exit-message]
|
||||
clean:
|
||||
@ninja -v -C build clean
|
||||
@ninja -v -C release clean
|
||||
@ccache -C || true
|
||||
@rm -rf ./dist
|
||||
@-ninja -v -C build clean
|
||||
@-ninja -v -C release clean
|
||||
@-ccache -C || true
|
||||
@-rm -rf ./dist
|
||||
|
||||
# run debug build with arguments
|
||||
# Run debug build with arguments
|
||||
run *args: build
|
||||
@./build/{{ project }} "$@"
|
||||
|
||||
# create release, default to native march
|
||||
release march=arch $CCACHE_DISABLE="1":
|
||||
# Setup release environment
|
||||
setup-release march=arch $CCACHE_DISABLE="1":
|
||||
@meson setup release \
|
||||
-DCLI11:warning_level=0
|
||||
@meson configure release \
|
||||
|
@ -84,56 +87,53 @@ release march=arch $CCACHE_DISABLE="1":
|
|||
-Db_pie={{ pie }} \
|
||||
-Ddebug=true \
|
||||
{{ if pie == 'false' { "-Dcpp_link_args=-no-pie" } else { "" } }}
|
||||
|
||||
# Create release, default to native march
|
||||
release march=arch $CCACHE_DISABLE="1":
|
||||
@test -f release || just setup-release
|
||||
@ninja -v -C release
|
||||
@mkdir -p dist/
|
||||
@cp -f release/{{ project }} dist/{{ project }}-{{ march }}
|
||||
|
||||
# create release for x86-64-v3
|
||||
release-generic:
|
||||
@just release x86-64-v3
|
||||
|
||||
# create all release variants
|
||||
release-all:
|
||||
@just release {{ arch }}
|
||||
@just release-generic
|
||||
|
||||
# invoke setup and build, creating a complete debug build
|
||||
# Invoke setup and build, creating a complete debug build
|
||||
debug: setup build
|
||||
|
||||
# try building all debug and release variants
|
||||
build-all: debug release-all
|
||||
# Try building debug and release variants
|
||||
build-all: build release
|
||||
|
||||
# create tar archive for specific architecture
|
||||
bundle march:
|
||||
test -f dist/procwatch-{{ march }}
|
||||
mkdir -p dist/{{ march }}/procwatch
|
||||
ln -f dist/procwatch-{{ march }} dist/{{ march }}/procwatch/procwatch
|
||||
cp LICENSE dist/{{ march }}/procwatch
|
||||
tar -cvJf dist/{{ march }}/procwatch.tar.zst -C dist/{{ march }} procwatch
|
||||
# Show NVR
|
||||
version:
|
||||
@cat dist/version
|
||||
|
||||
# create rpm package from bundle for architecture
|
||||
rpm march: (bundle march)
|
||||
#!/usr/bin/env bash
|
||||
cd dist/
|
||||
mock --resultdir {{ march }} --buildsrpm --spec ../contrib/procwatch.spec --sources {{ march }}/procwatch.tar.zst
|
||||
mock --resultdir {{ march }} {{ march }}/procwatch*.src.rpm
|
||||
# Build spec file
|
||||
spec:
|
||||
@mkdir -p dist
|
||||
@rpkg spec --outdir=dist --sources
|
||||
@rpkg nvr > dist/version
|
||||
|
||||
rpm-native:
|
||||
@just rpm native
|
||||
# Build locally
|
||||
rpkg:
|
||||
@rpkg local --outdir={{ proot }}/dist
|
||||
|
||||
rpm-generic:
|
||||
@just rpm x86-64-v3
|
||||
# Create srpm in mock container
|
||||
mock-srpm:
|
||||
@mock --resultdir dist --buildsrpm --spec dist/procwatch.spec --sources dist/procwatch-$(git rev-parse --short HEAD)*.tar.gz
|
||||
|
||||
rpm-all: rpm-native rpm-generic
|
||||
# Build the rpm package in mock container
|
||||
mock-rpm:
|
||||
@mock --resultdir dist dist/$(< dist/version).src.rpm
|
||||
|
||||
# remove all untracked files
|
||||
# Build rpm
|
||||
rpm: spec mock-srpm mock-rpm
|
||||
|
||||
# Remove all untracked files
|
||||
[no-exit-message]
|
||||
[private]
|
||||
mrproper: wipe
|
||||
|
||||
# remove all untracked files
|
||||
# Remove all untracked files
|
||||
[no-exit-message]
|
||||
wipe:
|
||||
wipe: clean
|
||||
@git clean -fxd
|
||||
|
||||
# vi: set ft=just ts=4 sw=4 sts=-1 nosr et si tw=0 fdm=manual:
|
||||
|
|
32
meson.build
32
meson.build
|
@ -1,15 +1,10 @@
|
|||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# Copyright © 2023 Thorsten Schubert <tschubert@bafh.org>
|
||||
|
||||
project('procwatch',
|
||||
'cpp',
|
||||
version: 'v0.9.7',
|
||||
default_options: [ 'cpp_std=c++23', 'warning_level=3'])
|
||||
project('procwatch', 'cpp', version: 'v0.9.7', default_options: [ 'cpp_std=c++23', 'warning_level=3'])
|
||||
|
||||
if get_option('buildtype') == 'release'
|
||||
cpp_args = [
|
||||
'-Db_lto=true',
|
||||
'-DNDEBUG']
|
||||
cpp_args = [ '-Db_lto=true', '-DNDEBUG']
|
||||
|
||||
foreach arg : cpp_args
|
||||
add_project_arguments(arg, language : 'cpp')
|
||||
|
@ -20,12 +15,6 @@ if get_option('buildtype') == 'release'
|
|||
'-Wconversion',
|
||||
'-Wno-unused-parameter',
|
||||
'-Wno-unused-variable',
|
||||
# '-D_FORTIFY_SOURCE=2',
|
||||
# '-fasynchronous-unwind-tables',
|
||||
# '-fstack-clash-protection',
|
||||
# '-fcf-protection',
|
||||
# '-fstack-protector-strong',
|
||||
# '-fno-omit-frame-pointer',
|
||||
'-ffast-math']
|
||||
|
||||
cc = meson.get_compiler('cpp')
|
||||
|
@ -37,23 +26,12 @@ if get_option('buildtype') == 'release'
|
|||
endif
|
||||
|
||||
# subprojects / dependencies
|
||||
deps = [
|
||||
subproject('CLI11').get_variable('CLI11_dep'),
|
||||
subproject('unordered_dense').get_variable('unordered_dense_dep'),
|
||||
dependency('re2'),
|
||||
dependency('libnotify')]
|
||||
deps = [ dependency('CLI11'), dependency('re2'), dependency('libnotify') ]
|
||||
|
||||
conf = configuration_data()
|
||||
conf.set('PROJECT_VERSION', meson.project_version())
|
||||
conf.set('BENCHMARK', get_option('bench'))
|
||||
|
||||
configure_file(input: 'config.h.in',
|
||||
output: 'config.h',
|
||||
configuration: conf)
|
||||
configure_file(input: 'config.h.in', output: 'config.h', configuration: conf)
|
||||
|
||||
executable('procwatch',
|
||||
'src/main.cpp',
|
||||
'src/notify.cpp',
|
||||
dependencies: deps,
|
||||
# link_args: '-Wl,-z,now'
|
||||
)
|
||||
executable('procwatch', 'src/main.cpp', 'src/notify.cpp', dependencies: deps, install: true)
|
||||
|
|
38
procwatch.spec.rpkg
Normal file
38
procwatch.spec.rpkg
Normal file
|
@ -0,0 +1,38 @@
|
|||
Name: {{{ git_name }}}
|
||||
Version: {{{ git_version }}}
|
||||
Release: {{{ git_release }}}%{?dist}
|
||||
Summary: Process watcher
|
||||
|
||||
License: GPLv3+
|
||||
URL: https://betaco.de/strom/procwatch
|
||||
|
||||
VCS: {{{ git_dir_vcs }}}
|
||||
Source0: {{{ git_dir_pack }}}
|
||||
|
||||
BuildRequires: gcc-c++
|
||||
BuildRequires: meson
|
||||
BuildRequires: pkgconfig(CLI11)
|
||||
BuildRequires: pkgconfig(re2)
|
||||
BuildRequires: pkgconfig(libnotify)
|
||||
|
||||
%description
|
||||
Monitor CPU usage of processes matching a regular expression pattern
|
||||
|
||||
%prep
|
||||
{{{ git_dir_setup_macro }}}
|
||||
|
||||
%build
|
||||
export CXXFLAGS="$CXXFLAGS -march=x86-64-v3"
|
||||
%meson
|
||||
%meson_build
|
||||
|
||||
%install
|
||||
%meson_install
|
||||
|
||||
%files
|
||||
%license LICENSE
|
||||
%doc README.md
|
||||
%{_bindir}/procwatch
|
||||
|
||||
%changelog
|
||||
{{{ git_dir_changelog }}}
|
2
rpkg.conf
Normal file
2
rpkg.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
[rpkg]
|
||||
user_macros = "${git_props:root}/rpkg.macros"
|
38
rpkg.macros
Normal file
38
rpkg.macros
Normal file
|
@ -0,0 +1,38 @@
|
|||
# vi: ft=sh
|
||||
# shellcheck shell=bash disable=2155
|
||||
|
||||
git_tag() {
|
||||
git describe --tags --abbrev=0 2>/dev/null | head -n 1
|
||||
}
|
||||
|
||||
git_commit_count() {
|
||||
local tag=$1
|
||||
if [ -n "$tag" ]; then
|
||||
git rev-list "$tag"..HEAD --count 2>/dev/null || printf 0
|
||||
else
|
||||
git rev-list HEAD --count 2>/dev/null || printf 0
|
||||
fi
|
||||
}
|
||||
|
||||
git_version() {
|
||||
tag="$(git_tag)"
|
||||
tag_version="$(echo "$tag" | sed -E -n "s/^v?([^-]+)/\1/p")"
|
||||
if [ -z "$tag_version" ]; then
|
||||
tag_version=0
|
||||
fi
|
||||
commit_count="$(git_commit_count "$tag")"
|
||||
if [ "$commit_count" -eq 0 ]; then
|
||||
output "$tag_version"
|
||||
else
|
||||
shortcommit="$(git rev-parse --short HEAD)"
|
||||
output "$tag_version^${commit_count}.git${shortcommit}"
|
||||
fi
|
||||
}
|
||||
|
||||
git_release() {
|
||||
output "1"
|
||||
}
|
||||
|
||||
git_dir_release() {
|
||||
git_release "$@"
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Copyright © 2023 Thorsten Schubert <tschubert@bafh.org>
|
||||
|
||||
#include <ankerl/unordered_dense.h>
|
||||
#include <re2/re2.h>
|
||||
|
||||
#include <CLI/CLI.hpp>
|
||||
|
@ -24,6 +23,8 @@
|
|||
#include <string>
|
||||
#include <string_view>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
#include "config.h"
|
||||
#include "debug.hpp"
|
||||
|
@ -522,11 +523,10 @@ auto main(int argc, char** argv) -> int {
|
|||
auto start = std::chrono::steady_clock::now();
|
||||
auto notify_last = start;
|
||||
|
||||
ankerl::unordered_dense::map<i64, u64> prev_cpu_total{}, current_cpu_times{},
|
||||
over_threshold_cycles{};
|
||||
std::unordered_map<i64, u64> prev_cpu_total{}, current_cpu_times{}, over_threshold_cycles{};
|
||||
|
||||
// Keep track of active processes for cycle count calculation
|
||||
ankerl::unordered_dense::set<i64> active_processes;
|
||||
std::unordered_set<i64> active_processes;
|
||||
|
||||
prev_cpu_total.reserve(1 << 11), current_cpu_times.reserve(1 << 11);
|
||||
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
project('unordered_dense', 'cpp',
|
||||
version: '4.4.0',
|
||||
license: 'MIT',
|
||||
default_options : [
|
||||
'cpp_std=c++17',
|
||||
'warning_level=3',
|
||||
'werror=true',
|
||||
'b_ndebug=true', # otherwise absl is really slow!
|
||||
])
|
||||
|
||||
unordered_dense_inc = include_directories(['include'])
|
||||
|
||||
unordered_dense_dep = declare_dependency(
|
||||
include_directories : unordered_dense_inc,
|
||||
version : meson.project_version())
|
13
subprojects/re2.wrap
Normal file
13
subprojects/re2.wrap
Normal file
|
@ -0,0 +1,13 @@
|
|||
[wrap-file]
|
||||
directory = re2-2023-03-01
|
||||
source_url = https://github.com/google/re2/archive/2023-03-01.tar.gz
|
||||
source_filename = re2-2023-03-01.tar.gz
|
||||
source_hash = 7a9a4824958586980926a300b4717202485c4b4115ac031822e29aa4ef207e48
|
||||
patch_filename = re2_20230301-2_patch.zip
|
||||
patch_url = https://wrapdb.mesonbuild.com/v2/re2_20230301-2/get_patch
|
||||
patch_hash = 2ebbb91690ceafd1f24cdbbdfd9cc60f78e260779c283d1a0e1fac2afae891a9
|
||||
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/re2_20230301-2/re2-2023-03-01.tar.gz
|
||||
wrapdb_version = 20230301-2
|
||||
|
||||
[provide]
|
||||
re2 = re2_dep
|
|
@ -1,5 +0,0 @@
|
|||
[wrap-git]
|
||||
url = https://github.com/martinus/unordered_dense.git
|
||||
revision = d911053e390816ecc5dedd5a9d6b4bb5ed92b4c9
|
||||
depth = 1
|
||||
patch_directory = unordered_dense
|
Loading…
Reference in a new issue