Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcdonell committed Oct 18, 2024
2 parents 5c33a84 + a754b19 commit 138a945
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 51 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ jobs:
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@0d4c9c5ea7693da7b068278f7b52bda2a190a446
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@a64d0487d7069df33b279515d35d60fa80e2ea62
uses: docker/metadata-action@70b2cdc6480c1a8b86edf1777157f8f437de2166
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@9552610e81f4c8002dadc4670f1fdced6a2c830b
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75
with:
context: .
file: ./build/containers/pcp/Dockerfile
Expand Down
4 changes: 3 additions & 1 deletion qa/1794
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ _filter()
{
sed \
-e "s@$tmp@TMP@g" \
-e "[email protected][0-9][0-9]*@SMALLNUM@g" \
-e "[email protected]@ZERONUM@g" \
# end
}

Expand All @@ -51,7 +53,7 @@ if (len(df.columns) < 42):
else:
print('Columns:', len(df.columns))
print('Shape:', df.shape)
"
" | _filter
done

# success, all done
Expand Down
8 changes: 4 additions & 4 deletions qa/1794.out
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Columns: ['disk.all.total', 'event.flags', 'event.missed', 'hinv.ncpu', 'kernel.
1 and 15 minute load averages
kernel.all.load[1 minute] kernel.all.load[15 minute]
0 NaN NaN
1 0.024414 0.0
2 0.020508 0.0
3 0.013672 0.0
4 0.012695 0.0
1 SMALLNUM ZERONUM
2 SMALLNUM ZERONUM
3 SMALLNUM ZERONUM
4 SMALLNUM ZERONUM
Shape: (5, 20)

=== pcp2arrow proc
Expand Down
4 changes: 4 additions & 0 deletions qa/737.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ pmCtime from int: Mon Feb 3 04:46:19 2014
pmCtime from float: Mon Feb 3 04:46:19 2014
pmWhichZone: UTC
pmWhichZone: UTC
timeval from int: 1391402779.000
timeval from float: 1391402779.500
timespec from int: 1391402779.000
timespec from float: 1391402779.500
16 changes: 14 additions & 2 deletions qa/src/test_pcp_time.python
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env pmpython
#
# Copyright (C) 2014,2016 Red Hat.
# Copyright (C) 2014,2016,2024 Red Hat.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
Expand All @@ -13,7 +13,7 @@
# for more details.
#

""" Exercise the pmCtime and pmLocaltime interfaces """
""" Exercise pmCtime, pmLocaltime, timeval and timespec interfaces """

from pcp import pmapi
import time
Expand Down Expand Up @@ -44,3 +44,15 @@ print("pmCtime from float: %s" % str(context.pmCtime(sample_time_f)).rstrip
print("pmWhichZone: %s" % str(context.pmWhichZone()))
# https://bugzilla.redhat.com/show_bug.cgi?id=1352465
print("pmWhichZone: %s" % str(context.pmWhichZone()))

sample_time_f += 0.5 # sub-second component

timevali = pmapi.timeval(sample_time_i)
timevalf = pmapi.timeval(sample_time_f)
print("timeval from int: %s" % timevali)
print("timeval from float: %s" % timevalf)

timespeci = pmapi.timespec(sample_time_i)
timespecf = pmapi.timespec(sample_time_f)
print("timespec from int: %s" % timespeci)
print("timespec from float: %s" % timespecf)
30 changes: 8 additions & 22 deletions src/pmdas/bpf/bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,33 +127,19 @@ int bpf_printfn(enum libbpf_print_level level, const char *out, va_list ap)
return 0;
}

#define WANT_MEM (100LL*1024*1024)
/**
* setrlimit required for BPF loading ... try for WANT_MEM, but will
* accept whatever we can get
* setrlimit required for BPF loading ... try for infinite memlocking
* as we have no idea how much we will really need (it depends on all
* loaded eBPF programs).
*/
void bpf_setrlimit()
{
struct rlimit rnew;
int ret;
ret = getrlimit(RLIMIT_MEMLOCK, &rnew);
if (ret < 0) {
pmNotifyErr(LOG_ERR, "bpf_setrlimit: getrlimit RMLIMIT_MEMLOCK failed: %s", pmErrStr(-errno));
return;
}
if (rnew.rlim_max == RLIM_INFINITY)
rnew.rlim_cur = rnew.rlim_max = WANT_MEM;
else if (rnew.rlim_max > WANT_MEM)
rnew.rlim_cur = rnew.rlim_max = WANT_MEM;
else {
rnew.rlim_cur = rnew.rlim_max;
pmNotifyErr(LOG_INFO, "bpf_setrlimit: setrlimit RMLIMIT_MEMLOCK %lld not %lld", (long long)rnew.rlim_cur, WANT_MEM);
}
ret = setrlimit(RLIMIT_MEMLOCK, &rnew);
if (ret == 0)
pmNotifyErr(LOG_INFO, "setrlimit RMLIMIT_MEMLOCK ok");
struct rlimit rnew = { RLIM_INFINITY, RLIM_INFINITY };

if (setrlimit(RLIMIT_MEMLOCK, &rnew) == 0)
pmNotifyErr(LOG_INFO, "setrlimit RLIMIT_MEMLOCK ok");
else
pmNotifyErr(LOG_ERR, "setrlimit RMLIMIT_MEMLOCK (%lld,%lld) failed: %s", (long long)rnew.rlim_cur, (long long)rnew.rlim_max, pmErrStr(-errno));
pmNotifyErr(LOG_ERR, "setrlimit RLIMIT_MEMLOCK (infinity) failed: %s", pmErrStr(-errno));
}

/**
Expand Down
25 changes: 17 additions & 8 deletions src/pmdas/openmetrics/Install
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/bin/sh
#
# Copyright (c) 2019 Red Hat.
#
# Copyright (c) 2019,2024 Red Hat.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
#
# Install the OpenMetrics PMDA - https://openmetrics.io/
#

Expand All @@ -23,10 +23,19 @@ python_opt=true
daemon_opt=false

#
# See pmcd(1) man page. PMDA starts up in the "not ready" state.
# When it has finished starting up, it sends a PM_ERR_PMDAREADY
# error PDU to PMCD to indicate it's ready to start processing
# requests.
# If PMDA ran as root previously, permissions will be incorrect.
#
if [ -O "$PCP_VAR_DIR/config/pmda/144.0.py" ]
then
chown $PCP_USER:$PCP_GROUP $PCP_VAR_DIR/config/pmda/144.*.py
fi

#
# Starts in not-ready state as described in the pmcd(1) man page.
# When it has completed its startup a PM_ERR_PMDAREADY error PDU
# is sent to PMCD, indicating PMDA readiness to start processing
# client requests.
#
ipc_prot="binary notready"

pmdaSetup
Expand Down
44 changes: 33 additions & 11 deletions src/python/pcp/pmapi.py.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" Wrapper module for LIBPCP - the core Performace Co-Pilot API
#
# Copyright (C) 2012-2022 Red Hat
# Copyright (C) 2012-2024 Red Hat
# Copyright (C) 2009-2012 Michael T. Werner
#
# This file is part of the "pcp" module, the python interfaces for the
Expand Down Expand Up @@ -94,9 +94,11 @@ import os
import sys
import time
import errno
import datetime
import json

from datetime import datetime
from math import modf

# constants adapted from C header file <pcp/pmapi.h>
import cpmapi as c_api

Expand Down Expand Up @@ -227,8 +229,18 @@ class timeval(Structure):
_fields_ = [("tv_sec", c_time_t),
("tv_usec", c_suseconds_t)]

def __init__(self, sec=0, usec=0):
def __init__(self, sec=0, usec=None):
Structure.__init__(self)
if usec is None:
if isinstance(sec, datetime):
epoch = datetime.utcfromtimestamp(0)
sec = float((sec - epoch).total_seconds())
if isinstance(sec, float):
ts = modf(sec)
sec = int(ts[1])
usec = int(ts[0] * 1000000)
else:
usec = 0
self.tv_sec = sec
self.tv_usec = usec

Expand Down Expand Up @@ -270,8 +282,18 @@ class timespec(Structure):
_fields_ = [("tv_sec", c_time_t),
("tv_nsec", c_long)]

def __init__(self, sec=0, nsec=0):
def __init__(self, sec=0, nsec=None):
Structure.__init__(self)
if nsec is None:
if isinstance(sec, datetime):
epoch = datetime.utcfromtimestamp(0)
sec = float((sec - epoch).total_seconds())
if isinstance(sec, float):
ts = modf(sec)
sec = int(ts[1])
nsec = int(ts[0] * 1000000000)
else:
nsec = 0
self.tv_sec = sec
self.tv_nsec = nsec

Expand Down Expand Up @@ -2900,7 +2922,7 @@ class pmContext(object):
@staticmethod
def datetime_to_secs(value, precision=c_api.PM_TIME_SEC):
""" Convert datetime value to seconds of given precision """
tdt = value - datetime.datetime.fromtimestamp(0)
tdt = value - datetime.fromtimestamp(0)
if precision == c_api.PM_TIME_SEC:
tst = (tdt.microseconds + (tdt.seconds + tdt.days * 24.0 * 3600.0) * 10.0**6) / 10.0**6
elif precision == c_api.PM_TIME_MSEC:
Expand Down Expand Up @@ -3030,8 +3052,8 @@ class fetchgroup(object):
"""
ts = self.ctx.pmLocaltime(self.value.tv_sec)
us = int(self.value.tv_nsec) // 1000
dt = datetime.datetime(ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday,
ts.tm_hour, ts.tm_min, ts.tm_sec, us, None)
dt = datetime(ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday,
ts.tm_hour, ts.tm_min, ts.tm_sec, us, None)
return dt

class fetchgroup_timeval(object):
Expand All @@ -3054,8 +3076,8 @@ class fetchgroup(object):
"""
ts = self.ctx.pmLocaltime(self.value.tv_sec)
us = int(self.value.tv_usec)
dt = datetime.datetime(ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday,
ts.tm_hour, ts.tm_min, ts.tm_sec, us, None)
dt = datetime(ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday,
ts.tm_hour, ts.tm_min, ts.tm_sec, us, None)
return dt

# create the backward compatibility alias
Expand Down Expand Up @@ -3140,8 +3162,8 @@ class fetchgroup(object):

ts = self.ctx.pmLocaltime(self.times[i].tv_sec)
us = int(self.times[i].tv_nsec) // 1000
dt = datetime.datetime(ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday,
ts.tm_hour, ts.tm_min, ts.tm_sec, us, None)
dt = datetime(ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday,
ts.tm_hour, ts.tm_min, ts.tm_sec, us, None)
# nested lambda for proper i capture
# pylint: disable=cell-var-from-loop,unnecessary-direct-lambda-call
vv.append((dt,
Expand Down
2 changes: 2 additions & 0 deletions src/selinux/pcp.fc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/usr/bin/pmie -- gen_context(system_u:object_r:pcp_pmie_exec_t,s0)
/usr/bin/pmiectl -- gen_context(system_u:object_r:pcp_pmie_exec_t,s0)
/usr/bin/pmlogger -- gen_context(system_u:object_r:pcp_pmlogger_exec_t,s0)
/usr/bin/pmlogctl -- gen_context(system_u:object_r:pcp_pmlogger_exec_t,s0)

/usr/libexec/pcp/bin/pmcd -- gen_context(system_u:object_r:pcp_pmcd_exec_t,s0)
/usr/libexec/pcp/bin/pmproxy -- gen_context(system_u:object_r:pcp_pmproxy_exec_t,s0)
Expand Down

0 comments on commit 138a945

Please sign in to comment.