This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: static user probes


Maneesh Soni wrote:

Which is stap-probes.c file and why is this required?

That is just an editing problem. It isn't required


Is this .d file written by the user or generated automatically?
what is the use of it?

It is written by the user and describes the argument signature for the probes.


Do you mean, stap-probes-tstlable.c? Could you also share the .py?

Sure. Here is an stap example which will now hit a probe and print arguments and also the python script.


***** cat tstlabel.c *****  test program
#include <stdlib.h>
#include "stap-probes.h"

foo ()
{
  STAP_PROBE(tstlabel,label1);
}

bar (int i)
{
  STAP_PROBE(tstlabel,label2,i);
}

baz (int i, char* s)
{
  STAP_PROBE(tstlabel,label3,i,s);
}

main ()
{
  foo();
  bar(2);
  baz(3,"abc");
}

***** cat stap-probes.h ***** marker include file
#define STAP_PROBE(provider,probe,...)        \
  _stap_probe_ ## probe (__VA_ARGS__);

***** cat tstlabel.d ***** used to create stap-probes-tstlabel.c
provider tstlabel {
   probe label1();
   probe label2(int);
   probe label3(int, char*);
};


***** cat stap-probes-tstlabel.c ***** currently, a generated file _stap_probe_label1 () { return 1; }

_stap_probe_label2 (int a)
{
   return 1;
}

_stap_probe_label3 (int a, char* b)
{
   return 1;
}

***** cat 19180.stp ***** script to test above
probe process.mark("label1")
{
   printf("label3\n")
}

probe process.mark("label2")
{
   printf("label3 arg1=%d\n", $a)
}
probe process.mark("label3")
{
   printf("label3 arg1=%d arg2=%#x\n", $a, $b)
}


stap -c /home/scox/stap/1918/tstlabel.x 19180.stp label1 label2 arg1=2 label3 arg1=3 arg2=0x4005e8

import sys

class provider:
    arglist = dict()
    def open(self, provider):
        self.f = open(provider)
        while (True):
            line = self.f.readline()
            if (line == ""):
                break
            if (line.find("provider") > 0):
                tokens = line.split()
                self.provider = tokens[1]
            elif (line.find("probe") > 0):
                this_probe = line[line.find("probe ")+5:line.find("(")].strip()
                args = (line[line.find("(")+1:line.find(")")])
                new_args = ""
                i = 0
                c = 0
                letters = "abcdefghijklmnopqrstuvwxyz"
                while (i < len(args)):
                    if (args[i:i+1] == ","):
                        new_args = new_args + " " + letters[c] + args[i]
                        c += 1
                    else:
                        new_args = new_args + args[i]
                    i += 1
                if (len(args) > 0):
                    self.arglist[this_probe] = new_args + " " + letters[c]
    def get(self, arg):
        print arg
        if (arg in self.arglist):
            return self.arglist[arg]
        else:
            return ""

class probe:
    isopen = False
    def open(self, provider):
        if (not self.isopen):
            self.f = open("stap-probes-" + provider + ".c", "w")
        self.isopen = True
    def add(self, probe, arglist):
        self.f.write("_stap_probe_" + probe + " (" + arglist + ")\n")
        self.f.write("{\n   return 1;\n}\n\n")
    def close(self, fn):
        self.f.close()

########################################################################
# main
########################################################################

def usage ():
    print "Usage " + sys.argv[0] + " File.d File.c <File.c>..."
    sys.exit(1)

def open_file (arg):
    if (len (sys.argv) <= arg):
        return False
    try:
        file = open(sys.argv[arg], 'r')
    except IOError:
        print (sys.argv[arg] + " not found")
        sys.exit(1)
    return file

if (len (sys.argv) < 3):
    usage()

providers = provider()
providers.open(sys.argv[1])

current_file = 2
d_file = open_file(current_file)
filename = sys.argv[current_file]
p_file = probe()

while (True):
    line = d_file.readline()
    if (line == ""):
        current_file += 1
        d_file = open_file(current_file)
        if (not d_file):
            break
    if (line.find("STAP_PROBE") > 0):
        p_file.open(line[line.find("(")+1:line.find(",")])
        partial_line=line[line.find(",")+1:]
        print partial_line
        comma = partial_line.find(",")
        rparen = partial_line.find(")")
        if (comma == -1):
            token_end = rparen
        else:
            token_end = comma
        this_probe = partial_line[0:token_end].strip()
        p_file.add(this_probe,providers.get(this_probe))


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]