性能优化工具-perf

概述

perf 是一个强大的 Linux 性能分析工具,它可以用来收集和分析性能数据。

perf的命令有很多,下文将就其中常用的几条进行阐述


usage: perf [--version] [--help] [OPTIONS] COMMAND [ARGS]

The most commonly used perf commands are:
annotate Read perf.data (created by perf record) and display annotated code
archive Create archive with object files with build-ids found in perf.data file
bench General framework for benchmark suites
buildid-cache Manage build-id cache.
buildid-list List the buildids in a perf.data file
c2c Shared Data C2C/HITM Analyzer.
config Get and set variables in a configuration file.
daemon Run record sessions on background
data Data file related processing
diff Read perf.data files and display the differential profile
evlist List the event names in a perf.data file
ftrace simple wrapper for kernel's ftrace functionality
inject Filter to augment the events stream with additional information
iostat Show I/O performance metrics
kallsyms Searches running kernel for symbols
kvm Tool to trace/measure kvm guest os
list List all symbolic event types
mem Profile memory accesses
record Run a command and record its profile into perf.data
report Read perf.data (created by perf record) and display the profile
script Read perf.data (created by perf record) and display trace output
stat Run a command and gather performance counter statistics
test Runs sanity tests.
top System profiling tool.
version display the version of perf binary
probe Define new dynamic tracepoints
trace strace inspired tool
kmem Tool to trace/measure kernel memory properties
kwork Tool to trace/measure kernel work properties (latencies)
lock Analyze lock events
sched Tool to trace/measure scheduler properties (latencies)
timechart Tool to visualize total system behavior during a workload

See 'perf help COMMAND' for more information on a specific command.

安装

阅读更多

linux二进制文件加载源码分析

linux二进制加载

结构

linux_binfmt 用来定义二进制格式的结构,代表某种 特定的格式,比如elf

struct linux_binfmt {
struct list_head lh; // 链表头部
struct module *module; // 模块
int (*load_binary)(struct linux_binprm *); // 加载函数
int (*load_shlib)(struct file *);
#ifdef CONFIG_COREDUMP
int (*core_dump)(struct coredump_params *cprm); // coredump处理函数,如elf会有定义
unsigned long min_coredump; /* minimal dump size */
#endif
} __randomize_layout;

linux_binprm 用来存放可执行 文件的各种参数,代表可执行文件的运行时结构

阅读更多

golang上下文切换测试

引入

golang是一门高性能的编程语言,基于其轻量,高效的的Goroutine的设计,可以实现很小的协程切换开销。
本文将解释一下基本的协程相关的原理,并实际做一个小的测试,去得到其实际的切换开销

原理

协程

协程(Coroutine)是一种更轻量级的并发编程方式,他是在用户态实现的,相比于线程进程更加轻量,拥有更小的上下文切换开销,栈空间等等。
协程主要分为两种类型:

阅读更多

Enum Class Improvements for C++17, C++20 and C++23(C++17、C++20 和 C++23 的枚举类改进)

Enum Class Improvements for C++17, C++20 and C++23(C++17、C++20 和 C++23 的枚举类改进)

The evolution of the C++ language continues to bring powerful features that enhance code safety, readability, and maintainability. Among these improvements, we got changes and additions to enum class functionalities across C++17, C++20, and C++23. In this blog post, we’ll explore these advancements, focusing on initialization improvements in C++17, the introduction of the using enum keyword in C++20, and the std::to_underlying utility in C++23.

文章转载自: https://www.cppstories.com/2024/enum-improvements/

alt text
C++ 语言的演变继续带来强大的功能,可增强代码安全性、可读性和可维护性。在这些改进中,我们对 C++17、C++20 和 C++23 中的枚举类功能进行了更改和添加。在这篇博文中,我们将探讨这些改进,重点介绍 C++17 中的初始化改进、C++20 中 using enum 关键字的引入以及 C++23 中的 std::to_underlying 实用程序。

Enum Class Recap Enum 类回顾

阅读更多

使用psmisc fuser 关闭指定端口或者路径的进程

使用psmisc fuser 关闭指定端口或者路径的进程

fuser 是一个非常有用的工具,可以用来查看哪些进程正在使用特定的文件、目录、或者端口。你也可以用它来查找和终止访问特定二进制文件的进程。

查询关闭特定端口的进程

格式如下,如启动了一个端口为8080的tcp服务进程

sudo fuser 8080/tcp
阅读更多

vscode C++ 扩展clangd介绍

概要

clangd是一个基于clang的C++语言服务器, 它提供了代码补全、跳转、重构等功能。它是一个独立的项目,不是clang的一部分。它的目标是提供一个快速、可靠的C++语言服务器,以便于IDE和其他开发工具使用。

项目主页: https://clangd.llvm.org/

安装

vscode扩展商店搜索clangd,安装即可。
注意启用后,需要将原有的微软的C/C++扩展进行取消

阅读更多

Wirewhark利用ssh/nc实现抓取Linux的网络包

概述

Wireshark是一个开源的网络数据包分析器,可以实时的从网络接口捕获数据包并分析。他支持多种协议类型,是最为流行的数据包分析器。

Wireshark支持Mac和Windows版本,但是对于Linux服务器上的包,以往只能通过服务器上tcpdump后,去离线分析数据包,较为不便。

之前的文章讲过利用rpcapd实现远程抓包https://blogs.92ac.cn/2024/08/06/rpcapd/, 这种方式要求在服务器上额外编译安装rpcapd。

这里再介绍其他的几种方式。

阅读更多