blob: c7820e56966014fa106e4cd2309651df6a97fe5f [file] [log] [blame]
Namhyung Kim0985a942012-08-16 17:14:54 +09001#include <pthread.h>
2
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -03003#include "../cache.h"
4#include "../debug.h"
Arnaldo Carvalho de Melo5c35d692011-02-09 11:38:43 -02005
Arnaldo Carvalho de Melo3f7247e2011-10-18 13:45:16 -02006
Namhyung Kim0985a942012-08-16 17:14:54 +09007pthread_mutex_t ui__lock = PTHREAD_MUTEX_INITIALIZER;
8
Arnaldo Carvalho de Melo229ade92011-01-31 18:08:39 -02009void setup_browser(bool fallback_to_pager)
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030010{
Namhyung Kim281ef542012-04-30 13:55:08 +090011 if (!isatty(1) || dump_trace)
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030012 use_browser = 0;
Namhyung Kim281ef542012-04-30 13:55:08 +090013
14 /* default to TUI */
15 if (use_browser < 0)
16 use_browser = 1;
17
18 switch (use_browser) {
19 case 2:
Namhyung Kimdc41b9b2012-04-30 13:55:09 +090020 if (perf_gtk__init() == 0)
21 break;
22 /* fall through */
Namhyung Kim281ef542012-04-30 13:55:08 +090023 case 1:
Namhyung Kimdc41b9b2012-04-30 13:55:09 +090024 use_browser = 1;
25 if (ui__init() == 0)
26 break;
27 /* fall through */
Namhyung Kim281ef542012-04-30 13:55:08 +090028 default:
Namhyung Kim21f0d422012-05-28 23:53:22 +090029 use_browser = 0;
Arnaldo Carvalho de Melo229ade92011-01-31 18:08:39 -020030 if (fallback_to_pager)
31 setup_pager();
Namhyung Kim281ef542012-04-30 13:55:08 +090032 break;
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030033 }
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030034}
35
36void exit_browser(bool wait_for_ok)
37{
Namhyung Kim281ef542012-04-30 13:55:08 +090038 switch (use_browser) {
39 case 2:
40 perf_gtk__exit(wait_for_ok);
41 break;
42
43 case 1:
44 ui__exit(wait_for_ok);
45 break;
46
47 default:
48 break;
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030049 }
50}