Esempio n. 1
0
def genInlineMethods(events, classId):

    # generate the generic inlines
    if pemGlobals.dialect == 'K42':
        print '_XLC_INLINE uval'
        print "trace" + classId + "Enabled() {"
        if pemGlobals.genTraceStubs > 0:
            print "#ifdef TRACE_STUBS"
            print "\tfprintf(stderr, \"trace" + classId + "Enabled()\\n\");"
            print "#else"
        print "\treturn (kernelInfoLocal.traceInfo.mask & " + \
          pemEvent.getEventMaskMacro(classId) + ");"
        if pemGlobals.genTraceStubs > 0: print "#endif"
        print "}"
        print '\n'

    for anEvent in events:

        print '_XLC_INLINE void'
        print "Trace" + anEvent.getQualifiedSpecifier(),
        print "(",
        # print "TimestampT timestamp",

        hasListFields = 0
        printComma = 0
        for field in anEvent._fieldSeq:
            fieldType = anEvent.getFieldType(field)
            if printComma == 1: print ",",
            else: printComma = 1
            if fieldType == 'string': print "const",
            if anEvent.isListField(field):
                print pemTypes.getCType(fieldType), '*', field,
                hasListFields = 1
            else:
                print pemTypes.getCType(fieldType), field,
        print ") {"

        if pemGlobals.genTraceStubs > 0:
            print "#ifdef TRACE_STUBS"
            genPrintStatement(anEvent)
            print "#else"

        #if pemGlobals.dialect == 'K42':
        #    genK42MethodBody(anEvent, hasListFields)
        #else:
        #    genAPIMethodBody(anEvent, hasListFields)
        if pemGlobals.dialect == 'AIX':
            genAIXMethodBody(anEvent, hasListFields)
        else:
            genMethodBody(anEvent, hasListFields)

        if pemGlobals.genTraceStubs > 0: print "#endif"
        print "}\n"
Esempio n. 2
0
def genInlineMethods(events, classId):

    # generate the generic inlines
    if pemGlobals.dialect == 'K42':
        print '_XLC_INLINE uval'
        print "trace" + classId + "Enabled() {"
        if pemGlobals.genTraceStubs > 0:
            print "#ifdef TRACE_STUBS"
            print "\tfprintf(stderr, \"trace" + classId + "Enabled()\\n\");"
            print "#else"
        print "\treturn (kernelInfoLocal.traceInfo.mask & " + \
         	pemEvent.getEventMaskMacro(classId) + ");"
        if pemGlobals.genTraceStubs > 0: print "#endif"
        print "}"
        print '\n'

    for anEvent in events:

        print '_XLC_INLINE void'
        print "Trace" + anEvent.getQualifiedSpecifier(),
        print "(",
        # print "TimestampT timestamp",

        hasListFields = 0
        printComma = 0
        for field in anEvent._fieldSeq:
            fieldType = anEvent.getFieldType(field)
            if printComma == 1: print ",",
            else:               printComma = 1
            if fieldType == 'string': print "const",
            if anEvent.isListField(field):
                print pemTypes.getCType(fieldType), '*', field,
                hasListFields = 1
            else:
                print pemTypes.getCType(fieldType), field,
        print ") {"

        if pemGlobals.genTraceStubs > 0:
            print "#ifdef TRACE_STUBS"
            genPrintStatement(anEvent)
            print "#else"

        #if pemGlobals.dialect == 'K42':
        #    genK42MethodBody(anEvent, hasListFields)
        #else:
        #    genAPIMethodBody(anEvent, hasListFields)
        if pemGlobals.dialect == 'AIX':
            genAIXMethodBody(anEvent, hasListFields)
        else:
            genMethodBody(anEvent, hasListFields)
        
        if pemGlobals.genTraceStubs > 0: print "#endif"
        print "}\n"
Esempio n. 3
0
def genLayerClassDefs(layer, allClassIds, outputDir):

    fd = None
    if pemGlobals.dummyOutput == 0:
        fd = open(os.path.join(outputDir, "trace" + layer + "Classes.h"), 'w')
        sys.stdout = fd

    print "#ifndef __TRACE_" + string.upper(layer) + "_CLASSES_H_"
    print "#define __TRACE_" + string.upper(layer) + "_CLASSES_H_"
    genPreamble()

    # another hack for the K42 hw event list
    if layer == 'HW':
        if pemGlobals.hasHWEventList > 0:
            print '#include "traceHWEventList.h"\n'

    print '#define', pemEvent.getLayerIdMacro(layer),
    print pemEvent.PEMLayers[layer]

    # generate the major_id enum
    if allClassIds.has_key(layer):
        print 'enum {'
        for classId, classVal in allClassIds[layer]:
            print "\t"+ pemEvent.getEventMajorIdMacro(classId), "=", \
                  classVal, ","
        # the most awful hack until I talk to Bob about the LAST_MAJOR_ID
        if layer == 'OS':
            print "\tTRACE_LAST_MAJOR_ID_CHECK = 26,"
        print "\tTRACE_LAST_" + string.upper(layer) + "_MAJOR_ID_CHECK"
        print '};'
        print '\n'

        # generate the masks
        for classId, classVal in allClassIds[layer]:
            print "#define " + pemEvent.getEventMaskMacro(classId),
            print "(1 <<", pemEvent.getEventMajorIdMacro(classId) + ")"
        print '\n'

    print "#endif /* #ifndef __TRACE_" + string.upper(layer) + "_CLASSES_H_ */"

    if pemGlobals.dummyOutput == 0:
        sys.stdout = sys.__stdout__
        fd.close()
Esempio n. 4
0
def genLayerClassDefs(layer, allClassIds, outputDir):

    fd = None
    if pemGlobals.dummyOutput == 0:
        fd = open(os.path.join(outputDir, "trace" + layer + "Classes.h"), 'w')
        sys.stdout = fd

    print "#ifndef __TRACE_" + string.upper(layer) + "_CLASSES_H_"
    print "#define __TRACE_" + string.upper(layer) + "_CLASSES_H_"
    genPreamble()

    # another hack for the K42 hw event list
    if layer == 'HW':
        if pemGlobals.hasHWEventList > 0:
            print '#include "traceHWEventList.h"\n'
            
    print '#define', pemEvent.getLayerIdMacro(layer),  
    print pemEvent.PEMLayers[layer]
        
    # generate the major_id enum
    if allClassIds.has_key(layer):
        print 'enum {'
        for classId, classVal in allClassIds[layer]:
            print "\t"+ pemEvent.getEventMajorIdMacro(classId), "=", \
                  classVal, ","
        # the most awful hack until I talk to Bob about the LAST_MAJOR_ID
        if layer == 'OS':
            print "\tTRACE_LAST_MAJOR_ID_CHECK = 26,"
        print "\tTRACE_LAST_" + string.upper(layer) + "_MAJOR_ID_CHECK"
        print '};'
        print '\n'

        # generate the masks
        for classId, classVal in allClassIds[layer]:
            print "#define " + pemEvent.getEventMaskMacro(classId),
            print "(1 <<", pemEvent.getEventMajorIdMacro(classId) +")"
        print '\n'
        
    print "#endif /* #ifndef __TRACE_" + string.upper(layer) + "_CLASSES_H_ */"

    if pemGlobals.dummyOutput == 0:
        sys.stdout = sys.__stdout__
        fd.close()
Esempio n. 5
0
def genMethodBody(anEvent, hasListFields):

    args = anEvent.packFields()
    sortedKeys = args.keys()
    sortedKeys.sort()
    stringsCount = anEvent.countStrings()

    if pemGlobals.dialect == 'K42':
        print "\tif(unlikely(kernelInfoLocal.traceInfo.mask & " + \
              pemEvent.getEventMaskMacro(anEvent.getClassId()) + ")) {"
        funcNamePrefix = "\ttraceDefault"
        castUint64 = 'uval64'
    else:
        funcNamePrefix = "notifyEvent"
        castUint64 = 'unsigned long long'

    if hasListFields:
        # take the args and the list and pack it into an array of bytes
        print '\t\tunsigned char ___tmpBuffer[1024];'
        print '\t\tunsigned int ___listLength = 0;'
        if stringsCount > 0: print '\t\tunsigned int i;'
        currentKey = 0  # where are we with the other fields
        firstPacked = 0  # how many args are packed in this arg
        for f in anEvent.getTraceFields():
            if anEvent.isListField(f):
                fieldSize = pemTypes.getTypeRawSize(anEvent.getFieldType(f),
                                                    f + "[i]")
                memcpy = '\t\tmemcpy(&___tmpBuffer[___listLength],'

                if anEvent.getFieldType(f) == 'string':
                    print '\t\tfor(i = 0; i <', anEvent.getListCount(f), \
                          '; i++) {'
                    print '\t', memcpy, f + "[i]", ",", fieldSize, ');'
                    print '\t\t\t ___listLength +=', fieldSize, ';\n\t\t}'
                else:
                    fieldSize = fieldSize + '*' + anEvent.getListCount(f)
                    print memcpy, '(char *)', f, ",", fieldSize, ');'
                    print '\t\t___listLength +=', fieldSize, ';'
            else:
                fieldSize = pemTypes.getTypeRawSize(anEvent.getFieldType(f), f)
                if args[currentKey].count(f) == 1:
                    if firstPacked == 0:
                        # argument found as packed
                        print '\t\t*(', castUint64,\
                              '*)&___tmpBuffer[___listLength] =',\
                              args[currentKey], ';'
                        print '\t\t___listLength += 8;'
                        firstPacked = 1
                        byteSize = 0
                    byteSize = byteSize + int(fieldSize)
                    if byteSize == 8:
                        currentKey = currentKey + 1
                        firstPacked = 0
                else:
                    # argument has not been packed
                    print '\t\tmemcpy(&___tmpBuffer[___listLength],',
                    if anEvent.getFieldType(f) != 'string': print '(char *)&',
                    print f, ',', fieldSize, ');'
                    print '\t\t___listLength +=', fieldSize, ';'

        # print "\t"+ funcNamePrefix +"Pre"+ str(len(args)-2) +"Bytes (",
        print "\t" + funcNamePrefix + "Bytes (",
        genNotifyEventId(anEvent)
        #for arg in sortedKeys:
        #    print ",\n\t\t\t" + args[arg],
        #print ");"
        print ",\n\t\t\t___listLength, ___tmpBuffer);"
    elif len(args) < 8 and stringsCount == 0:
        print "\t" + funcNamePrefix + str(len(args)) + "(",
        genNotifyEventId(anEvent)
        for arg in sortedKeys:
            print ",\n\t\t\t" + args[arg],
        print ");"
    else:
        print "\t" + funcNamePrefix + "Generic(",
        genNotifyEventId(anEvent)
        print ",\n\t\t\t", str(len(args) - stringsCount), "/* word(s) */,",
        print str(stringsCount), "/* string(s) */",
        for arg in sortedKeys:
            print ",\n\t\t\t" + args[arg],
        print ");"

    if pemGlobals.dialect == 'K42':
        print "\t}"
Esempio n. 6
0
def genK42Wrappers(layerId, classId, layerEvents):

    wrappers = []
    classIdUpper = string.upper(classId)
    print "#include <trace/trace" + classId + ".h>\n"
        
    # generate the trace event macros/inlines
    fName = "trace" + classId + "Enabled"
    wrappers.append(fName)
    fName = string.lower(fName)	
    print 'inline uval'
    print fName + "() {"
    print "\treturn (kernelInfoLocal.traceInfo.mask & " + \
          pemEvent.getEventMaskMacro(classId) + ");"
    print "}"
    print '\n'
    
    # generate the generic inline functions
    # genGenericInlines(classId) 

    # a list of lists of data arguments
    dataArgs = []
    for anEvent in layerEvents[classId]:
        args = []
        for field in anEvent._fieldSeq:
            args.append(anEvent.getFieldType(field))
        if dataArgs.count(args) == 0:
            dataArgs.append(args)

    # generate all the inlines
    for args in dataArgs:
        (words, strings) = countWordsAndStrings(args)

        print 'inline void'
        fName = getMethodName(classId, args)
        wrappers.append(fName)
	fName = string.lower(fName)
        print fName + "(uval16 * minorId",
        whichArg = 0
        for arg in args:
            if arg == 'string':
                print ", "+ pemTypes.getCType(arg) + " data" + str(whichArg),
                print ", int len" + str(whichArg),
            else:
                print ", "+ pemTypes.getCType(arg) +" * data"+ str(whichArg),
            whichArg = whichArg+1
        print ") {"
        print "\t if(unlikely(kernelInfoLocal.traceInfo.mask & " + \
              pemEvent.getEventMaskMacro(classId) + ")) {"
        if strings == 0:
            print "\t\ttraceDefault" + str(len(args)),
            print "(TRACE_" + classIdUpper + "_MAJOR_ID, *minorId," + \
                  pemEvent.getLayerIdMacro(layerId),
        else:
            # add a NULL if there are string args
            whichArg = 0
            for arg in args:
                if arg == 'string':
                    print "\t\t((char *)data"+str(whichArg) + ")[len"+str(whichArg) + \
                          "] = '\\0';"
                whichArg = whichArg + 1
            print "\t\ttraceDefaultGeneric (",
            print "TRACE_" + classIdUpper + "_MAJOR_ID, *minorId," + \
                  pemEvent.getLayerIdMacro(layerId) + ",",
            print str(words) + ", " + str(strings),
        whichArg = 0
        for arg in args:
            if arg == 'string':  print ", data" + str(whichArg),
            else:                print ", *data" + str(whichArg),
            whichArg = whichArg + 1
        print ");"
        print "\t}"
        print "}\n"
Esempio n. 7
0
def genMethodBody(anEvent, hasListFields):            

    args = anEvent.packFields()
    sortedKeys = args.keys()
    sortedKeys.sort()
    stringsCount = anEvent.countStrings()
        
    if pemGlobals.dialect == 'K42':
        print "\tif(unlikely(kernelInfoLocal.traceInfo.mask & " + \
              pemEvent.getEventMaskMacro(anEvent.getClassId()) + ")) {"
        funcNamePrefix = "\ttraceDefault"
        castUint64 = 'uval64'
    else:
        funcNamePrefix = "notifyEvent"
        castUint64 = 'unsigned long long'
    
    if hasListFields:
        # take the args and the list and pack it into an array of bytes
        print '\t\tunsigned char ___tmpBuffer[1024];'
        print '\t\tunsigned int ___listLength = 0;'
        if stringsCount > 0: print '\t\tunsigned int i;'
        currentKey = 0          # where are we with the other fields
        firstPacked = 0         # how many args are packed in this arg
        for f in anEvent.getTraceFields():
            if anEvent.isListField(f):
                fieldSize = pemTypes.getTypeRawSize(anEvent.getFieldType(f),
                                                    f+"[i]")
                memcpy = '\t\tmemcpy(&___tmpBuffer[___listLength],'

                if anEvent.getFieldType(f) == 'string':
                    print '\t\tfor(i = 0; i <', anEvent.getListCount(f), \
                          '; i++) {'
                    print '\t', memcpy, f + "[i]", ",", fieldSize, ');'
                    print '\t\t\t ___listLength +=', fieldSize, ';\n\t\t}'
                else:
                    fieldSize = fieldSize + '*' + anEvent.getListCount(f)
                    print memcpy, '(char *)', f, ",", fieldSize, ');'
                    print '\t\t___listLength +=', fieldSize, ';'
            else:
                fieldSize = pemTypes.getTypeRawSize(anEvent.getFieldType(f),f)
                if args[currentKey].count(f) == 1:
                    if firstPacked == 0:
                        # argument found as packed
                        print '\t\t*(', castUint64,\
                              '*)&___tmpBuffer[___listLength] =',\
                              args[currentKey], ';'
                        print '\t\t___listLength += 8;'
                        firstPacked = 1
                        byteSize = 0
                    byteSize = byteSize + int(fieldSize)
                    if byteSize == 8:
                        currentKey = currentKey + 1
                        firstPacked = 0
                else:
                    # argument has not been packed
                    print '\t\tmemcpy(&___tmpBuffer[___listLength],',
                    if anEvent.getFieldType(f) != 'string': print '(char *)&',
                    print f, ',', fieldSize, ');'
                    print '\t\t___listLength +=', fieldSize, ';'
                
        # print "\t"+ funcNamePrefix +"Pre"+ str(len(args)-2) +"Bytes (",
        print "\t"+ funcNamePrefix +"Bytes (",
        genNotifyEventId(anEvent)
        #for arg in sortedKeys:
        #    print ",\n\t\t\t" + args[arg],
        #print ");"
        print ",\n\t\t\t___listLength, ___tmpBuffer);"
    elif len(args) < 8 and stringsCount == 0:
        print "\t" + funcNamePrefix + str(len(args)) + "(",
        genNotifyEventId(anEvent)
        for arg in sortedKeys:
            print ",\n\t\t\t" + args[arg],
        print ");"
    else:
        print "\t" + funcNamePrefix + "Generic(",
        genNotifyEventId(anEvent)
        print ",\n\t\t\t",str(len(args)-stringsCount),"/* word(s) */,",
        print str(stringsCount), "/* string(s) */",
        for arg in sortedKeys:
            print ",\n\t\t\t" + args[arg],
        print ");"

    if pemGlobals.dialect == 'K42':
        print "\t}"