性能优化工具-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 用来存放可执行 文件的各种参数,代表可执行文件的运行时结构

阅读更多

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

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

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

查询关闭特定端口的进程

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

sudo fuser 8080/tcp
阅读更多

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

概述

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

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

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

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

阅读更多

使用proxychain去代理tcp流量

概述

问题起因是git clone 代码的时候,发现会卡住拉取不下来

因此边使用telnet工具去测试一下端口是否是通的

telnet github.com 22

如果端口通的,应该会如下图展示
alt text
否则端口是不通的。

阅读更多

Wirewhark利用rpcapd实现抓取Linux的网络包

概述

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

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

这次要推荐的一个工具叫做rpcapd, 他现是libpcap的一部分,可以用于实时远程抓包。

安装

阅读更多