You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
taks.json: create task to build the C/C++ project.
c_cpp_properties.json: settings related to IntelliSense.
.clang-format: rules for how your code should be formatted, such as indentation, line length, spacing, and so on. It is based on a predefined style to base the formatting on (in my case, I use the Google style).
Simple Makefile for a basic build system template.
Instructions to analyze a C/C++ code performance.
TODO: To create comments for documentation, use Doxygen. It is very powerful and not so minimalist, so it might be tricky to get started. For documentation generated in the source code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"name": "My_C/C++_Linux_cfg", // used to differentiate between multiple configurations within a single project or workspace. If you have only one, this doens't make a relevant differece. You can see which config is select in the status bar
"includePath": [
"${workspaceFolder}/**", // An include path is a folder that contains header files
"/usr/include", // (such as `#include "myHeaderFile.h"`) that are included
"/usr/include/poppler" // in a source file. Add other paths here
],
"defines": [], // used to set preprocessor macros that will be applied during IntelliSense parsing. This helps the C/C++ extension understand your code better and provide accurate code completion, navigation, and error checking (?)
"compilerPath": "/usr/bin/g++", // (optional) The full path to the compiler you use to build your project to enable more accurate IntelliSense
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4 // don't edit this field. It tracks the current version. If it is wrongly changed or deleted, this file is overwritten with a minimal snippet configuration whenever it is saved
A profiler is a performance analysis tool used in software development. It measures the behavior of a program by collecting data on various aspects such as execution time, memory usage, and CPU usage. Profilers help developers identify performance bottlenecks and optimize their code. There are several types of profilers, each focusing on different aspects of performance:
CPU Profiler: Measures which parts of the code are consuming the most CPU time. This helps in identifying functions or methods that are slowing down the execution of the program.
Memory Profiler: Tracks memory usage of the application, identifying memory leaks and inefficient memory allocation that can lead to excessive memory consumption.
I/O Profiler: Monitors input/output operations, such as file reads and writes, and network activity, helping to identify slow I/O operations that may be impacting performance.
Concurrency Profiler: Analyzes multi-threaded or parallel applications, identifying issues such as thread contention, deadlocks, and suboptimal thread usage.
Profilers are essential tools for performance analysis and optimization in software development. They provide detailed insights into various performance aspects, helping developers improve the efficiency and effectiveness of their applications. Converting profiler output into dot graphs can aid in the visual analysis of performance data, making it easier to understand and address performance issues.
Example Profilers
gprof: A GNU profiler that produces a flat profile and a call graph, showing the time spent in each function and the call hierarchy.
Valgrind: A memory profiler that can detect memory leaks, memory corruption, and other memory-related issues.
perf: A performance analysis tool for Linux that can profile CPU, cache usage, and other hardware events.
VisualVM: A visual tool for profiling Java applications, providing insights into CPU and memory usage, thread activity, and more.
Instruments: A profiling tool for macOS and iOS applications, part of Xcode, that provides a variety of performance metrics.
Using gprof and gprof2dot to obtain plots
Install gprof2dot
pip install gprof2dot
Make sure certain flags are disabled
CXXFLAGS += -pg # Generate extra code to write profile information suitable for the analysis program prof (for -p) or gprof (for -pg)#CXXFLAGS += -O3 -fno-stack-protector # we don't want any optimization
Compile the program with whatever build system tool you are using.
make
Execute the program as you normally would. This will generate a profiling data file (typically named gmon.out) in the current directory.
/path/to/executable
Use gprof profiler to analyze the gmon.out file generated in the previous step along with the executable.
gprof /path/to/executable > flat_profile.txt
Obtain the graph plot from the profile performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The tasks.json file is used to define tasks that can be executed in VS Code.
// These tasks can be anything from building your project to running tests or
// cleaning up build artifacts.
// You can execute tasks defined in tasks.json directly from the Command Palette
// (Ctrl+Shift+P) by typing "Run Task" and selecting the task you want to
// execute. For example, you can run the build task to compile your project.
// This file defines a build task to compile your C/C++. If this task is the
// default one, you can press `ctrl+shift+B` to run it. Concerning how to
// build your C/C++ project, it really depends on the developer tastes and
// the project complexity. Toy projects can build it by directly running
// the compiler (`gcc` or `g++`), but real projects usualy relies on build
// systems, such as `Makefile` and `CMake`.
{
"version": "2.0.0",
"tasks": [
{
"label": "Build my C/C++ project", // when pressing Ctrl+Shift+P and selecting `Run Task`, this name will appear
"type": "shell",
"command": "make", // Change if want to use another approach
"group": {
"kind": "build", // Indicates that this task is associated with the build process (we can have other kind of tasks, such as test, cleaning, etc.)
"isDefault": true
},
"problemMatcher": { // VS Code can process the output from a task with a problem matcher. Problem matchers scan the task output text for known warning or error strings, and report these inline in the editor and in the Problems panel.
"owner": "cpp", // helps Visual Studio Code organize and present errors and warnings in a relevant context to the user. For example, if you're working on a C/C++ project and the problem matcher's owner is set to "cpp", VSCode will associate errors and warnings detected by this problem matcher with C/C++ files. "Associating" errors and warnings with a specific programming language or file type allows Visual Studio Code to provide targeted assistance and support tailored to the user's current development context
"fileLocation": ["relative", "${workspaceFolder}"], // specifies that file paths in error messages are relative to the workspace folder.