1 #pragma lib "libdtracy.a"
2 #pragma src "/sys/src/libdtracy"
5 triggered probes run in "probe context", which involves grabbing a per-CPU lock using dtmachlock/dtmachunlock.
6 everything else in the library assumes that the calling code has grabbed a global lock (which is done in 9/port/devtracy.c).
14 typedef struct DTName DTName;
15 typedef struct DTProbe DTProbe;
16 typedef struct DTExprState DTExprState;
17 typedef struct DTAct DTAct;
18 typedef struct DTActGr DTActGr;
19 typedef struct DTClause DTClause;
20 typedef struct DTEnab DTEnab;
21 typedef struct DTChan DTChan;
22 typedef struct DTExpr DTExpr;
23 typedef struct DTProvider DTProvider;
24 typedef struct DTBuf DTBuf;
33 we assign all pairs (probe,action-group) (called an enabling or DTEnab) a unique ID.
34 we could also use probe IDs and action group IDs but using a single 32-bit ID for both is more flexible/efficient.
39 DTEnab *probnext, *probprev;
44 /* probes are never freed */
50 void *aux; /* for the provider */
57 provide() is called when the user asks for a probe that doesn't exist.
58 provide() should call dtpnew() to create probes.
59 it can use the DTName as a hint or just create all probes that it knows about.
60 the provider has to ensure not to create the same probe multiple times.
62 void (*provide)(DTProvider *, DTName);
63 int (*enable)(DTProbe *); /* enable the probe. return >= 0 for success and < 0 for failure */
64 void (*disable)(DTProbe *); /* disable the probe */
66 /* for the library, not the provider */
71 the dtracy vm is a simple RISC machine with (currently) 16 64-bit registers.
72 all operations are 64-bit.
94 DTE_LSL = 0x0B, /* logical shift left */
95 DTE_LSR = 0x0C, /* logical shift right */
96 DTE_ASR = 0x0D, /* arithmetic shift right */
97 DTE_SEQ = 0x10, /* set if equal */
98 DTE_SNE = 0x11, /* set if not equal */
99 DTE_SLT = 0x12, /* set if less than */
100 DTE_SLE = 0x13, /* set if less or equal */
102 /* immediate operations, const = 10 top bits of ab, sign extended and shifted left by 6 bottom bits */
103 DTE_LDI = 0x20, /* Rc = const */
104 DTE_XORI = 0x21, /* Rc = Rc ^ const */
106 /* if(Ra (op) Rb) PC += c; */
112 DTE_LDV = 0x40, /* R[b] = Var[a] */
114 DTE_ZXT = 0x50, /* R[c] = lower b bits of R[a], zero extended, 0 < b <= 64 */
115 DTE_SXT = 0x51, /* R[c] = lower b bits of R[a], sign extended, 0 < b <= 64 */
117 DTE_RET = 0xF0, /* RET Ra */
119 #define DTE(op,a,b,c) ((op)<<24|(a)<<16|(b)<<8|(c))
126 /* an action is an expression, plus info about what to do with the result */
129 ACTTRACE, /* record the result. size is the number of bytes used. 0 <= size <= 8 */
130 ACTTRACESTR, /* take the result to be a pointer to a null-terminated string. store it as zero-padded char[size]. */
136 /* an action group is an optional predicate and a set of actions. */
140 DTExpr *pred; /* if non-nil and evaluates to 0, skip the actions. */
144 int reclen; /* record size, including 12-byte header */
147 /* a clause list probe wildcard expressions and an action group. only used during set-up. */
154 enum { DTBUFSZ = 65536 };
160 /* a chan is the kernel representation of a client. */
168 u32int epidalloc; /* lowest unused EPID */
170 /* we have 2 buffers per cpu, one for writing and one for reading. dtcread() swaps them if empty. */
174 /* list of enablings. */
181 /* probe functions */
182 DTProbe *dtpnew(DTName, DTProvider *, void *aux);
183 int dtpmatch(DTName, DTProbe ***);
184 void dtptrigger(DTProbe *, int, uvlong, uvlong, uvlong, uvlong);
186 /* expression functions */
187 int dteverify(DTExpr *);
189 #pragma varargck type "I" u32int
191 /* action group functions */
192 void dtgpack(Fmt *, DTActGr *);
193 char *dtgunpack(char *, DTActGr **);
194 int dtgverify(DTActGr *);
195 void dtgfree(DTActGr *);
197 /* clause functions */
198 void dtclpack(Fmt *, DTClause *);
199 char *dtclunpack(char *, DTClause **);
200 void dtclfree(DTClause *);
203 DTChan *dtcnew(void);
204 void dtcfree(DTChan *);
205 int dtcaddgr(DTChan *, DTName, DTActGr *);
206 int dtcaddcl(DTChan *, DTClause *);
207 int dtcread(DTChan *, void *, int);
208 void dtcreset(DTChan *);
209 void dtcrun(DTChan *, int);
211 extern DTProvider *dtproviders[];
215 char *dtstrdup(char *);
217 /* these functions are provided by the kernel interface */
218 uvlong dttime(void); /* return current timestamp */
219 void *dtrealloc(void *, ulong);
221 void *dtmalloc(ulong);
222 void dtmachlock(int); /* lock the per-cpu lock */
223 void dtmachunlock(int); /* unlock the per-cpu lock */
224 void dtcoherence(void); /* memory barrier */
225 uvlong dtgetvar(int); /* return the value of a variable */
226 int dtpeek(uvlong, void*, int); /* safe memmemove(). returns -1 on error. */
245 extern char *dtvarnames[DTNVARS];