%global debug_package %{nil}
%global _enable_debug_packages 0
Name:           sysTrace
Version:        1.1
Release:        5
Summary:        System Tracing Library with Fail Slow Detection
License:        GPLv2 AND MulanPSL2
URL:            https://atomgit.com/src-openeuler/sysTrace
Source0:        %{name}-%{version}.tar.gz


BuildRequires:  gcc-c++ cmake make
BuildRequires:  python3-devel
BuildRequires:  libbpf libbpf-devel clang bpftool
BuildRequires:  protobuf-devel protobuf-compiler protobuf-c protobuf-c-devel

%description
sysTrace is a system tracing library that provides low-level system
tracing capabilities for debugging and performance analysis, bundled
with fail slow detection module.

%package -n sysTrace-failslow
Summary:        Fail Slow Detection for AI Model Training and Inference
Requires:       python3-pyyaml python3-joblib python3-numpy python3-setuptools
Requires:       python3-pandas python3-scikit-learn
Requires:       procps-ng

%description -n sysTrace-failslow
Fail slow detection module for A-Ops project, providing detection
capabilities for AI model training and inference scenarios.

%prep
%setup -q -n %{name}-%{version}

%build
cd systrace
bash build.sh
cd ..

cd failslow
%py3_build
cd ..

%install
install -d -m 755 %{buildroot}%{_sysconfdir}/systrace/config
install -d -m 755 %{buildroot}%{_libdir}
install -d -m 755 %{buildroot}%{_bindir}
install -m 755 systrace/build/libsysTrace.so %{buildroot}%{_libdir}/
install -m 755 systrace/build/sysTrace_cli %{buildroot}%{_bindir}/
install -m 755 systrace/config/PyFuncList %{buildroot}%{_sysconfdir}/systrace/config/

install -m 644 failslow/config/*.json %{buildroot}%{_sysconfdir}/systrace/config/


cd failslow
%py3_install
cd ..

install -d -m 750 %{buildroot}/var/lib/systrace

%pre -n sysTrace-failslow
getent group systrace >/dev/null || groupadd -r systrace
getent passwd systrace >/dev/null || \
    useradd -r -g systrace -d /var/lib/systrace -s /sbin/nologin \
    -c "System Trace Service Account" systrace

%post -n sysTrace-failslow
%systemd_post systrace-failslow.service
chown -R root:systrace %{_sysconfdir}/systrace/config
chmod 750 %{_sysconfdir}/systrace/config
chown -R root:systrace /var/lib/systrace
chmod 750 /var/lib/systrace

%preun -n sysTrace-failslow
%systemd_preun systrace-failslow.service

%postun -n sysTrace-failslow
%systemd_postun_with_restart systrace-failslow.service

%files
%{_libdir}/libsysTrace.so
%{_bindir}/sysTrace_cli
%{_sysconfdir}/systrace/config/PyFuncList

%files -n sysTrace-failslow
%doc failslow/README.md
%{_bindir}/systrace-failslow
%config(noreplace) %{_sysconfdir}/systrace/config/*.json
%{python3_sitelib}/failslow/
%{python3_sitelib}/systrace_failslow-*.egg-info
%{_unitdir}/systrace-failslow.service
%dir %attr(750, root, systrace) /var/lib/systrace


%changelog
* Tue Sep 15 2026 zwyangah<zwyangah@isoftstone.com> - 1.1-5
- change: update URL from gitee to atomgit.com

* Mon Sep 15 2025 huangbin <huangbin58@huawei.com> - 1.1-4
- update systrace.

* Fri Aug 15 2025 houxu <houxu5@h-partners.com> - 1.1-3
- update fail_slow_detection

* Thu Aug 14 2025 houxu <houxu5@h-partners.com> - 1.1-2
- update mcp parameter

* Mon Aug 11 2025 houxu <houxu5@h-partners.com> - 1.1-1
- Add sysTrace-mcpserver subpackage with MCP integration

* Wed May 14 2025 liwei <1289113577@qq.com> - 1.0-1
- Initial package for sysTrace