Ejemplo n.º 1
0
    def test(self):

        n = GafferTest.AddNode()
        cs = GafferTest.CapturingSlot(n.plugDirtiedSignal())

        n["op1"].setValue(10)
        n["op2"].setValue(20)

        self.assertEqual(len([x[0] for x in cs if x[0].isSame(n["sum"])]), 2)

        del cs[:]

        with Gaffer.DirtyPropagationScope():

            n["op1"].setValue(11)
            n["op2"].setValue(21)

        self.assertEqual(len([x[0] for x in cs if x[0].isSame(n["sum"])]), 1)
Ejemplo n.º 2
0
    def testSwitchPerformance(self):

        script = Gaffer.ScriptNode()

        def build(maxDepth, upstreamNode=None, depth=0):

            node = Gaffer.Switch()
            node.setup(Gaffer.V3iPlug())
            if upstreamNode is not None:
                node["in"][0].setInput(upstreamNode["out"])

            script.addChild(node)

            if depth < maxDepth:
                build(maxDepth, node, depth + 1)
                build(maxDepth, node, depth + 1)

        with Gaffer.DirtyPropagationScope():
            build(13)

        with GafferTest.TestRunner.PerformanceScope():
            script.serialise()
Ejemplo n.º 3
0
    def _run(self, args):

        if args["cacheMemoryLimit"].value:
            Gaffer.ValuePlug.setCacheMemoryLimit(
                1024 * 1024 * args["cacheMemoryLimit"].value)
        if args["hashCacheSizeLimit"].value:
            Gaffer.ValuePlug.setHashCacheSizeLimit(
                args["hashCacheSizeLimit"].value)

        self.__timers = collections.OrderedDict()
        self.__memory = collections.OrderedDict()

        self.__memory["Application"] = _Memory.maxRSS()

        script = Gaffer.ScriptNode()
        script["fileName"].setValue(os.path.abspath(args["script"].value))

        with _Timer() as loadingTimer:
            script.load(continueOnError=True)
        self.__timers["Loading"] = loadingTimer

        self.root()["scripts"].addChild(script)

        self.__memory["Script"] = _Memory.maxRSS(
        ) - self.__memory["Application"]

        if args["postLoadScript"].value:
            postLoadScriptExecutionContext = {"root": script}
            with Gaffer.DirtyPropagationScope():
                exec(
                    compile(
                        open(args["postLoadScript"].value).read(),
                        args["postLoadScript"].value, "exec"),
                    postLoadScriptExecutionContext,
                    postLoadScriptExecutionContext)

        if args["performanceMonitor"].value:
            self.__performanceMonitor = Gaffer.PerformanceMonitor()
        else:
            self.__performanceMonitor = None

        if args["contextMonitor"].value:
            contextMonitorRoot = None
            if args["contextMonitorRoot"].value:
                contextMonitorRoot = script.descendant(
                    args["contextMonitorRoot"].value)
                if contextMonitorRoot is None:
                    IECore.msg(
                        IECore.Msg.Level.Error, "stats",
                        "Context monitor root \"%s\" does not exist" %
                        args["contextMonitorRoot"].value)
                    return 1
            self.__contextMonitor = Gaffer.ContextMonitor(contextMonitorRoot)
        else:
            self.__contextMonitor = None

        if args["vtune"].value:
            try:
                self.__vtuneMonitor = Gaffer.VTuneMonitor()
            except AttributeError:
                self.__vtuneMonitor = None
                IECore.msg(IECore.Msg.Level.Error, "gui",
                           "unable to create requested VTune monitor")
        else:
            self.__vtuneMonitor = None

        self.__output = file(args["outputFile"].value,
                             "w") if args["outputFile"].value else sys.stdout

        self.__writeVersion(script)

        self.__output.write("\n")

        self.__writeArgs(args)

        self.__output.write("\n")

        self.__writeSettings(script)

        self.__output.write("\n")

        self.__writeVariables(script)

        self.__output.write("\n")

        if args["nodeSummary"].value:

            self.__writeNodes(script)

        if args["scene"].value:

            self.__writeScene(script, args)

        if args["image"].value:

            self.__writeImage(script, args)

        if args["task"].value:

            self.__writeTask(script, args)

        self.__output.write("\n")

        self.__writeMemory()

        self.__output.write("\n")

        self.__writePerformance(script, args)

        self.__output.write("\n")

        self.__writeContext(script, args)

        self.__output.write("\n")

        self.__output.close()

        if args["annotatedScript"].value:

            if self.__performanceMonitor is not None:
                Gaffer.MonitorAlgo.annotate(
                    script, self.__performanceMonitor,
                    Gaffer.MonitorAlgo.PerformanceMetric.TotalDuration)
                Gaffer.MonitorAlgo.annotate(
                    script, self.__performanceMonitor,
                    Gaffer.MonitorAlgo.PerformanceMetric.HashCount)
                Gaffer.MonitorAlgo.annotate(
                    script, self.__performanceMonitor,
                    Gaffer.MonitorAlgo.PerformanceMetric.ComputeCount)
            if self.__contextMonitor is not None:
                Gaffer.MonitorAlgo.annotate(script, self.__contextMonitor)

            script.serialiseToFile(args["annotatedScript"].value)

        return 0