grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a ùº†jÿAã@s`dZddlmZmZddlmZmZddlZddlmZm Z ddlm Z m Z m Z m Z mZmZmZe ej d¡¡ZGdd „d eƒZGd d „d eƒZGd d „d eƒZeej_ee e e eƒe e eƒe gej_dej_eegej_e eƒej_eeegej_dej_ee eƒegej_dej_ee eƒe eƒgej_dej_ee eƒegej_dej _ee eƒe eƒgej _dej!_ee eƒee gej!_dej"_eeeegej"_dej#_eeegej#_dej$_eeeegej$_dej%_eeeeegej%_dej&_eeeegej&_e eƒej'_ee eƒeegej'_dej(_ee eƒgej(_dej)_eeeee gej)_Gdd„de*ƒZ+dS)a² Wrapper module for libpcp_mmv - PCP Memory Mapped Values library # # Copyright (C) 2013-2016,2019 Red Hat. # # This file is part of the "pcp" module, the python interfaces for the # Performance Co-Pilot toolkit. # # 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. # # Example use of this module for instrumenting a python application: from pcp import mmv, pmapi import cpmapi as pcpapi import cmmv as mmvapi instances = [ mmv.mmv_instance(0, "Anvils"), mmv.mmv_instance(1, "Rockets"), mmv.mmv_instance(2, "Giant_Rubber_Bands") ] ACME_PRODUCTS_INDOM = 61 indoms = [ mmv.mmv_indom( serial = ACME_PRODUCTS_INDOM, shorttext = "Acme products", helptext = "Most popular products produced by the Acme Corporation") ] indoms[0].set_instances(instances) metrics = [ mmv.mmv_metric( name = "products.count", item = 7, typeof = mmvapi.MMV_TYPE_U64, semantics = mmvapi.MMV_SEM_COUNTER, dimension = pmapi.pmUnits(0,0,1,0,0,pcpapi.PM_COUNT_ONE), indom = ACME_PRODUCTS_INDOM, shorttext = "Acme factory product throughput", helptext = "Monotonic increasing counter of products produced in the Acme Corporation " + "factory since starting the Acme production application. Quality guaranteed."), mmv.mmv_metric( name = "products.time", item = 8, typeof = mmvapi.MMV_TYPE_U64, semantics = mmvapi.MMV_SEM_COUNTER, dimension = pmapi.pmUnits(0,1,0,0,pcpapi.PM_TIME_USEC,0), indom = ACME_PRODUCTS_INDOM, shorttext = "Machine time spent producing Acme products") ] values = mmv.MemoryMappedValues("acme") values.add_indoms(indoms) values.add_metrics(metrics) values.start() anvils = values.lookup_mapping("products.count", "Anvils") values.set(anvils, 41) values.inc(anvils) values.stop() é)ÚpmUnitsÚ pmAtomValue)Ú MMV_NAMEMAXÚMMV_INDOM_NULLN)Ú StructureÚPOINTER)Úc_intÚc_uintÚc_longÚc_charÚc_char_pÚc_doubleÚc_void_pZpcp_mmvc@s,eZdZdZdefdeefgZdd„ZdS)Ú mmv_instancezX Maps internal to external instance identifiers, within an instance domain. ÚinternalÚexternalcCs.t |¡t|tƒs| d¡}||_||_dS©Núutf-8)rÚ__init__Ú isinstanceÚbytesÚencoderr)ÚselfÚinstÚname©rú-/usr/lib64/python3.9/site-packages/pcp/mmv.pyrcs    zmmv_instance.__init__N) Ú__name__Ú __module__Ú __qualname__Ú__doc__rr rÚ_fields_rrrrrr\s  ÿrc@sHeZdZdZdefdefdeeƒfdefdefgZd dd „Z d d „Z d S)Ú mmv_indomzÒ Represents an instance domain (for set valued metrics) Instance domains have associated instances - integer/string pairs. Defines complete indom metadata (instances, count, text and so on) ÚserialÚcountÚ instancesÚ shorttextÚhelptextÚcCsXt |¡|dur&t|tƒs&| d¡}|durBt|tƒsB| d¡}||_||_||_dSr)rrrrrr&r'r#)rr#r&r'rrrrus   zmmv_indom.__init__cCsPt|ƒ|_t|jƒ}t|jƒD]$}||j||_||j||_q ||_dS)z7 Update the instances and counts fields for this indom N)Úlenr$rÚrangerrr%)rr%Zinstance_arrayÚirrrÚ set_instancess   zmmv_indom.set_instancesN)r(r() rrrr r rrr r!rr,rrrrr"js ü r"c @sXeZdZdZdeefdefdefdefdefdefde fd e fgZ e d d fd d „Z d S)Ú mmv_metricz‹ Represents an individual metric to be exported by pmdammv Defines complete metric metadata (type, semantics, units and so on) rÚitemÚtypeofÚ semanticsÚ dimensionÚindomr&r'r(c Cs„t |¡t|tƒs| d¡}||_|dur@t|tƒs@| d¡}||_|durbt|tƒsb| d¡}||_||_||_ ||_ ||_ dSr) rrrrrrr'r&r0r/r2r.) rrr.r/r0r1r2r&r'rrrr•s     zmmv_metric.__init__N) rrrr r rrrr r r!rrrrrrr-ˆs ù r-c@sÊeZdZdZd3dd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2S)4ÚMemoryMappedValuesz» Defines a set of PCP Memory Mapped Value (MMV) metrics Creates PCP metrics from an instrumented python script via pmdammv (Performance Metrics Domain Agent for MMV) ré*cCs<t|tƒs| d¡}||_||_||_g|_g|_d|_dSr) rrrÚ_nameÚ_clusterÚ_flagsÚ_metricsÚ_indomsÚ_handle)rrÚflagsZclusterrrrrís  zMemoryMappedValues.__init__c Csšt|jƒ}|dkrt|ƒnd}t|ƒD]}|j|||<q(t|jƒ}|dkrXt|ƒnd}t|ƒD]}|j|||<qdt |j|j |j ||||¡|_ dS)z‰ Initialise the underlying library with metrics/instances. On completion of this call, we're all visible to pmdammv. rN) r)r8r-r*r9r"Ú LIBPCP_MMVÚmmv_stats_initr5r6r7r:)rZ count_metricsÚmetricsr+Z count_indomsÚindomsrrrÚstart÷s     ýzMemoryMappedValues.startcCs$|jdurt |j|j¡d|_dS)zˆ Shut down the underlying library with metrics/instances. This closes the mmap file preventing any further updates. N)r:r<Úmmv_stats_stopr5©rrrrÚstops zMemoryMappedValues.stopcCs| ¡| ¡dS)z: Cleanly stop-if-running and restart MMV export services. N)rCr@rBrrrÚrestartszMemoryMappedValues.restartcCs|jdurdSdS)z, Property flagging an active memory mapping Nré)r:rBrrrÚstarteds zMemoryMappedValues.startedcCs||_| ¡r| ¡dS)z; Make a list of instance domains visible to the MMV export N)r9rFrD)rr?rrrÚ add_indomsszMemoryMappedValues.add_indomscCs|j |¡| |j¡dS)z> Make an additional instance domain visible to the MMV export N)r9ÚappendrG)rr2rrrÚ add_indom!s zMemoryMappedValues.add_indomcCs||_| ¡r| ¡dS)z2 Make a list of metrics visible to the MMV export N)r8rFrD)rr>rrrÚ add_metrics&szMemoryMappedValues.add_metricscCs|j |¡| |j¡dS)z5 Make an additional metric visible to the MMV export N)r8rHrJ)rZmetricrrrÚ add_metric,s zMemoryMappedValues.add_metriccCsH|durt|tƒs| d¡}|dur8t|tƒs8| d¡}t |j||¡S)aô Find the memory mapping for a given metric name and instance This handle can be used to directly manipulate metric values by other interfaces in this module. This is the *preferred* technique for manipulating MMV values. It is more efficient and the alternative (name/inst lookups) is made available as a convenience only for situations where performance will not be affected by repeated (linear) name/inst lookups. Nr)rrrr<Úmmv_lookup_value_descr:©rrrrrrÚlookup_mapping2s   z!MemoryMappedValues.lookup_mappingcCst |j||¡dS)z. Increment the mapped metric by a given value N©r<Ú mmv_inc_valuer:©rÚmappingÚvaluerrrÚaddBszMemoryMappedValues.addcCst |j|d¡dS)z$ Increment the mapped metric by one rENrO©rrRrrrÚincFszMemoryMappedValues.inccCst |j||¡dS)z( Set the mapped metric to a given value N)r<Ú mmv_set_valuer:rQrrrÚsetJszMemoryMappedValues.setcCs6|durt|tƒs| d¡}t |j||t|ƒ¡dS)z/ Set the string mapped metric to a given value Nr)rrrr<Úmmv_set_stringr:r)rQrrrÚ set_stringNs zMemoryMappedValues.set_stringcCst |j|dd¡S)z„ Start a timed interval for the mapped metric The opaque handle (mapping) returned is passed to interval_end(). r)r<Úmmv_stats_interval_startr:rUrrrÚinterval_startTsz!MemoryMappedValues.interval_startcCst |j|¡S)zA End a timed interval, the metrics time is increased by interval )r<Úmmv_stats_interval_endr:rUrrrÚ interval_endZszMemoryMappedValues.interval_endcCsN|durt|tƒs| d¡}|dur8t|tƒs8| d¡}t |j|||¡dS)z9 Lookup the named metric[instance] and add a value to it Nr)rrrr<Ú mmv_stats_addr:©rrrrSrrrÚ lookup_add_s   zMemoryMappedValues.lookup_addcCsL|durt|tƒs| d¡}|dur8t|tƒs8| d¡}t |j||¡dS)z5 Lookup the named metric[instance] and add one to it Nr)rrrr<Ú mmv_stats_incr:rMrrrÚ lookup_incgs   zMemoryMappedValues.lookup_inccCsN|durt|tƒs| d¡}|dur8t|tƒs8| d¡}t |j|||¡dS)z5 Lookup the named metric[instance] and set its value Nr)rrrr<Ú mmv_stats_setr:r`rrrÚ lookup_setos   zMemoryMappedValues.lookup_setcCsJ|durt|tƒs| d¡}|dur8t|tƒs8| d¡}t |jd||¡S)z… Lookup the named metric[instance] and start an interval The opaque handle returned is passed to interval_end(). Nr)rrrr<r[r:rMrrrÚlookup_interval_startws  ÿz(MemoryMappedValues.lookup_interval_startcCsh|durt|tƒs| d¡}|dur8t|tƒs8| d¡}t|tƒsL| d¡}t |j|||t|ƒ¡dS)z< Lookup the named metric[instance] and set its string value Nr)rrrr<Úmmv_stats_set_strlenr:r))rrrÚsrrrÚlookup_set_string‚s    z$MemoryMappedValues.lookup_set_stringcCsP|durt|tƒs| d¡}|dur8t|tƒs8| d¡}t |j||||¡dS)a Lookup the named metric[instance] and set its value if found If instance is not found, fallback to using a second instance One example use is: add value to bucketN else use a catch-all bucket such as "other" Nr)rrrr<Úmmv_stats_add_fallbackr:)rrrZfallrSrrrÚlookup_add_fallbackŒs   z&MemoryMappedValues.lookup_add_fallbackcCsN|durt|tƒs| d¡}|dur8t|tƒs8| d¡}t |j|||¡dS)zà Lookup the named metric[instance] and increment its value if found If instance is not found, fallback to using a second instance One sample use is: inc value of BucketA, else inc a catch-all Nr)rrrr<Úmmv_stats_inc_fallbackr:)rrrÚfallbackrrrÚlookup_inc_fallback˜s   z&MemoryMappedValues.lookup_inc_fallbackN)rr4)rrrr rr@rCrDrFrGrIrJrKrNrTrVrXrZr\r^rarcrerfrirkrnrrrrr3æs0    r3),r Z pcp.pmapirrZcmmvrrZctypesrrrr r r r r rZCDLLÚutilZ find_libraryr<rr"r-r=ZrestypeÚargtypesrArLrPZmmv_inc_atomvaluerWZmmv_set_atomvaluerYr_rbrdrjrlr[r]rgÚobjectr3rrrrÚsbG$  þ   ÿ ÿÿ  ÿ ÿ