xref: /netbsd-src/external/cddl/dtracetoolkit/dist/Notes/ALLcolors_notes.txt (revision c29d51755812ace2e87aeefdb06cb2b4dac7087a)
1**************************************************************************
2* The following are additional notes on all programs that print a colorized
3* ("colourised") output, *color*.d.
4*
5* $Id: ALLcolors_notes.txt,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $
6*
7* COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
8**************************************************************************
9
10* The colors aren't working, I see rubbish characters
11
12Try using a terminal that supports colors, such as gnome-terminal or dtterm.
13
14The following text should test the spectrum of colors for your terminal.
15Read this using "more" or "cat" (not "less" or "vim") to check if your
16terminal will print colors, and what they will look like:
17
18	Color		Test String		Dark Background
19	---------------------------------------------------------
20	black		color test		color test
21	red		color test		color test
22	green		color test		color test
23	yellow		color test		color test
24	blue		color test		color test
25	magenta		color test		color test
26	cyan		color test		color test
27	white		color test		color test
28
29and now for a test of attributes:
30
31	Color		Bold			Faint
32	---------------------------------------------------------
33	black		color test		color test
34	red		color test		color test
35	green		color test		color test
36	yellow		color test		color test
37	blue		color test		color test
38	magenta		color test		color test
39	cyan		color test		color test
40	white		color test		color test
41
42
43* Why so much green and violet in the toolkit scripts?
44
45As DTrace can examine the entire software stack, it is conceivable that
46your script could print events from many different layers each with their
47own color. Color scripts in the DTraceToolkit generally start by tracing
48two layers, with extra layers added by the end user as needed (you). The
49general plan is:
50
51	Software Layer		Example	Provider	Color
52	-------------------------------------------------------
53	Dynamic Language	perl			violet
54	User Library		pid:libperl		blue
55	OS Library		pid:libc		cyan
56	System Calls		syscall			green
57	Kernel and Drivers	fbt			red
58
59How these colors will look will depend on your terminal software. Useful
60variations can be made, for example using red/bold for kernel abstraction
61providers (io, vminfo, ...); and red/faint for raw kernel tracing (fbt).
62
63The color examples in this toolkit usually trace the syscall and dynamic
64language layers, hense the green and violet.
65
66
67* I don't like the choosen terminal colors / your colors suck
68
69It should be easy to customize them by tweaking the script. I've tried
70to use the following convention for declaring colors in D scripts:
71
72   dtrace:::BEGIN
73   {
74           color_shell = "\033[2;35m";             /* violet, faint */
75           color_line = "\033[1;35m";              /* violet, bold */
76           color_syscall = "\033[2;32m";           /* green, faint */
77           color_off = "\033[0m";                  /* default */
78   }
79
80That way, printf() statements can print these string variables to turn
81on and off colors, as needed. These strings contain an escape sequence to
82inform your terminal software to change the output color. Customizations
83can be made by tweaking the variables; refer to documentation for your
84terminal software to see what numbers will print what colors.
85
86For my terminal (dtterm), the numbers are (from dtterm(5)):
87
88	Attributes
89
90		1	bold
91		2	faint
92
93	Forground colors
94
95		30	black
96		31	red
97		32	green
98		33	yellow
99		34	blue
100		35	magenta
101		36	cyan
102		37	white
103
104	Background colors
105
106		40	black
107		41	red
108		...	etc, as above
109
110
111* I'd like to use this colored output on a website.
112
113The easiest way would be to change the script to output HTML rather than
114escape sequences. eg:
115
116   dtrace:::BEGIN
117   {
118           color_shell = "<font color=\"#FFAAFF\">";     /* violet, faint */
119           color_line = "<font color=\"#FF44FF\">";      /* violet, bold */
120           color_syscall = "<font color=\"#44CC44\">";   /* green, faint */
121           color_off = "</font>";                        /* default */
122   }
123
124Other tweaks can be made to either print the output in a <pre> tagged block;
125or as seperate lines ending in <br> along with changing the font to be
126fixed width.
127
128