12 from xml.etree
import ElementTree
16 counter, cmask, invmask, sampling_period, startatevent, storeresultsat, family
18 cmask =
map(int, cmask)
19 invmask =
map(int, invmask)
20 sampling_period =
map(int, sampling_period)
21 startatevent = int(startatevent)
23 from Configurables
import ApplicationMgr, AuditorSvc, PerfMonAuditor
26 app.AuditAlgorithms = 1
29 pfaud.EVENT0 = counter[0]
30 pfaud.SP0 = sampling_period[0]
31 pfaud.INV0 = int(invmask[0])
32 pfaud.CMASK0 = int(cmask[0])
33 pfaud.EVENT1 = counter[1]
34 pfaud.SP1 = sampling_period[1]
35 pfaud.INV1 = int(invmask[1])
36 pfaud.CMASK1 = int(cmask[1])
37 pfaud.EVENT2 = counter[2]
38 pfaud.SP2 = sampling_period[2]
39 pfaud.INV2 = int(invmask[2])
40 pfaud.CMASK2 = int(cmask[2])
41 pfaud.EVENT3 = counter[3]
42 pfaud.SP3 = sampling_period[3]
43 pfaud.INV3 = int(invmask[3])
44 pfaud.CMASK3 = int(cmask[3])
49 pfaud.PREFIX =
"%s_%s" % (storeresultsat,
"S" if sampling_period[0] > 0
else "C")
50 pfaud.SAMPLE = int(sampling_period[0] > 0)
51 pfaud.START_AT_EVENT = startatevent
59 Adds object like functionality to the standard dictionary.
65 dict.__init__(self, initdict)
68 return self.__getitem__(item)
71 self.__setitem__(item, value)
75 return self.__getitem__(
"_text")
82 Static method to wrap a dictionary recursively as an XmlDictObject
85 if isinstance(x, dict):
86 return XmlDictObject((k, XmlDictObject.Wrap(v))
for (k, v)
in x.iteritems())
87 elif isinstance(x, list):
88 return [XmlDictObject.Wrap(v)
for v
in x]
94 if isinstance(x, dict):
95 return dict((k, XmlDictObject._UnWrap(v))
for (k, v)
in x.iteritems())
96 elif isinstance(x, list):
97 return [XmlDictObject._UnWrap(v)
for v
in x]
103 Recursively converts an XmlDictObject to a standard dictionary and returns the result.
106 return XmlDictObject._UnWrap(self)
110 assert not isinstance(dictitem, list)
112 if isinstance(dictitem, dict):
113 for tag, child
in dictitem.iteritems():
114 if str(tag) ==
"_text":
115 parent.text = str(child)
116 elif isinstance(child, list):
118 for listchild
in child:
119 elem = ElementTree.Element(tag)
123 elem = ElementTree.Element(tag)
127 parent.text = str(dictitem)
132 Converts a dictionary to an XML ElementTree Element
135 roottag = xmldict.keys()[0]
136 root = ElementTree.Element(roottag)
142 nodedict = dictclass()
144 if len(node.items()) > 0:
146 nodedict.update(dict(node.items()))
151 if child.tag
in nodedict:
153 if isinstance(nodedict[child.tag], list):
155 nodedict[child.tag].append(newitem)
158 nodedict[child.tag] = [nodedict[child.tag], newitem]
161 nodedict[child.tag] = newitem
163 if node.text
is None:
166 text = node.text.strip()
168 if len(nodedict) > 0:
171 nodedict[
"_text"] = text
181 Converts an XML file or ElementTree Element to a dictionary
185 if isinstance(root, str):
186 root = ElementTree.parse(root).getroot()
187 elif not isinstance(root, ElementTree.Element):
188 raise TypeError(
"Expected ElementTree.Element or file path string")