1 import nuke
2 import socket
3 import datetime
4 import platform
5 import hardwareinfo
6
7
8 profileCategories = {
9 "ProfileStore" : nuke.PROFILE_STORE,
10 "ProfileValidate" : nuke.PROFILE_VALIDATE,
11 "ProfileRequest": nuke.PROFILE_REQUEST,
12 "ProfileEngine" : nuke.PROFILE_ENGINE,
13 }
14
21
24
26 return " " * self._indent
27
28 - def OpenTag(self, tagName, optionsDict = {}, closeTag = False):
29 xmlString = self.indentString() + "<" + tagName + ">\n"
30 if closeTag:
31 xmlString += "\n"
32 self._indent += 1
33 for dictKey, dictValue in optionsDict.iteritems():
34 xmlString += self.indentString() + "<" + dictKey + ">" + str(dictValue) + "</" + dictKey + ">\n"
35 if closeTag:
36 self._indent -= 1
37 xmlString += self.indentString() + "</" + tagName + ">\n"
38 return xmlString
39
41 self._indent -= 1
42 closeTagString = self.indentString() + "</" + tagName + ">\n"
43 return closeTagString
44
46 xmlString = ""
47 for dictKey, dictValue in dictToWrite.iteritems():
48 xmlString += self.indentString() + "<" + dictKey + ">" + str(dictValue) + "</" + dictKey + ">\n"
49 return xmlString
50
52 nodeTag = "Node"
53 if nukeNode.Class() == "Group":
54
55
56
57
58 nodeTag = "GroupNode"
59 nodeInfoDict = { "Name" : nukeNode.fullName(), "Class" : nukeNode.Class() }
60
61 if nukeNode.Class() == "Read" or nukeNode.Class() == "Write":
62 nodeInfoDict["File"] = nukeNode["file"].value()
63 xmlString = self.OpenTag(nodeTag, nodeInfoDict)
64 for catName, catVal in profileCategories.iteritems():
65 xmlString += self.OpenTag(catName)
66 if catName == "ProfileEngine":
67 info = nukeNode.performanceInfo(catVal).copy()
68 if maxEngineVal > 0:
69 perfVal = float(info["timeTakenWall"]) / float(maxEngineVal)
70 else:
71 perfVal = -1.0
72 info.update({ "ProfileEngineRelativeToMax" : perfVal })
73 xmlString += self.WriteDictInner(info)
74 else:
75 xmlString += self.WriteDictInner(nukeNode.performanceInfo(catVal))
76 xmlString += self.CloseTag(catName)
77 xmlString += self.CloseTag(nodeTag)
78 return xmlString
79
81 commandLineString = ""
82 for i in nuke.rawArgs:
83 commandLineString += i + " "
84 self._profileDesc = {
85 "ScriptName" : nuke.root().name(),
86 "NumThreads" : nuke.env["threads"],
87 "TimeStored" : str(datetime.datetime.now().replace(microsecond = 0)),
88 "CommandLine" : commandLineString
89 }
90
92 self._file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
93 self._file.write("<?xml-stylesheet type=\"text/xsl\" href=\"testStylesheet.xsl\"?>\n")
94
101
107
125
127
128
129
130 if self._file != None:
131 self._file.write(self.CloseTag("PerformanceProfile"))
132 self._file.close()
133