A must-see for learning game server development, an introduction to common tools for C++ game server development

Introduction to common tools for C++ game server development



There are many types of tools that need to be used in the software development process. From requirement modeling to software testing, from code compilation to project management, these tools have an irreplaceable role in the project. Zhuangzi said, "My life has a limit, but my knowledge has no limit. If I have a limit, I follow the limitless, and I'm at risk." Substituting it into the project development means that if there is an indiscriminate attack on the knowledge points, it will not only lead to embarrassment that the knowledge is extensive but not in-depth, but also takes up too much effective time and affects the progress of the project. As a C++ game server developer, we are always shouldering the task of online game development and maintenance. We can give priority to learning the most common and important things for our work, and solving practical problems is the most urgent. This article introduces and guides some commonly used tools, including debuggers, memory leak detection tools, code coverage tools, packet capture tools, performance analysis tools, static code inspection tools, high cpu analysis tools, and Lua script development tools. Help inexperienced C++ server development engineers solve code problems and improve code quality, thereby improving the work efficiency of yourself and your team.


  1. Debugger

In general, debugging refers to the process of finding bugs and correcting them. If there is a defect in the code, we first need to identify the root cause of the defect, a process called debugging. Once the root cause is found, the defect can be corrected. In the software development cycle, debugging and fixing bugs can be much more time than writing code, and having handy tools to save debugging time is undoubtedly very important.

  • Under linux,  GDB (GNU symbolic debugger) is generally used for debugging. It is a free software protected by the General Public License (GPL) and can debug multiple languages. 

    • Usage reference: http://www.gnu.org/software/gdb/

    • Download address: http://ftp.gnu.org/gnu/gdb/

  • Those who have a certain understanding of GDB will find that it is difficult to debug STL with GDB. Here we recommend a debugging tool provided by GNU, implemented in python, and supports C++11 features. 

    • Usage reference: http://sourceware.org/gdb/wiki/STLSupport

    • Download address: svn co svn://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python

  • At the same time, you can use some front-end tools such as XXGDB, DDD, etc. They all have a graphical interface, so they are more convenient to use. You can also use WinGdb to use Visual Studio's IDE for Linux remote debugging. 

    • Download address: http://www.wingdb.com/

  • In addition, if you find problems related to system calls in your program, you can use strace to quickly locate them. strace can trace system calls and received signals during process execution, and put related call information in the output stream. 

    • Download address: http://sourceforge.net/projects/strace/

  • In Windows, the debugging tools that come with Visual Studio are generally used. In addition, WinDbg is also recommended . It is a very good source-level debugging tool released by Microsoft. It can be used for Kernel mode debugging and users. Mode debugging, you can also debug Dump files. 

    • Usage reference: http://www.microsoft.com/whdc/devtools/debugging/debugstart.mspx

    • Download address: http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx


2. Memory leak checking tool


Memory leaks are a common problem in many C++ code. Memory leaks are also called "storage leaks", which means that when you dynamically open up a memory space with a dynamic memory allocation function and forget to release it after use, this space is no longer available until the process ends. Occasional memory leaks may not be serious, but the following situations can lead to serious system failure: 
1) the program runs unattended and consumes more and more memory over time; 
2) the program can request unreleased memory (such as shared memory), even when the program terminates; 
3) leaks occur inside the operating system or in system-critical drivers; 
4) memory is very limited, such as in embedded systems or portable devices; 
we can use memory The leak detection tool monitors the running of the process in the test environment and obtains detailed test reports, and then breaks down the code segments with memory leaks to avoid the risk of serious failures.

  • It is recommended to use valgrind in the Linux environment , it is a toolset for locating memory related errors in c/c++ programs, functions include memory leaks, use of uninitialized memory, read/write freed memory, read/write memory out of bounds etc. 

    • Usage reference: http://valgrind.org/docs/manual/manual.html

    • Download address: http://valgrind.org/downloads/current.html

  • Windows Leaks Detector is a tool specially used to solve memory leaks in the Windows environment. It is implemented based on Win API call hooks and can detect resource leaks (memory, handles, etc.) in any Win32 application.

    • Usage reference: http://winleak.sourceforge.net/

    • Download address: http://sourceforge.net/projects/winleak/

  • If you have WinDbg installed, the  umdh tool will also be installed in the same directory as windbg.exe. The lightweight umdh can also be used to locate memory leaks and is very simple to use. 

    • Usage reference: https://msdn.microsoft.com/en-us/library/windows/hardware/ff558947(v=vs.85).aspx


3. Code coverage tools

Code coverage rate (code coverage rate) is an important indicator that reflects the degree of coverage of test cases to the software under test, and is also an important indicator to measure the progress of testing work. In the case of complex code logic, testing work often only covers obvious logic branches, while more deep logic branches are not easy to be discovered by testers. In order to ensure the coverage of the test, some developers will try to assist the tester to write all the test cases, which will not only sacrifice a lot of valuable development time, but also have a certain degree of difficulty. The most important reason is that the test is difficult to quantify. The code coverage tool is used to quantify the coverage of code testing, so that testers can intuitively find those code branches that are not covered.

  • It is recommended to use gcov in the Linux environment , which is a command-line console program distributed with gcc, usually found in the path /usr/bin/gcov. 

    • Usage reference: https://gcc.gnu.org/onlinedocs/gcc/Gcov.html

  • It is recommended to use OpenCppCoverage in the windows environment. The code is open source and easy to use. As long as the pdb file is retained, it can be instrumented for testing at runtime. The export result is a color-coded copy of the source code, which is quite intuitive for developers. 

    • Usage reference: https://opencppcoverage.codeplex.com/documentation

    • Download address: https://opencppcoverage.codeplex.com/


4. Performance Analysis Tools

The performance of software is an important inspection point for software quality. Whether it is a server or a client program, performance is the key to user experience, mainly including performance and stability. The most basic way to solve performance problems is for developers to review the code, and tools can also be used to profile the code .

  • It is recommended to use gprof in the Linux environment , which is one of the gnu binutils tools. By default, this tool is included in the Linux system. It can accurately give the time and number of function calls and the function call relationship. 

    • Usage reference: http://www.cs.utah.edu/dept/old/texinfo/as/gprof_toc.html

  • In the windows environment, you can use the profiling tool that comes with visual studio. The interface entry of the tool is Config Properties -> Linker -> Advanced -> Profile, but it requires visual studio 2008 or later. If you are using an earlier version, you can use the C++ Profiler. 

    • Download address: http://www.semdesigns.com/Products/Profilers/CppProfiler.html

  • Another well-known software is AQTime , which can collect key performance information and memory/resource allocation information when the program is running, and submit summary and detailed reports. It also provides all program optimization processing tools, including custom filtering It is a complete set of performance and debugging tools, and it is very powerful. 

    • Usage reference: http://www.codework-solutions.com/testing-tools/aqtime-java-profiling/

    • Download address: http://www.automatedqa.com/products/aqtime/index.asp


5. Network packet capture tool

Packet capture is to intercept, retransmit, edit, and dump the data packets sent and received by network transmission. It is also used to check network security, and is often used for data interception. In the process of project development, especially in B/S or C/S model projects, it is difficult to locate the interaction-related problems between the server and the client, requiring additional understanding of a lot of source code, and debugging is quite time-consuming. This is the design purpose of the network packet capture tool. For issues such as the number of protocols, protocol sequence, and whether the protocol content is consistent with the coding and design expectations, the content of the binary tcp or udp stream can be directly obtained and exported to text. It is convenient for developers to solve complex interaction problems.

  • The most commonly used in Linux environment is Tcpdump , which can completely intercept the "header" of data packets transmitted in the network to provide analysis, support filtering for network layer, protocol, host, network or port, and provide and, or , not and other logical statements to help you remove useless information. 

    • Usage reference: http://www.tcpdump.org/

    • Download address: http://www.tcpdump.org/#latest-release

  • The most commonly used under windows is wireshark , which uses WinPCAP as the interface to exchange data packets directly with the network card, and also has the function of syntax filtering. 

    • Usage reference: https://www.wireshark.org/#learnWS

    • Download address: https://www.wireshark.org/#download


6. Static code inspection tool

Static code check refers to the use of automated tool software to check program source code to analyze program behavior, and is applied to program correctness checking, security defect detection, program optimization, etc. Static code inspection promises to find existing defects in the code without the developer's effort. Of course, these promises are not guaranteed to be fulfilled. Still, a good static analysis tool is an invaluable addition to your toolbox because it can help you check your code for potential risks without running it.

  • It is recommended to use cppcheck in the Linux environment , as a supplementary check of the compiler, cppcheck performs strict logic checks on the source code of the product, including automatic variable checking, array bounds checking, class class checking, expired function call checking, The types of abnormal memory usage, release checking, memory leak checking, operating system resource release checking, unusual STL function usage checking, code formatting errors, and performance factor checking are very comprehensive. 

    • Usage reference: http://sourceforge.net/p/cppcheck/wiki/Home/

    • Download address: http://cppcheck.sourceforge.net/

  • PC-Lint can be used in the windows environment , and its functions are comparable to cppcheck. 

    • Download address: http://www.gimpel.com/html/pcl.htm

  • Since PC-Lint is a commercial software, it is not convenient for everyone to learn and use, but if you only need to use C language for development, you can use the open source program static analysis tool splint

    • Download address: http://www.splint.org/

  • In addition, introduce a C++ code specification checking tool Cpplint used by Google. If you are currently using Google C++ code specification, then it is necessary for you to use Cpplint , it is a python script that uses simple commands to verify that your code is written to the specification. It supports both linux and windows environments and can be embedded in visual studio. 

    • Download address: https://github.com/google/styleguide


7. High CPU Monitoring Tool

The High CPU monitoring tool can be used to monitor and locate processes and threads with high CPU usage, and obtain current stack information to locate code segments, which is more intuitive than profiling tools.

  • ProcDump is a command-line tool for monitoring the CPU peak value. It is suitable for the Windows environment and is used in an attach mode. When the preset CPU peak value is reached, a dump file at that time will be generated. ProcDump can also monitor hung windows and unhandled exceptions, and can dump based on the values ​​of system performance counters. It also acts as a general process dump utility that can be embedded in other scripts (like python). 

    • Download address: https://technet.microsoft.com/en-us/sysinternals/bb896653/

  • Another recommended tool in Windows environment is process explorer , which is a Windows system and application monitoring tool developed by Sysinternals, which not only combines the functions of Filemon (file monitor) and Regmon (registry monitor), Several important enhancements have also been added. Includes stability and performance improvements, powerful filtering options, revised process tree dialog (with process lifetime graph added), right-click menu to filter entries based on click position, integrated stack trace dialog with source code storage, Faster stack traces, the ability to load 32-bit log files on 64-bit Windows, monitor image (DLL and kernel-mode drivers) loading, log all operations when the system boots, and more. 

    • Usage reference: http://www.howtogeek.com/school/sysinternals-pro/lesson3/all/

    • Download address: https://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

  • There is no integrated corresponding tool found in the Linux environment, but pstack can be used to export thread stacks. In order to assist pstack to capture process and cpu related information, commands such as top, atop, pidstat, ps, and pstree are needed to monitor and locate High CPU processes. The final effect is consistent with the two tools below Windows. 

    • Usage reference: https://docs.oracle.com/cd/E19683-01/816-0210/6m6nb7mih/index.html

    • Download address: https://packages.debian.org/sid/pstack


8. Lua script development tool

Lua scripting is a dynamic language that is very closely combined with C/C++, and is itself implemented by C code. Because of its simple and efficient features, it has been successfully used in various industry software, and it has an unshakable position in the field of game development. As a game developer, it is equally important to have an efficient and easy-to-use lua development environment.

  • Because Lua syntax is relatively simple, many editing tools can provide syntax highlighting or syntax jumping functions for Lua, but there are few debugging functions. Debugging Lua is limited to adding the print function to re-run, and the debugging efficiency is very low. Therefore, it is recommended to use Lua Studio , which is suitable for the windows environment. The IDE itself has the function of beautiful code, which can be attached to any process dynamically in the form of attach for debugging, and comes with a script hotspot function performance analysis tool, which is more comprehensive. 

    • Download address: http://www.luastudio.net/

  • Eclipse LDT can be used in a Linux environment and still has debugging capabilities. 

    • Download address: http://www.eclipse.org/ldt/

  • The only static checking tool for lua is Lua-Checker , but it has special requirements for the writing of lua, depends on bison and needs to be compiled manually.

    • Download address: https://code.google.com/p/lua-checker/

  • If you just use a simple Lua syntax check, you can use the luac tool that comes with lua, the command is as follows: 

    • luac -p * .lua

  • If you want to package lua, use the following command: 

    • luac -o lua.o * .lua

  • If you need to use various network libraries, you can use luarocks  , which is similar to python's pip/ez-install. 

    • Download address: https://luarocks.org/

    • It’s normal to be confused. You don’t want to learn if you can’t learn it. You can add my 2,000 people to 487790381, share live classes every day, teach practical projects, and learn standard coding styles.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325583789&siteId=291194637