pcp
[Top] [All Lists]

Re: [pcp] pmrep: handle known/duplicate derived metrics

To: myllynen@xxxxxxxxxx, pcp developers <pcp@xxxxxxxxxxx>
Subject: Re: [pcp] pmrep: handle known/duplicate derived metrics
From: Ken McDonell <kenj@xxxxxxxxxxxxxxxx>
Date: Mon, 7 Dec 2015 18:40:51 +1100
Delivered-to: pcp@xxxxxxxxxxx
In-reply-to: <56652146.2090500@xxxxxxxxxx>
References: <56652146.2090500@xxxxxxxxxx>
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0
On 07/12/15 17:03, Marko Myllynen wrote:
...
--- a/src/pmrep/pmrep.py
+++ b/src/pmrep/pmrep.py
@@ -61,7 +61,7 @@ import os
  import re

  from pcp import pmapi, pmgui, pmi
-from cpmapi import PM_CONTEXT_ARCHIVE, PM_CONTEXT_HOST, PM_CONTEXT_LOCAL, 
PM_MODE_FORW, PM_MODE_INTERP, PM_ERR_TYPE, PM_ERR_EOL, PM_IN_NULL, 
PM_SEM_COUNTER, PM_TIME_MSEC, PM_TIME_SEC, PM_XTB_SET
+from cpmapi import PM_CONTEXT_ARCHIVE, PM_CONTEXT_HOST, PM_CONTEXT_LOCAL, 
PM_MODE_FORW, PM_MODE_INTERP, PM_ERR_TYPE, PM_ERR_EOL, PM_ERR_NAME, PM_IN_NULL, 
PM_SEM_COUNTER, PM_TIME_MSEC, PM_TIME_SEC, PM_XTB_SET
  from cpmapi import PM_TYPE_32, PM_TYPE_U32, PM_TYPE_64, PM_TYPE_U64, 
PM_TYPE_FLOAT, PM_TYPE_DOUBLE, PM_TYPE_STRING
  from cpmgui import PM_REC_ON, PM_REC_OFF, PM_REC_SETARG

@@ -618,7 +618,12 @@ class PMReporter(object):
                      err = ""
                      try:
                          name, expr = definition.split("=")
-                        self.context.pmRegisterDerived(name.strip(), 
expr.strip())
+                        self.context.pmLookupName(name.strip())
+                    except pmapi.pmErr as error:
+                        if error.args[0] == PM_ERR_NAME:
+                            self.context.pmRegisterDerived(name.strip(), 
expr.strip())
+                            continue
+                        err = error.message()
                      except ValueError as error:
                          err = "Invalid syntax (expected metric=expression)"
                      except Exception as error:


The check may be less necessary after my next commit (tomorrow probably) ... I have added a check below pmRegisterDerived() to reject attempts to define a derived metric with a name that collides with a real metric (this test can only be done with an open context as that is where you need to check for the name of the metric being defined ... so it may happen at the pmNewContext() if there is no context when pmRegisterDerived() is called).

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