xref: /dragonfly/usr.bin/flame_graph/main.c (revision 91dc43dd)
1*91dc43ddSMatthew Dillon /*
2*91dc43ddSMatthew Dillon  * Copyright (c) 2020 The DragonFly Project.  All rights reserved.
3*91dc43ddSMatthew Dillon  *
4*91dc43ddSMatthew Dillon  * This code is derived from software contributed to The DragonFly Project
5*91dc43ddSMatthew Dillon  * by Matthew Dillon <dillon@backplane.com>
6*91dc43ddSMatthew Dillon  *
7*91dc43ddSMatthew Dillon  * Redistribution and use in source and binary forms, with or without
8*91dc43ddSMatthew Dillon  * modification, are permitted provided that the following conditions
9*91dc43ddSMatthew Dillon  * are met:
10*91dc43ddSMatthew Dillon  *
11*91dc43ddSMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
12*91dc43ddSMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
13*91dc43ddSMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
14*91dc43ddSMatthew Dillon  *    notice, this list of conditions and the following disclaimer in
15*91dc43ddSMatthew Dillon  *    the documentation and/or other materials provided with the
16*91dc43ddSMatthew Dillon  *    distribution.
17*91dc43ddSMatthew Dillon  * 3. Neither the name of The DragonFly Project nor the names of its
18*91dc43ddSMatthew Dillon  *    contributors may be used to endorse or promote products derived
19*91dc43ddSMatthew Dillon  *    from this software without specific, prior written permission.
20*91dc43ddSMatthew Dillon  *
21*91dc43ddSMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22*91dc43ddSMatthew Dillon  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23*91dc43ddSMatthew Dillon  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24*91dc43ddSMatthew Dillon  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25*91dc43ddSMatthew Dillon  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26*91dc43ddSMatthew Dillon  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27*91dc43ddSMatthew Dillon  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28*91dc43ddSMatthew Dillon  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29*91dc43ddSMatthew Dillon  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30*91dc43ddSMatthew Dillon  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31*91dc43ddSMatthew Dillon  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*91dc43ddSMatthew Dillon  * SUCH DAMAGE.
33*91dc43ddSMatthew Dillon  */
34*91dc43ddSMatthew Dillon 
35*91dc43ddSMatthew Dillon #include "flame.h"
36*91dc43ddSMatthew Dillon 
37*91dc43ddSMatthew Dillon int
main(int ac,char ** av)38*91dc43ddSMatthew Dillon main(int ac, char **av)
39*91dc43ddSMatthew Dillon {
40*91dc43ddSMatthew Dillon 	int mode = 'c';
41*91dc43ddSMatthew Dillon 	int c;
42*91dc43ddSMatthew Dillon 
43*91dc43ddSMatthew Dillon 	while ((c = getopt(ac, av, "p")) != -1) {
44*91dc43ddSMatthew Dillon 		switch(c) {
45*91dc43ddSMatthew Dillon 		case 'p':
46*91dc43ddSMatthew Dillon 			mode = c;
47*91dc43ddSMatthew Dillon 			break;
48*91dc43ddSMatthew Dillon 		case 'h':
49*91dc43ddSMatthew Dillon 		default:
50*91dc43ddSMatthew Dillon 			fprintf(stderr, "flame_graph [-p]\n");
51*91dc43ddSMatthew Dillon 			exit(1);
52*91dc43ddSMatthew Dillon 		}
53*91dc43ddSMatthew Dillon 	}
54*91dc43ddSMatthew Dillon 	switch(mode) {
55*91dc43ddSMatthew Dillon 	case 'c':
56*91dc43ddSMatthew Dillon 		flame_collect_loop();
57*91dc43ddSMatthew Dillon 		break;
58*91dc43ddSMatthew Dillon 	case 'p':
59*91dc43ddSMatthew Dillon 		flame_process_loop();
60*91dc43ddSMatthew Dillon 		break;
61*91dc43ddSMatthew Dillon 	}
62*91dc43ddSMatthew Dillon 	return 0;
63*91dc43ddSMatthew Dillon }
64