pcp
[Top] [All Lists]

Reporting archive timezone

To: pcp developers <pcp@xxxxxxxxxxx>
Subject: Reporting archive timezone
From: Marko Myllynen <myllynen@xxxxxxxxxx>
Date: Mon, 4 Jul 2016 11:10:55 +0300
Delivered-to: pcp@xxxxxxxxxxx
Organization: Red Hat
Reply-to: Marko Myllynen <myllynen@xxxxxxxxxx>
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0
Hi,

It seems that reporting of timezone from archives is not consistent
across PCP tools (pmval/pmdumptext/pmrep) when not using -Z or -z.

The QA archives pcp-atop and pcp-vmstat can be used as test cases, they
are from AEST-10/AEDT-11 as both pmdumplog(1) and pmrep(1) confirm
(using -z, both also include the mem.util.slab metric). Below is the
info shown by pmrep(1) for the pcp-vmstat archive today:

  archive: pcp-vmstat
 timezone: AEDT-11 (reporting, local is EEST-3)
    start: Mon Feb 15 15:53:01 2016
      end: Mon Feb 15 15:53:05 2016

The issue is that when the archive was created the timezone here was
not EEST-3 but EET-2 (so the real time difference was 9, not 8 hours).

pmval handles this correctly, without -Z/-z it reports first metric at
06:53:01 which was 9 hours earlier at EET-2 than 15:53 at AEDT-11.

pmdumptext/pmrep however report first metric at 07:53:03, thus they
report as it had been EEST-3 here in February. (With -Z/-z both
pmdumptext and pmrep use the correct time.)

For the pcp-atop archive we can see the same inconsistency, the real
time difference was 7 hours which pmval uses but pmdumptext/pmrep use 8
hours instead.

Below is a patch to fix pmrep to do the same as pmval. Unfortunately,
I'm not providing any concrete QA updates as I don't know how this could
be tested automatically as this is dependent on the local timezone.

Btw, I noticed this comment in the pmrep QA files:

#  we also need to filter for AEST-10 during standard timezone
#  as it appears that pmrep will report the change in -11 to -10

I'm not quite sure what this means, AFAICS pmrep report the TZ info
from the archive regardless of the local TZ and after the patch below
does the TZ change correctly when needed.

>From 45253a49198d8ce93e82cec7f3c67d45e20dd754 Mon Sep 17 00:00:00 2001
From: Marko Myllynen <myllynen@xxxxxxxxxx>
Date: Sun, 3 Jul 2016 22:40:24 +0300
Subject: [PATCH 4/6] pmrep tz handling fix

---
 qa/1069            |  6 +++---
 qa/1070            |  4 ++--
 qa/1071            |  6 +++---
 src/pmrep/pmrep.py | 20 +++++++++++++-------
 4 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/qa/1069 b/qa/1069
index ddbc1be..78353c9 100755
--- a/qa/1069
+++ b/qa/1069
@@ -35,11 +35,11 @@ _path_filter()
     #end
 }
 
-#  timezone: :Australia/Melbourne (creation, current is AEDT-11)
-#  this is not deterministic .......................... ^^^^^^^
+#  timezone: :Australia/Melbourne (reporting, current is AEDT-11)
+#  this is not deterministic ........................... ^^^^^^^
 #  and
 #  timezone: AEDT-11
-#            ^^^^ ... ditto
+#            ^^^^^^^ ... ditto
 #
 #  we also need to filter for AEST-10 during standard timezone
 #  as it appears that pmrep will report the change in -11 to -10
diff --git a/qa/1070 b/qa/1070
index f2e9192..0eade3d 100755
--- a/qa/1070
+++ b/qa/1070
@@ -39,12 +39,12 @@ _path_filter()
 }
 
 # deal with ...
-# timezone: PCP-10 (reporting, local is AEDT-11)
+# timezone: PCP-10 (reporting, current is AEDT-11)
 #
 _filter()
 {
     sed \
-       -e 's/ (reporting, local is .*)$//g' \
+       -e 's/ (reporting, current is .*)$//g' \
     #end
 }
 
diff --git a/qa/1071 b/qa/1071
index 0093a55..ce7eae1 100755
--- a/qa/1071
+++ b/qa/1071
@@ -29,11 +29,11 @@ _path_filter()
     #end
 }
 
-#  timezone: :Australia/Melbourne (creation, current is AEDT-11)
-#  this is not deterministic .......................... ^^^^^^^
+#  timezone: :Australia/Melbourne (reporting, current is AEDT-11)
+#  this is not deterministic ........................... ^^^^^^^
 #  and
 #  timezone: AEDT-11
-#            ^^^^ ... ditto
+#            ^^^^^^^ ... ditto
 #
 #  we also need to filter for AEST-10 during standard timezone
 #  as it appears that pmrep will report the change in -11 to -10
diff --git a/src/pmrep/pmrep.py b/src/pmrep/pmrep.py
index 0a91311..97b60e6 100755
--- a/src/pmrep/pmrep.py
+++ b/src/pmrep/pmrep.py
@@ -782,9 +782,11 @@ class PMReporter(object):
             pmidA[i] = c_uint(p)
         return pmidA
 
-    def get_current_tz(self):
-        """ Figure out the current timezone using the PCP convention """
+    def get_local_tz(self, set_dst=-1):
+        """ Figure out the local timezone using the PCP convention """
         dst = time.localtime().tm_isdst
+        if set_dst >= 0:
+            dst = 1 if set_dst else 0
         offset = time.altzone if dst else time.timezone
         currtz = time.tzname[dst]
         if offset:
@@ -823,14 +825,18 @@ class PMReporter(object):
                 self.delimiter = OUTSEP
 
         # Time
-        self.localtz = self.get_current_tz()
+        self.localtz = self.get_local_tz()
         if self.opts.pmGetOptionHostZone():
             os.environ['TZ'] = self.context.pmWhichZone()
             time.tzset()
         else:
-            os.environ['TZ'] = self.localtz
+            tz = self.localtz
+            if self.context.type == PM_CONTEXT_ARCHIVE:
+                # Determine correct local TZ based on DST of the archive
+                tz = 
self.get_local_tz(time.localtime(self.opts.pmGetOptionOrigin()).tm_isdst)
+            os.environ['TZ'] = tz
             time.tzset()
-            self.context.pmNewZone(self.localtz)
+            self.context.pmNewZone(tz)
         if self.opts.pmGetOptionTimezone():
             os.environ['TZ'] = self.opts.pmGetOptionTimezone()
             time.tzset()
@@ -1087,9 +1093,9 @@ class PMReporter(object):
         if self.context.type == PM_CONTEXT_LOCAL:
             host = "localhost, using DSO PMDAs"
 
-        timezone = self.get_current_tz()
+        timezone = self.get_local_tz()
         if timezone != self.localtz:
-            timezone += " (reporting, local is " + self.localtz + ")"
+            timezone += " (reporting, current is " + self.localtz + ")"
 
         self.writer.write(comm + "\n")
         if self.context.type == PM_CONTEXT_ARCHIVE:

Thanks,

-- 
Marko Myllynen

<Prev in Thread] Current Thread [Next in Thread>