Bug 1284417 - Python PMAPI pmSetMode does not allow None timeval
Summary: Python PMAPI pmSetMode does not allow None timeval
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: pcp
Version: 23
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Nathan Scott
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-11-23 10:03 UTC by Marko Myllynen
Modified: 2016-04-06 14:55 UTC (History)
7 users (show)

Fixed In Version: pcp-3.10.9-1.fc23 pcp-3.10.9-1.fc22 pcp-3.11.1-1.el5
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2016-04-06 14:55:24 UTC
Type: Bug


Attachments (Terms of Use)
test.tar.gz (1.44 KB, application/x-gzip)
2015-11-24 16:05 UTC, Marko Myllynen
no flags Details

Description Marko Myllynen 2015-11-23 10:03:22 UTC
Description of problem:
From pmSetMode(1):

...
       int pmSetMode(int mode, const struct timeval *when, int delta);
...
       As  a  special  case, if when is NULL then the mode and delta arguments
       are used as described above, but the current time in the archive is not
       altered.
...

But the Python pmSetMode does not allow this:

...
    def pmSetMode(self, mode, timeVal, delta):
        """PMAPI - set interpolation mode for reading archive files
        code = pmSetMode(c_api.PM_MODE_INTERP, timeval, 0)
        """
        status = LIBPCP.pmUseContext(self.ctx)
        if status < 0:
            raise pmErr(status)
        status = LIBPCP.pmSetMode(mode, pointer(timeVal), delta)
        if status < 0:
            raise pmErr(status)
        return status
...

Comment 1 Nathan Scott 2015-11-24 00:35:51 UTC
If I'm reading the ctypes docs correctly, the patch below should work ... could you try it out Marko, if you have a use-case for this already?

cheers.


diff --git a/src/python/pcp/pmapi.py b/src/python/pcp/pmapi.py
index f9805a7..b3f126b 100644
--- a/src/python/pcp/pmapi.py
+++ b/src/python/pcp/pmapi.py
@@ -1551,7 +1551,10 @@ class pmContext(object):
         status = LIBPCP.pmUseContext(self.ctx)
         if status < 0:
             raise pmErr(status)
-        status = LIBPCP.pmSetMode(mode, pointer(timeVal), delta)
+        when = None
+        if timeVal != None:
+            when = pointer(timeVal)
+        status = LIBPCP.pmSetMode(mode, when, delta)
         if status < 0:
             raise pmErr(status)
         return status

Comment 2 Marko Myllynen 2015-11-24 16:04:55 UTC
Thanks, I tested the change and it seems to work in that sense that my test code runs. I see only one in-tree user pmSetMode(PM_MODE_FORW, NULL, 0) (src/pmlogreduce/scan.c) but I'm not yet sure would this be useful elsewhere.

However, there's also one case where the man pages could be clarified a bit:

The pmSetMode(1) man page states:

...
       As  a  special  case, if when is NULL then the mode and delta arguments
       are used as described above, but the current time in the archive is not
       altered.
...

The pmFetchArchive(1) man page states:

...
       The result is instantiated with all of the metrics (and instances) from
       the next archive record, consequently there is no notion of a  list  of
       desired  metrics,  and  the  instance  profile  of the PMAPI context is
       ignored.
...

But with code like:

...
        self.context.pmSetMode(c_api.PM_MODE_FORW, None, 0)
        while self.context.type == c_api.PM_CONTEXT_ARCHIVE and True:
            result = self.context.pmFetchArchive()
            print "Fetch @ " + str(result.contents.timestamp)
...

I see:

...
$ python ~/pmapi-test.py -a pVZ3Sj.localhost
Fetch @ 1448379062.065
Fetch @ 1448379064.064
Fetch @ 1448379066.065
...

Based on the above quotes from pmSetMode(1) and pmFetchArchive(1) I was perhaps expecting 1448379062.065 being printed repeatedly here.

I'll attach the test archive and the crude test script just in case (I see the same behaviour with both pmFetch() pmFetchArchive()).

Thanks.

Comment 3 Marko Myllynen 2015-11-24 16:05:34 UTC
Created attachment 1098255 [details]
test.tar.gz

Comment 4 Marko Myllynen 2015-11-30 15:48:37 UTC
(In reply to Marko Myllynen from comment #2)
> 
> However, there's also one case where the man pages could be clarified a bit:
> 
> Based on the above quotes from pmSetMode(1) and pmFetchArchive(1) I was
> perhaps expecting 1448379062.065 being printed repeatedly here.

Err, nevermind, I completely misunderstood/misread the pages; pmSetMode with NULL timeval doesn't alter the time during pmSetMode() call, of course pmFetchArchive() then moves it to the next record according to the mode set earlier by pmSetMode().

So no additional changes needed here.

Thanks.

Comment 5 Nathan Scott 2015-12-03 04:29:58 UTC
Fixed upstream, will be in pcp-3.10.9.

Comment 6 Fedora Update System 2015-12-17 01:54:33 UTC
pcp-3.10.9-1.fc22 has been submitted as an update to Fedora 22. https://bodhi.fedoraproject.org/updates/FEDORA-2015-d08245c076

Comment 7 Fedora Update System 2015-12-17 01:55:16 UTC
pcp-3.10.9-1.fc23 has been submitted as an update to Fedora 23. https://bodhi.fedoraproject.org/updates/FEDORA-2015-2b40815137

Comment 8 Fedora Update System 2015-12-17 02:18:04 UTC
pcp-3.10.9-1.el5 has been submitted as an update to Fedora EPEL 5. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2015-2ac90519bc

Comment 9 Fedora Update System 2015-12-17 10:26:31 UTC
pcp-3.10.9-1.fc23 has been pushed to the Fedora 23 testing repository. If problems still persist, please make note of it in this bug report.
If you want to test the update, you can install it with
$ su -c 'dnf --enablerepo=updates-testing update pcp'
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2015-2b40815137

Comment 10 Fedora Update System 2015-12-17 10:26:50 UTC
pcp-3.10.9-1.fc22 has been pushed to the Fedora 22 testing repository. If problems still persist, please make note of it in this bug report.
If you want to test the update, you can install it with
$ su -c 'dnf --enablerepo=updates-testing update pcp'
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2015-d08245c076

Comment 11 Fedora Update System 2015-12-17 12:48:55 UTC
pcp-3.10.9-1.el5 has been pushed to the Fedora EPEL 5 testing repository. If problems still persist, please make note of it in this bug report.
If you want to test the update, you can install it with
$ su -c 'yum --enablerepo=epel-testing update pcp'
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2015-2ac90519bc

Comment 12 Fedora Update System 2016-01-05 21:57:47 UTC
pcp-3.10.9-1.fc23 has been pushed to the Fedora 23 stable repository. If problems still persist, please make note of it in this bug report.

Comment 13 Fedora Update System 2016-01-05 22:54:23 UTC
pcp-3.10.9-1.fc22 has been pushed to the Fedora 22 stable repository. If problems still persist, please make note of it in this bug report.

Comment 14 Fedora Update System 2016-02-03 03:56:41 UTC
pcp-3.11.0-1.el5 has been submitted as an update to Fedora EPEL 5. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-57b7efb2d7

Comment 15 Fedora Update System 2016-02-03 22:17:18 UTC
pcp-3.11.0-1.el5 has been pushed to the Fedora EPEL 5 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-57b7efb2d7

Comment 16 Fedora Update System 2016-03-22 00:17:38 UTC
pcp-3.11.1-1.el5 has been pushed to the Fedora EPEL 5 testing repository. If problems still persist, please make note of it in this bug report.
See https://fedoraproject.org/wiki/QA:Updates_Testing for
instructions on how to install test updates.
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2016-5b519318e0

Comment 17 Fedora Update System 2016-04-06 14:53:52 UTC
pcp-3.11.1-1.el5 has been pushed to the Fedora EPEL 5 stable repository. If problems still persist, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.