]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Notes/ALLcolors_notes.txt
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Notes / ALLcolors_notes.txt
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 58 2007-10-01 13:36:29Z brendan $
6 *
7 * COPYRIGHT: Copyright (c) 2007 Brendan Gregg.
8 **************************************************************************
9
10 * The colors aren't working, I see rubbish characters
11
12 Try using a terminal that supports colors, such as gnome-terminal or dtterm.
13
14 The following text should test the spectrum of colors for your terminal.
15 Read this using "more" or "cat" (not "less" or "vim") to check if your
16 terminal will print colors, and what they will look like:
17
18         Color           Test String             Dark Background
19         ---------------------------------------------------------
20         black           \e[30mcolor test\e[0m             \e[30;40mcolor test\e[0m
21         red             \e[31mcolor test\e[0m             \e[31;40mcolor test\e[0m
22         green           \e[32mcolor test\e[0m             \e[32;40mcolor test\e[0m
23         yellow          \e[33mcolor test\e[0m             \e[33;40mcolor test\e[0m
24         blue            \e[34mcolor test\e[0m             \e[34;40mcolor test\e[0m
25         magenta         \e[35mcolor test\e[0m             \e[35;40mcolor test\e[0m
26         cyan            \e[36mcolor test\e[0m             \e[36;40mcolor test\e[0m
27         white           \e[37mcolor test\e[0m             \e[37;40mcolor test\e[0m
28
29 and now for a test of attributes:
30
31         Color           Bold                    Faint
32         ---------------------------------------------------------
33         black           \e[1;30mcolor test\e[0m           \e[2;30mcolor test\e[0m
34         red             \e[1;31mcolor test\e[0m           \e[2;31mcolor test\e[0m
35         green           \e[1;32mcolor test\e[0m           \e[2;32mcolor test\e[0m
36         yellow          \e[1;33mcolor test\e[0m           \e[2;33mcolor test\e[0m
37         blue            \e[1;34mcolor test\e[0m           \e[2;34mcolor test\e[0m
38         magenta         \e[1;35mcolor test\e[0m           \e[2;35mcolor test\e[0m
39         cyan            \e[1;36mcolor test\e[0m           \e[2;36mcolor test\e[0m
40         white           \e[1;37mcolor test\e[0m           \e[2;37mcolor test\e[0m
41
42
43 * Why so much green and violet in the toolkit scripts?
44
45 As DTrace can examine the entire software stack, it is conceivable that
46 your script could print events from many different layers each with their
47 own color. Color scripts in the DTraceToolkit generally start by tracing
48 two layers, with extra layers added by the end user as needed (you). The
49 general 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
59 How these colors will look will depend on your terminal software. Useful
60 variations can be made, for example using red/bold for kernel abstraction
61 providers (io, vminfo, ...); and red/faint for raw kernel tracing (fbt).
62
63 The color examples in this toolkit usually trace the syscall and dynamic
64 language layers, hense the green and violet.
65
66
67 * I don't like the choosen terminal colors / your colors suck
68
69 It should be easy to customize them by tweaking the script. I've tried
70 to 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
80 That way, printf() statements can print these string variables to turn
81 on and off colors, as needed. These strings contain an escape sequence to
82 inform your terminal software to change the output color. Customizations
83 can be made by tweaking the variables; refer to documentation for your
84 terminal software to see what numbers will print what colors.
85
86 For 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
113 The easiest way would be to change the script to output HTML rather than
114 escape 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
124 Other tweaks can be made to either print the output in a <pre> tagged block;
125 or as seperate lines ending in <br> along with changing the font to be
126 fixed width.
127