- Profiling and Memory Checking Tools
- Linux, Mac OS X
- Windows
- Profiling Function Execution
- Building Apps for Profiling
- Collecting Data
- Viewing Collected Data
- Selecting Profiling Options
- Enabling Full Cache Simulation
- Enabling Branch Prediction Simulation
- Русские Блоги
- Установите Valgrind
- Как использовать Valgrind
- Информация журнала вывода
- Qtcreator использует Valgrind
Profiling and Memory Checking Tools
This is a collection of tools for profiling and memory checking. It’s mostly a summary of programs/libraries mentioned in the forums, notably in threads Advice on checking for memory leaks and dangling resources? and Other tools for Qt Development
Linux, Mac OS X
Valgrind is the tool of choice for analyzing a variety of issues on Linux and Mac OS X. It uses individual tools for specific analysis like profiling and memory checking. Qt Creator’s Analyze mode integrates Valgrind, and provides both memory checking and profiling functionality from within the IDE. Valgrind needs to be installed for that to work. Valgrind is not available on Windows, but since memory issues are usually not platform dependent, analysis can be done on Linux or Mac OS X as well.
Visualizer for Valgrind profiling results
Qt4-based GUI for the Valgrind 3.6.x and 3.7.x series
visualizer for the massif (one of the valgrind tools) output
- Heaptrack traces all memory allocations and annotates these events with stack traces. So you generally use it to find the «big spenders» of memory, whereas other tools are more focused on detecting memory leaks.
Windows
- AQTime Pro (Commercial — €539) Find Issues & Memory Leaks with Application Runtime Analysis & Performance Profiling
- Borland Bounds Checker (Commercial)
- Deleaker (Commercial — $99) Deleaker is a tool for C++ developers who want to find all possible known leaks in their projects. Detects memory, GDI and other leaks.
- Dr.Memory (Open-source) v1.9.0 | 2015-10-02 | Memory monitoring tool (Not working with Qt currently due to a bug)
- Intel Inspector XE (Commercial — $1599) Memory and Thread Debugger
- Luke Stackwalker (Open-source) v0.9.9 | 2010-12-22 | CPU profiler based on sampling
- UNICOM Systems PurifyPlus (Commercial) PurifyPlus is a runtime analysis tool suite that monitors your program as it runs and reports on key aspects of its behavior.
- Visual Leak Detector for Visual C++ 2008-2015 (Open-source) v2.4rc2 | 2014-04-06 | Visual Leak Detector is a free, robust, open-source memory leak detection system for Visual C++.
- Very Sleepy (Open-source) v0.90 | 2014-12-23 | CPU profiler based on sampling (can’t be attached to Qt processes on Windows 10 x64)
- Visual Studio Profiler (Free in Visual Studio 2013 and 2015 Community Editions) CPU Sampling, Instrumentation, .NET Memory allocation, Resource Contention
- MTuner (Free) MTuner utilizes a novel approach to memory profiling & analysis, keeping entire time-based history of memory operations.
- Memory Leak Detection Tool (Free, Open source code) High performance memory leak detection tool, 32/64-bit architectures are supported
- heob (Free, open-source) Detects buffer overruns and memory leaks. Integrated into Qt Creator.
- WonderLeak (Free) — A high performance Windows heap and handle allocation profiler.
Profiling Function Execution
You can use the Callgrind tool included in the Valgrind tool suite to detect problems that are related to executing functions. In addition, you can load the data files generated by Callgrind into the KCachegrind profile data visualization tool for browsing the performance results. After you download and install Valgrind tools and KCachegrind, you can use Callgrind and KCachegrind from Qt Creator.
Note: You can install and run Callgrind and KCachegrind locally on Linux. You can run Callgrind on a remote Linux machine or device from any development machine.
Building Apps for Profiling
Callgrind records the call history of functions that are executed when the application is run. It collects the number of instructions that are executed, their relationship to source lines, the relationships of the caller and callee between functions, and the numbers of such calls. You can also use cache simulation or branch prediction to gather information about the runtime behavior of an application. Since the run-time characteristics of debug and release build configurations differ significantly, analytical findings for one build configuration may not be relevant for the other. Profiling a debug build often finds a major part of the time being spent in low-level code, such as container implementations, while the same code does not show up in the profile of a release build of the same application due to inlining and other optimizations typically done there. Many recent compilers allow you to build an optimized application with debug information present at the same time. For example, typical options for GCC are: -g -O2 . It is advisable to use such a setup for Callgrind profiling.
Collecting Data
To analyze applications:
- In the Projects mode, select a release build configuration.
- Select Debug to open the Debug mode, and then select Callgrind on the toolbar.
- Select the «Start button» button to start the application.
- Use the application to analyze it.
- Select the «Stop button» button to view the results of the analysis in the Functions view.
Select to speed up program execution during profiling by pausing event logging. No events are counted while logging is paused.
Select to reset all event counters.
Select to discard all collected data.
Select to view the data in KCachegrind. Qt Creator launches KCachegrind and loads the data into it for visualization.
Viewing Collected Data
The results of the analysis are displayed in the Callgrind views. You can detach views and move them around. To revert the changes, select Views > Reset to Default Layout.
Select Views to show and hide views and view titles. The Visualization view is hidden by default. Select to refresh the data displayed in it when it is shown.
As an alternative to collecting data, you can select to load an external log file into the Callgrind views.
Enter a string in the Filter field to filter the results.
Move the cursor on a function in the Functions view for more information about it.
Double-click a function to view information about the calling functions in the Callers view and about the called functions in the Callees view.
Select or To move between functions in the Callee view.
To set the cost format, select $. You can view absolute or relative costs, as well as relative costs to parent. Select to view only profiling info that originated from the project.
To properly handle recursive or circular function calls, enable cycle detection by selecting O.
To remove template parameter lists when displaying function names, select <>.
Selecting Profiling Options
You can specify analyzer settings either globally for all projects or separately for each project in the run settings of the project.
To specify global settings for Valgrind, select Edit > Preferences > Analyzer. The Callgrind Profiling Options group has Callgrind options.
In the KCachegrind executable field, enter the path to the KCachegrind executable to launch.
In Extra Callgrind arguments, specify additional arguments for launching the executable.
In the Result view: Minimum event cost and Visualization: Minimum event cost fields, limit the amount of results the profiler presents and visualizes to increase profiler performance.
To show additional information about events in tooltips, select Show additional information for events in tooltips.
To collect information about the system call times, select Collect system call time. To collect the number of global bus events of the event type Ge that are executed, select Collect global bus events.
Enabling Full Cache Simulation
By default, only instruction read accesses (Ir) are counted. To fully simulate the cache, select the Enable cache simulation check box. This enables the following additional event counters:
- Cache misses on instruction reads (I1mr/I2mr)
- Data read accesses (Dr) and related cache misses (D1mr/D2mr)
- Data write accesses (Dw) and related cache misses (D1mw/D2mw)
Enabling Branch Prediction Simulation
To enable the following additional event counters, select the Enable branch prediction simulation check box:
- Number of conditional branches executed and related predictor misses (Bc/Bcm)
- Executed indirect jumps and related misses of the jump address predictor (Bi/Bim)
© 2023 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.
Русские Блоги
Поскольку QT Creator и Valgrind не зависят друг от друга, сначала после установки Valgrind, QT может использоваться для использования этой функции для обнаружения и анализа памяти.
Установите Valgrind
1. Используйте командную строку для установки
sudo apt-get install valgrind
2. Скачать и установить исходный код
tar -jxvf valgrind-3.15.0.tar.bz2.tar.bz2 cd valgrind-3.15.0 sudo ./configure #Configuration #Если заменен другой каталог установки, используйте следующую команду #./Configure -prefix =/opt/valgrind #configure каталог установки sudo make // Скомпилируйте и установите sudo make install
Просмотр номера версии подтверждения успешно
Как использовать Valgrind
Применение: valgrind [options] prog-and-args [options]:
Общие варианты, подходящие для всех инструментов Valgrind:
-Tool = наиболее часто используемые варианты. Запуск инструмента с именем ToolName в Valgrind. По умолчанию Мемхек.
H -Help отображать информацию справки.
-Персия показывает версию ядра Valgrind, и каждый инструмент имеет свои собственные версии.
Q — тихо бежит тихо и печатает только информацию об ошибках.
V -вербоза более подробная информация и увеличить статистику ошибок.
-trace-children = нет | Да отслеживание подгруппы? [Нет]
-track-fds = нет | Да, отслеживаемый дескриптор открытого файла? [НЕТ]
-Time-stamp = no | Да, увеличивайте временную метку для регистрации информации? [Нет]
-log-fd = выходной журнал в файл дескриптора [2 = stderr]
-log-file = Записать выходную информацию в файл файла fileName.pid. PID-это идентификатор программы запуска для идентификатора
-Log-file-Exactly = Информация о выводе журнала для файла
-log-file-qualifier= Получите значение переменной среды в качестве имени файла выходной информации. [Никто]
-Log-Socket = iPaddr: выходной выход порта
Информация журнала вывода
Xml = да выводат информацию в формате XML, доступен только Memcheck
-num-callers= show callers in stack traces [12]
-Error-limit = нет | Да, если слишком много ошибок, прекратите отображать новые ошибки? [Да]
-Error-ExitCode = Если обнаружена ошибка, код ошибки возвращается [0 = отключить]
-Db-attach = нет | Да ошибка, Valgrind автоматически запустит GDB отладчика. [НЕТ]
-Db -command = Опция командной строки для запуска отладчика [GDB -NW %f %P]
Применимые параметры для инструментов Memcheck:
-Лик-проверка = нет | Сводка | Полные запросы, чтобы дать подробную информацию утечку? [Сводка]
-leak-resolution=low|med|high how much bt merging in leak check [low]
-show-reachable=no|yes show reachable blocks in leak check? [no]
Qtcreator использует Valgrind
Начиная с как показано на рисунке ниже, использование относительно просто. Вы можете исследовать его самостоятельно.