pcp
[Top] [All Lists]

Re: [pcp] [RFC] pcp python patch

To: Nathan Scott <nathans@xxxxxxxxxx>
Subject: Re: [pcp] [RFC] pcp python patch
From: David Smith <dsmith@xxxxxxxxxx>
Date: Fri, 14 Nov 2014 15:17:45 -0600
Cc: pcp <pcp@xxxxxxxxxxx>
Delivered-to: pcp@xxxxxxxxxxx
In-reply-to: <615631257.11639679.1415673601327.JavaMail.zimbra@xxxxxxxxxx>
References: <54512E80.9090302@xxxxxxxxxx> <1832581184.7889066.1415166007440.JavaMail.zimbra@xxxxxxxxxx> <545A53B0.9030500@xxxxxxxxxx> <704052736.8837998.1415255680009.JavaMail.zimbra@xxxxxxxxxx> <545CEE9A.5060007@xxxxxxxxxx> <615631257.11639679.1415673601327.JavaMail.zimbra@xxxxxxxxxx>
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0
On 11/10/2014 08:40 PM, Nathan Scott wrote:
> Hi David,
> 
> ----- Original Message -----
>> [...]
>> We have 3 distinct classes of dictionaries, each treated differently.
>> During PMDA.run(), the PMDA class passes down to cpmda several dictionaries:
>>
>> (1) self._metric_names (used by cpmda.pmns_refresh)
>> (2) self._metric_oneline (used by cpmda.pmid_oneline_refresh)
>> (2) self._metric_helptext (used by cpmda.pmid_longtext_refresh)
>> (2) self._indom_oneline (used by cpmda.indom_oneline_refresh)
>> (2) self._indom_helptext (used by cpmda.indom_longtext_refresh)
>> (3) self._indomtable (used by cpmda.pmda_dispatch)
>> (3) self._metrictable (used by cpmda.pmda_dispatch)
>>
>> Dictionaries marked by (1) are passed down, used once when needed, then
>> discarded.
>>
>> Dictionaries marked by (2) are passed down and kept, used when needed,
>> never discarded.
>>
>> Dictionaries marked by (3) aren't passed down and kept. Instead the PMDA
>> class creates a string buffer for each dictionary and passes that down
>> to cpmda. This string buffer is used once and then discarded.
>>
>> I was thinking all dictionaries were treated as being in class (1) (used
>> once then discarded). That's why I was passing down everything again in
>> PMDA.__refresh_metrics(). Since I don't need to pass down items again in
>> class (2), that simplifies PMDA.__refresh_metrics() to:
>>
>> ====
>>     def __refresh_metrics(self):
>>         # Call the user's function.
>>         if self.__refresh_metrics_func:
>>             self.__refresh_metrics_func()
>>
>>         if cpmda.get_need_refresh():
>>             self.pmns_refresh()
>>             cpmda.pmda_rehash(self._indomtable, self._metrictable)
>> ====
> 
> Yeah, that's much neater - nice!
> 
>> We actually could go further here, if we can change the cpmda interface.
>> I'm not sure how set in stone it is. I'm not talking about a change to
>> the PMDA class interface here, just the cpmda interface. If we change
>> cpmda.pmda_dispatch() to take the indomtable and metrictable
>> dictionaries directly (instead of using string buffers), we could keep
>> them around for use later by pmda_rehash() - basically moving them to
>> class (2).

So, commit b2e3b5c in the pcpfans.git dsmith/dev branch does things as I
discussed above. That dramatically simplifies the changes to pmda.py (1)
and the refresh_metrics wrapper in pmda.py goes completely away.

(1) Except for one thing. I about went nuts with one problem. So we
stashed list/dictionary references down in cpmda. I'd update the
list/dictionaries in pmda.py and would see newly added metric info, but
if I cleared the metrics, I'd still get the old values. I finally
figured out the difference between 'dict = []' and 'dict.clear()'. The
former assigns a new empty dictionary while the latter clears out the
current dictionary. At the pmda.py level there really isn't any
difference, but the caused problems for cpmda which had a stashed
reference to the original dictionary, not the new one.

-- 
David Smith
dsmith@xxxxxxxxxx
Red Hat
http://www.redhat.com
256.217.0141 (direct)
256.837.0057 (fax)

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