metrics.py 6.05 KB
Newer Older
yoogx's avatar
yoogx committed
1 2 3 4 5 6 7 8 9 10 11
#! /usr/bin/python

import sys
import getopt
import StringIO

def printError(source, messages):
    print 'Error while calling ' , source
    for message in messages:
        print message

12
def main(argv):ne
yoogx's avatar
yoogx committed
13
    '''Test function'''
14
    import ocarina;
15
    import lmp;
16

yoogx's avatar
yoogx committed
17 18
    aadlFiles = ''
    root = ''
19

yoogx's avatar
yoogx committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    try:
        opts, args = getopt.getopt(argv,"ha:r:",["aadlFiles=","root="])
    except getopt.GetoptError:
        print 'Error in command options. Usage is:'
        print 'metrics.py -a <aadlfile>[,<aadlfile>]* -r <root object>'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'Usage is:'
            print 'metrics.py -a <aadlfile>[,<aadlfile>]* -r <root object>'
            sys.exit()
        elif opt in ("-a", "--aadlFiles"):
            aadlFiles = arg.split(',')
        elif opt in ("-r", "--root"):
            root = arg

    if root == '' :
        print 'Root object shall be defined. Usage is:'
        print 'metrics.py -a <aadlfile>[,<aadlfile>]* -r <root object>'
        sys.exit(2)
    if aadlFiles == '' :
        print 'At least one aadl file shall be loaded. Usage is:'
        print 'metrics.py -a <aadlfile>[,<aadlfile>]* -r <root object>'
        sys.exit(2)
44

yoogx's avatar
yoogx committed
45 46 47 48 49
    for aadlFile  in aadlFiles:
        err = ocarina.load(aadlFile)
        if err[3]!=[]:
            printError('ocarina.load('+aadlFile+')', err[3])
            sys.exit(2)
50
    err = ocarina.analyze()
yoogx's avatar
yoogx committed
51 52 53 54 55 56 57 58 59 60 61
    if err[3]!=[]:
        printError('ocarina.analyze()', err[3])
        sys.exit(2)
    err = ocarina.instantiate(root)
    if err[3]!=[]:
        printError('ocarina.instantiate('+root+')', err[3])
        sys.exit(2)

    print '----------------------------------------------------'
    print 'Number of Component Instances:'
    print '----------------------------------------------------'
62
    aadlInstances=lmp.getInstances('processor')[0]
yoogx's avatar
yoogx committed
63
    print '- Processors:\t\t',len(aadlInstances)
64
    aadlInstances=lmp.getInstances('process')[0]
yoogx's avatar
yoogx committed
65
    print '- Processes:\t\t',len(aadlInstances)
66
    aadlInstances=lmp.getInstances('thread')[0]
yoogx's avatar
yoogx committed
67
    print '- Threads:\t\t',len(aadlInstances)
68
    aadlInstances=lmp.getInstances('subprogram')[0]
yoogx's avatar
yoogx committed
69 70 71 72
    print '- Subprograms:\t\t',len(aadlInstances)
    print '----------------------------------------------------'
    print '           *** DECLARATIVE MODEL ***'
    print '----------------------------------------------------'
73
    aadlPackages=lmp.getPackages()[0]
yoogx's avatar
yoogx committed
74
    print 'Number of Packages:\t\t\t',len(aadlPackages)
75
    aadlCompoTypes=lmp.getComponentTypes('all')[0]
yoogx's avatar
yoogx committed
76
    print 'Number of Component Types:\t\t',len(aadlCompoTypes)
77
    aadlCompoImpl=lmp.getComponentImplementations('all')[0]
yoogx's avatar
yoogx committed
78 79 80
    print 'Number of Component Implementations:\t',len(aadlCompoImpl)
    aadlSubcomponents=[]
    for impl in aadlCompoImpl:
81
        tmp=lmp.ATN.Subcomponents(impl)[0]
yoogx's avatar
yoogx committed
82 83 84 85 86
        if tmp is not None :
            aadlSubcomponents=aadlSubcomponents+tmp
    print 'Number of Subcomponents:\t\t',len(aadlSubcomponents)
    aadlCalls=[]
    for impl in aadlCompoImpl:
87
        tmp=lmp.ATN.Calls(impl)[0]
yoogx's avatar
yoogx committed
88 89 90 91 92
        if tmp is not None :
            aadlCalls=aadlCalls+tmp
    print 'Number of Call Sequences:\t\t',len(aadlCalls)
    aadlSubprogramCalls=[]
    for call in aadlCalls:
93
        aadlSubprogramCalls=aadlSubprogramCalls+lmp.ATN.Subprogram_Calls(call)[0]
yoogx's avatar
yoogx committed
94 95 96
    print 'Number of Subprogram Calls:\t\t',len(aadlSubprogramCalls)
    aadlFeatures=[]
    for type in aadlCompoTypes:
97
        tmp=lmp.ATN.Features(type)[0]
yoogx's avatar
yoogx committed
98 99 100 101 102
        if tmp is not None :
            aadlFeatures=aadlFeatures+tmp
    print 'Number of Features:\t\t\t',len(aadlFeatures)
    aadlConnections=[]
    for impl in aadlCompoImpl:
103
        tmp=lmp.ATN.Connections(impl)[0]
yoogx's avatar
yoogx committed
104 105 106 107 108
        if tmp is not None :
            aadlConnections=aadlConnections+tmp
    print 'Number of Connections:\t\t\t',len(aadlConnections)
    aadlProperties=[]
    for elt in aadlCompoTypes+aadlCompoImpl+aadlFeatures+aadlConnections:
109
        tmp=lmp.ATN.Properties(elt)[0]
yoogx's avatar
yoogx committed
110 111 112 113
        if tmp is not None :
            aadlProperties=aadlProperties+tmp
    print 'Number of Property Associations:\t',len(aadlProperties)
    print '---- Prototypes ------------------------------------'
114
    knownAadlElt=lmp.getPrototypes()[0]
yoogx's avatar
yoogx committed
115
    print 'Number of Prototypes:\t\t\t',len(knownAadlElt)
116
    knownAadlElt=lmp.getPrototypeBindings()[0]
yoogx's avatar
yoogx committed
117 118
    print 'Number of Prototype Bindings:\t\t',len(knownAadlElt)
    print '---- Flows -----------------------------------------'
119
    knownAadlElt=lmp.getFlowSpecifications()[0]
yoogx's avatar
yoogx committed
120
    print 'Number of Flow Specifications:\t\t',len(knownAadlElt)
121
    knownAadlElt=lmp.getFlowImplementations()[0]
yoogx's avatar
yoogx committed
122 123
    print 'Number of Flow Implementations:\t\t',len(knownAadlElt)
    print '---- Modes -----------------------------------------'
124
    knownAadlElt=lmp.getModes()[0]
yoogx's avatar
yoogx committed
125
    print 'Number of Modes:\t\t\t',len(knownAadlElt)
126
    knownAadlElt=lmp.getModeTransitions()[0]
yoogx's avatar
yoogx committed
127 128
    print 'Number of Mode Transitions:\t\t',len(knownAadlElt)
    print '---- Properties ------------------------------------'
129
    aadlPropertySets=lmp.getPropertySets()[0]
yoogx's avatar
yoogx committed
130 131 132
    print 'Number of Property Sets:\t\t',len(aadlPropertySets)
    aadlPropertyTypes=[]
    for propSet in aadlPropertySets:
133
        tmp=lmp.getPropertyTypes(propSet)[0]
yoogx's avatar
yoogx committed
134 135 136 137 138
        if tmp is not None :
            aadlPropertyTypes=aadlPropertyTypes+tmp
    print 'Number of Property Types:\t\t',len(aadlPropertyTypes)
    aadlPropertyDefinitions=[]
    for propSet in aadlPropertySets:
139
        tmp=lmp.getPropertyDefinitions(propSet)[0]
yoogx's avatar
yoogx committed
140 141 142 143 144
        if tmp is not None :
            aadlPropertyDefinitions=aadlPropertyDefinitions+tmp
    print 'Number of Property Definitions:\t\t',len(aadlPropertyDefinitions)
    aadlPropertyConstants=[]
    for propSet in aadlPropertySets:
145
        tmp=lmp.getPropertyConstants(propSet)[0]
yoogx's avatar
yoogx committed
146 147 148 149
        if tmp is not None :
            aadlPropertyConstants=aadlPropertyConstants+tmp
    print 'Number of Property Constants:\t\t',len(aadlPropertyConstants)
    print '---- Annexes ---------------------------------------'
150
    aadlAnnexes=lmp.getAnnexes()[0]
yoogx's avatar
yoogx committed
151 152 153 154 155
    print 'Number of Annexes:\t\t\t',len(aadlAnnexes)

if __name__ == "__main__":
    main(sys.argv[1:])
    sys.exit (0)                       # exit