xref: /original-bsd/usr.bin/ktrace/subr.c (revision 1d767c41)
1 /*-
2  * Copyright (c) 1988 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)subr.c	5.1 (Berkeley) 01/17/91";
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 #include <stdio.h>
19 #include "ktrace.h"
20 
21 getpoints(s)
22 	char *s;
23 {
24 	int facs = 0;
25 
26 	while (*s) {
27 		switch(*s) {
28 		case 'c':
29 			facs |= KTRFAC_SYSCALL | KTRFAC_SYSRET;
30 			break;
31 		case 'n':
32 			facs |= KTRFAC_NAMEI;
33 			break;
34 		case 'i':
35 			facs |= KTRFAC_GENIO;
36 			break;
37 		case 's':
38 			facs |= KTRFAC_PSIG;
39 			break;
40 		default:
41 			return (-1);
42 		}
43 		s++;
44 	}
45 	return (facs);
46 }
47 
48 timevaladd(t1, t2)
49 	struct timeval *t1, *t2;
50 {
51 	t1->tv_sec += t2->tv_sec;
52 	t1->tv_usec += t2->tv_usec;
53 	timevalfix(t1);
54 }
55 
56 timevalsub(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 timevalfix(t1)
65 	struct timeval *t1;
66 {
67 	if (t1->tv_usec < 0) {
68 		t1->tv_sec--;
69 		t1->tv_usec += 1000000;
70 	}
71 	if (t1->tv_usec >= 1000000) {
72 		t1->tv_sec++;
73 		t1->tv_usec -= 1000000;
74 	}
75 }
76