xref: /original-bsd/usr.bin/ktrace/subr.c (revision 0842ddeb)
1 /*-
2  * Copyright (c) 1988, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)subr.c	8.2 (Berkeley) 04/28/95";
10 #endif /* not lint */
11 
12 #include <sys/param.h>
13 #include <sys/file.h>
14 #include <sys/user.h>
15 #include <sys/proc.h>
16 #include <sys/time.h>
17 #include <sys/ktrace.h>
18 
19 #include <stdio.h>
20 
21 #include "ktrace.h"
22 
23 getpoints(s)
24 	char *s;
25 {
26 	int facs = 0;
27 
28 	while (*s) {
29 		switch(*s) {
30 		case 'c':
31 			facs |= KTRFAC_SYSCALL | KTRFAC_SYSRET;
32 			break;
33 		case 'n':
34 			facs |= KTRFAC_NAMEI;
35 			break;
36 		case 'i':
37 			facs |= KTRFAC_GENIO;
38 			break;
39 		case 's':
40 			facs |= KTRFAC_PSIG;
41 			break;
42 		case 'w':
43 			facs |= KTRFAC_CSW;
44 			break;
45 		case '+':
46 			facs |= DEF_POINTS;
47 			break;
48 		default:
49 			return (-1);
50 		}
51 		s++;
52 	}
53 	return (facs);
54 }
55 
56 timevaladd(t1, t2)
57 	struct timeval *t1, *t2;
58 {
59 	t1->tv_sec += t2->tv_sec;
60 	t1->tv_usec += t2->tv_usec;
61 	timevalfix(t1);
62 }
63 
64 timevalsub(t1, t2)
65 	struct timeval *t1, *t2;
66 {
67 	t1->tv_sec -= t2->tv_sec;
68 	t1->tv_usec -= t2->tv_usec;
69 	timevalfix(t1);
70 }
71 
72 timevalfix(t1)
73 	struct timeval *t1;
74 {
75 	if (t1->tv_usec < 0) {
76 		t1->tv_sec--;
77 		t1->tv_usec += 1000000;
78 	}
79 	if (t1->tv_usec >= 1000000) {
80 		t1->tv_sec++;
81 		t1->tv_usec -= 1000000;
82 	}
83 }
84