10 char *dtracyroot = "#Δ";
32 if(v == nil) sysfatal("malloc: %r");
34 setmalloctag(v, getcallerpc(&n));
39 erealloc(void *v, ulong n)
43 if(v == nil) sysfatal("realloc: %r");
44 setrealloctag(v, getcallerpc(&v));
62 defvar(char *name, int idx, Type *ty)
75 defvar("arg0", DTV_ARG0, type(TYPINT, 8, 1));
76 defvar("arg1", DTV_ARG1, type(TYPINT, 8, 1));
77 defvar("arg2", DTV_ARG2, type(TYPINT, 8, 1));
78 defvar("arg3", DTV_ARG3, type(TYPINT, 8, 1));
79 defvar("arg4", DTV_ARG4, type(TYPINT, 8, 1));
80 defvar("arg5", DTV_ARG5, type(TYPINT, 8, 1));
81 defvar("arg6", DTV_ARG6, type(TYPINT, 8, 1));
82 defvar("arg7", DTV_ARG7, type(TYPINT, 8, 1));
83 defvar("arg8", DTV_ARG8, type(TYPINT, 8, 1));
84 defvar("arg9", DTV_ARG9, type(TYPINT, 8, 1));
85 defvar("pid", DTV_PID, type(TYPINT, 4, 1));
86 defvar("machno", DTV_MACHNO, type(TYPINT, 4, 1));
87 defvar("time", DTV_TIME, type(TYPINT, 8, 0));
88 defvar("probe", DTV_PROBE, type(TYPSTRING));
98 snprint(buf, sizeof(buf), "%s/clone", dtracyroot);
99 ctlfd = open(buf, ORDWR);
100 if(ctlfd < 0) return -1;
101 n = read(ctlfd, buf, sizeof(buf) - 1);
104 dtracyno = strtol(buf, &p, 10);
105 if(p == buf || *p != 0){
106 werrstr("expected number reading from ctl");
109 snprint(buf, sizeof(buf), "%s/%d/buf", dtracyroot, dtracyno);
110 buffd = open(buf, OREAD);
111 if(buffd < 0) return -1;
125 prog = fmtstrflush(&f);
126 snprint(buf, sizeof(buf), "%s/%d/prog", dtracyroot, dtracyno);
127 fd = open(buf, OWRITE);
128 if(fd < 0) return -1;
129 if(write(fd, prog, strlen(prog)) < 0){
146 snprint(buf, sizeof(buf), "%s/%d/epid", dtracyroot, dtracyno);
147 bp = Bopen(buf, OREAD);
148 if(bp == nil) return -1;
149 for(; s = Brdstr(bp, '\n', 1), s != nil; free(s)){
150 if(tokenize(s, f, nelem(f)) != 4)
155 addepid(a, b, c, f[3]);
159 werrstr("epidread: invalid format");
168 static uchar buf[65536];
171 n = read(buffd, buf, sizeof(buf));
173 sysfatal("bufread: %r");
174 if(parsebuf(buf, n, bp) < 0)
175 sysfatal("parsebuf: %r");
185 extern int interrupted;
187 switch(rfork(RFPROC|RFMEM)){
188 case -1: sysfatal("rfork: %r");
192 snprint(buf, sizeof(buf), "%s/%d/aggbuf", dtracyroot, dtracyno);
193 buffd = open(buf, OREAD);
194 if(buffd < 0) sysfatal("open: %r");
196 atnotify(aggnote, 1);
198 n = read(buffd, buf, sizeof(buf));
202 sysfatal("aggbufread: %r");
204 if(aggparsebuf((uchar *) buf, n) < 0)
214 fprint(2, "usage: %s [ -d ] script\n", argv0);
221 main(int argc, char **argv)
227 case 'd': dflag = 1; break;
230 if(argc != 1) usage();
232 fmtinstall(L'α', nodetfmt);
233 fmtinstall('t', typetfmt);
234 fmtinstall(L'I', dtefmt);
235 fmtinstall(L'τ', typefmt);
236 fmtinstall(L'ε', nodefmt);
247 sysfatal("setup: %r");
249 sysfatal("progcopy: %r");
251 sysfatal("epidread: %r");
253 out = Bfdopen(1, OWRITE);
254 if(out == nil) sysfatal("Bfdopen: %r");