The tool for testing, debugging, and performance testing that is readily available in linux is originally titled "testing, debugging, and Performance Tools of linux", but it is not appropriate, such as gdb mentioned in this article, many Linux distributions provide it, but it is not a necessary part of Linux, but it is readily available to most Linux users. Reasonable combination of these tools can meet more complex requirements and write test scripts, which can provide great convenience for testing. This article does not involve writing specific scripts or network-related commands such as netstat and tcpdump. To facilitate reading, use a horizontal line to split the content and prompt the content under each underline. For ~ 6 These commands seem simple to be used separately, but they can exert their real power only when combined with redirection and regular expressions to form more complex functions or even automated scripts. Cmp and diff can be used for version control and compare the differences between two version files. They can also be used to compare program output. 1. cmp compares two files by byte and outputs them. If there is no option, the first difference is output. Common options:-l outputs all different bytes and displays the number of bytes (in decimal format) and each different byte (in octal format ). For example, if file1.txt is octal to 151,flie2.txt and 12, the system displays: 3 151 12 2. diff compares two files row by row. If the directory is specified, the system compares the files with the same name in the directory. The output is: number of lines in file 1 + format prompt + number of lines in file 2, where the format prompt is a, c, d, corresponding to add, change, delete. The exit value of diff has a specific meaning. 0 indicates no difference, 1 indicates finding different places, and 2 indicates an error. Common options:-y -- side-by-side are output in two columns. In this case, use | to mark different rows. <The latter is one row less than the former,> the former is one row less than the latter. You can also add the following options:-w num -- width = NUM to output a maximum of NUM (130 by default) columns. -- Left-column: only the left column of the total row is output. -C-c num -- context [= NUM]: output the context of NUM (default: 3) Row replication. The full text of both files is displayed. -U-u num -- uniied [= NUM]: output the context of NUM (default 3) Row merging. The same parts of the two files are only displayed once. -RuN generates a patch file in the format of diff-ruN file1 file2> patch. dat. Then, you can use patch file1 patch. dat to update the content of file1 to be consistent with that of file2. Sort, sum, and wc can also process files and outputs as needed. For Linux, which can redirect stdin to a file, the output processing is the same as the file processing. 3. sort outputs rows in alphabetical order. This command can process multiple files at the same time. Common options:-u remove duplicate rows-r output in descending order-n sort by number (so that 2 won't be ranked after 10)-t separate by a separator, in this case, you can use-k to specify the number of columns 4.sum to calculate the file checksum and the number of blocks occupied. The size of the checksum algorithm and block can be set according to the options. 5. Number of lines of wc output files, number of words, and number of bytes. If there is more than one file, the total number of lines will be output. Common options:-c Number of output bytes-m number of output characters-l number of output lines-w number of output words (word) 6. grep searches for content conforming to the regular expression in the text and displays it. Here we will not mention how powerful the regular expression is. Its rules can be written into a blog article separately, and many people have already done so. The following are some usage inspirations. After reading this article, we will feel that the original "Search" needs are so diverse. The example is out of "Program Design Practice": Which files use the Regexp class? % Grep Regexp *. Which file does the java class implement? % Grep 'class. * Regexp '*. How many blank lines does the java file contain? % Grep '. '*. c ++ | wc running time statistics and determination: time and gprof 7. the time usage is $ time. the executable file/command shows the total time, user time, and system time of the program running. For a program with short execution time, the running time may be displayed as 0. Because it is not collected by the program execution itself. If the time command is stopped or switched out of memory, the displayed time may be greater than the actual time. 8. gprof calculates the running time and number of calls of each function during the running of the program. This is very helpful for code optimization. Through this statistics, you can find functions with a large time-consuming ratio and a large number of calls and perform Alignment Optimization to improve program performance. For functions with less execution and less time consumption, even if there is a possibility of optimization, you do not have to worry about the optimization scheme, because the optimization of it does not significantly improve the performance. If you need gprof, you need to add the-pg option during gcc. A gmon. out file is generated. Code error: the gcc-Wall option and lint9.gcc-Wall columns this gcc option, mainly because it is easy to be ignored. The difference between investors and gamblers is that investors take advantage of every opportunity, no matter how small it is, while gamblers rely only on luck. The author suggests applying this sentence to programming, selecting all the optional warning options for the Compilation Program, and regard it as a program investment with no risk and high repayment. Do not ask "should I use this warning facility ?" "Why not use this warning facility ?" Enable all warning options unless there is an excellent reason for not doing so. 10. lint was initially used to check unportable code in C language, but now it is not just a portability check program, you can also check out the features in the code that are portable and fully compliant with the syntax but are likely to be incorrect. Lint has many versions. In Linux, splint can be used for installation through apt-get. Comprehensive debugging: gdb11.gdb is a comprehensive debugging tool that provides functions such as breakpoint, variable monitoring and setting, signal, function stack viewing, and single-step execution, I will not describe it in detail here. There are many related blog posts for reference. I have also made a record before: gdb debugging command. Others: strace12.strace strace can trace the system calls generated by a process, including parameters, return values, and execution time.