plcopen/InstanceTagnameCollector.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Fri, 25 May 2018 18:34:05 +0300
changeset 2168 a66062a205ae
parent 1953 5736d25bb393
child 3750 f62625418bff
permissions -rw-r--r--
Build by default with optimization level -O2 for GCC

before -O0 was used by default, that caused pretty bad performance.

Amd64, i6700k, 4200MHz, GNU/Linux (non-RT kernel), gcc 7.2.0

-------------------------------------
Optimization | EN/ENO |no EN/ENO |
-------------------------------------
default | 11 | 9.5 |
-O3 | 3.9 | 5.2 |
-O2 | 4 | 4.8 |
-Os | 4.1 | 3.5 |
-Ofast | 3.9 | 5.2 |
-------------------------------------

ARM, BBB Cortex-A8, 600Mhz, GNU/Linux, gcc 4.6.3

-------------------------------------
Optimization | EN/ENO |no EN/ENO |
-------------------------------------
default | 273 | 226 |
-O3 | 141.8 | 106.2 |
-O2 | 142 | 107 |
-Os | 152.5 | 112.2 |
-Ofast | 141.7 | 106.2 |
-------------------------------------

For embedded systems with size constaints (like Cortex-Mx, AVR and so
on) I usually use -Os. It gets pretty good results. For
GNU/Linux-based systems -O2 is usually a good choice, as you see the
test results.
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     3
# This file is part of Beremiz.
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     4
# See COPYING file for copyrights details.
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     5
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     6
from __future__ import absolute_import
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
     7
from plcopen.XSLTModelQuery import XSLTModelQuery
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     8
from plcopen.types_enums import *
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
     9
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    10
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    11
class InstanceTagName(object):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    12
    """Helpers object for generating instance tagname"""
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    13
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    14
    def __init__(self):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    15
        self.TagName = None
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    16
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    17
    def GetTagName(self):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    18
        return self.TagName
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    19
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    20
    def ConfigTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    21
        self.TagName = ComputeConfigurationName(args[0][0])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    22
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    23
    def ResourceTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    24
        self.TagName = ComputeConfigurationResourceName(args[0][0], args[1][0])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    25
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    26
    def PouTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    27
        self.TagName = ComputePouName(args[0][0])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    28
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    29
    def ActionTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    30
        self.TagName = ComputePouActionName(args[0][0], args[0][1])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    31
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    32
    def TransitionTagName(self, context, *args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    33
        self.TagName = ComputePouTransitionName(args[0][0], args[0][1])
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    34
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    35
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    36
class InstanceTagnameCollector(XSLTModelQuery):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    37
    """ object for collecting instances path list"""
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    38
    def __init__(self, controller):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    39
        XSLTModelQuery.__init__(self,
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    40
                                controller,
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    41
                                "instance_tagname.xslt",
1953
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    42
                                [(name, self.FactoryCaller(name))
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    43
                                 for name in ["ConfigTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    44
                                              "ResourceTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    45
                                              "PouTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    46
                                              "ActionTagName",
5736d25bb393 PEP8 and PyLint conformance: whitespaces and stuff
Edouard Tisserant
parents: 1952
diff changeset
    47
                                              "TransitionTagName"]])
1950
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    48
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    49
    def FactoryCaller(self, funcname):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    50
        def CallFactory(*args):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    51
            return getattr(self.factory, funcname)(*args)
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    52
        return CallFactory
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    53
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    54
    def Collect(self, root, debug, instance_path):
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    55
        self.factory = InstanceTagName()
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    56
        self._process_xslt(root, debug, instance_path=instance_path)
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    57
        res = self.factory.GetTagName()
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    58
        self.factory = None
752ec68da94d GetPouInstanceTagName optimized with XSLTModelQuery.
Edouard Tisserant
parents:
diff changeset
    59
        return res