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 [30mcolor test[0m [30;40mcolor test[0m 21 red [31mcolor test[0m [31;40mcolor test[0m 22 green [32mcolor test[0m [32;40mcolor test[0m 23 yellow [33mcolor test[0m [33;40mcolor test[0m 24 blue [34mcolor test[0m [34;40mcolor test[0m 25 magenta [35mcolor test[0m [35;40mcolor test[0m 26 cyan [36mcolor test[0m [36;40mcolor test[0m 27 white [37mcolor test[0m [37;40mcolor test[0m 28 29and now for a test of attributes: 30 31 Color Bold Faint 32 --------------------------------------------------------- 33 black [1;30mcolor test[0m [2;30mcolor test[0m 34 red [1;31mcolor test[0m [2;31mcolor test[0m 35 green [1;32mcolor test[0m [2;32mcolor test[0m 36 yellow [1;33mcolor test[0m [2;33mcolor test[0m 37 blue [1;34mcolor test[0m [2;34mcolor test[0m 38 magenta [1;35mcolor test[0m [2;35mcolor test[0m 39 cyan [1;36mcolor test[0m [2;36mcolor test[0m 40 white [1;37mcolor test[0m [2;37mcolor test[0m 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