strace

GCC/G++选项 -Wl,--as-needed

﹥>﹥吖頭↗ 提交于 2019-11-29 04:27:39
GCC/G++提供了 -Wl,--as-needed 和 -Wl,--no-as-needed 两个选项,这两个选项一个是开启特性,一个是取消该特性。 在生成可执行文件的时候,通过 -lxxx 选项指定需要链接的库文件。以动态库为例,如果我们指定了一个需要链接的库,则连接器会在可执行文件的文件头中会记录下该库的信息。而后,在可执行文件运行的时候,动态加载器会读取文件头信息,并加载所有的链接库。在这个过程中,如果用户指定链接了一个毫不相关的库,则这个库在最终的可执行程序运行时也会被加载,如果类似这样的不相关库很多,会明显拖慢程序启动过程。 这时,通过指定 -Wl,--as-needed 选项,链接过程中,链接器会检查所有的依赖库,没有实际被引用的库,不再写入可执行文件头。最终生成的可执行文件头中包含的都是必要的链接库信息。-Wl,--no-as-needed 选项不会做这样的检查,会把用户指定的链接库完全写入可执行文件中。 举例如下: main.cc #include <iostream> int main() { std::cout << "Hello, World" << std::endl; } 1,使用 -Wl,--no-as-needed 选项,且编译时指定加载不相关的 pthread库。 g++ -Wl,--no-as-needed -o main main.cc

MySQL 连接时尽量使用 127.0.0.1 而不是 localhost

橙三吉。 提交于 2019-11-29 03:53:40
原因 Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as in your PHP configuration and leave the server field blank. localhost 使用的 Linux socket,127.0.0.1 使用的是 tcp/ip 为什么我使用 localhost 一直没出问题 因为你的本机中只有一个 mysql 进程, 如果你有一个 node1 运行在 3306, 有一个 node2 运行在 3307 mysql -u root -h localhost -P 3306 mysql -u root -h

A lot of SIGSEGV while strace'ing java process

廉价感情. 提交于 2019-11-29 03:42:33
Interesting stuff occurred while I debug one of the unit tests on CI server (maven build actually). I connect to java process with strace -ff -e trace=network -p [pid] to trace network activity of build process. And that's what I saw: Process 26324 attached Process 26325 attached (waiting for parent) Process 26325 resumed (parent 26312 ready) Process 26325 detached Process 26324 detached Process 26320 detached Process 26317 detached Process 26308 resumed [pid 26308] --- SIGCHLD (Child exited) @ 0 (0) --- Process 26307 resumed Process 26308 detached [pid 26310] --- SIGCHLD (Child exited) @ 0 (0

深入理解 Linux磁盘顺序写、随机写

佐手、 提交于 2019-11-29 02:40:45
Linux 磁盘管理好坏直接关系到整个系统的性能问题。Linux磁盘管理常用三个 命令 为df、du和fdisk。 一、前言 ● 随机写会导致磁头不停地换道,造成效率的极大降低;顺序写磁头几乎不用换道,或者换道的时间很短 ● 本文来讨论一下两者具体的差别以及相应的内核调用 二、环境准备 组件 版本 OS Ubuntu 16.04.4 LTS fio 2.2.10 三、fio介绍 通过fio测试,能够反映在读写中的状态,我们需要重点关注fio的输出报告中的几个关键指标: slat :是指从 I/O 提交到实际执行 I/O 的时长(Submission latency) clat :是指从 I/O 提交到 I/O 完成的时长(Completion latency) lat :指的是从 fio 创建 I/O 到 I/O 完成的总时长 bw :吞吐量 iops :每秒 I/O 的次数 四、同步写测试 (1)同步随机写 主要采用fio作为测试工具,为了能够看到系统调用,使用strace工具, 命令 看起来是这样: 先来测试一个随机写 strace -f -tt -o /tmp/randwrite.log -D fio -name=randwrite -rw=randwrite \ -direct=1 -bs=4k -size=1G -numjobs=1 -group_reporting

网站故障排查常用命令

怎甘沉沦 提交于 2019-11-29 00:19:26
1.查看TCP连接状态 1 2 3 4 5 6 netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}' netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}' netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}' netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c 2.查找请求数请20个IP(常用于查找攻来源): 1 2 netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20 netstat -ant |awk '/:80/

Linux磁盘顺序写、随机写

半城伤御伤魂 提交于 2019-11-28 23:57:00
前言 随机写会导致磁头不停地换道,造成效率的极大降低 顺序写磁头几乎不用换道,或者换道的时间很短 fio 介绍 fio的输出报告中的几个关键指标: slat: 是指从 I/O 提交到实际执行 I/O 的时长(Submission latency) clat: 是指从 I/O 提交到 I/O 完成的时长(Completion latency) lat: 指的是从 fio 创建 I/O 到 I/O 完成的总时长 bw : 吞吐量 iops: 每秒 I/O 的次数 同步写测试 同步随机写 使用strace工具查看系统调用 strace -f -tt -o /tmp/randwrite.log -D fio -name=randwrite -rw=randwrite \ -direct=1 -bs=4k -size=1G -numjobs=1 -group_reporting -filename=/tmp/test.db 提取关键信息 root@wilson-ubuntu:~# strace -f -tt -o /tmp/randwrite.log -D fio -name=randwrite -rw=randwrite \ > -direct=1 -bs=4k -size=1G -numjobs=1 -group_reporting -filename=/tmp/test.db

Android: How to strace an app using ADB shell am start

我怕爱的太早我们不能终老 提交于 2019-11-28 18:29:29
I need help on stracing Android apps in the SDK emulator. Here is my setup: I have an Android SDK emulator running the Android API 4.03 ADB shell connected to emulator. I am able to install an APK using the ADB install filename.apk I am able to run the app using the ADB shell am start -a android.intent.action.Main -n com.akproduction.notepad/com.akproduction.notepad.NoteList I try to strace using (ADB shell) strace am start -a android.intent.action.Main -n com.akproduction.notepad/com.akproduction.notepad.NoteList but I get nothing! How do you trace the runtime behavior of Android apps and

How to track child process using strace?

情到浓时终转凉″ 提交于 2019-11-28 16:36:28
I used strace to attach to a process briefly. The process created 90 threads. When I found the offending thread, I had to tediously search for the parent thread, then the grandparent thread, and so on all the way to the root process. Is there a trick or tool to quickly figure out which thread created another? Or better yet, print the tree of thread creations like pstree ? strace -f to trace child process that's fork() ed. I can't see an easy way: You could use the -ff option with -o filename to produce multiple files (one per pid). eg: strace -o process_dump -ff ./executable grep clone process

How to solve “ptrace operation not permitted” when trying to attach GDB to a process?

a 夏天 提交于 2019-11-28 16:04:48
I'm trying to attach a program with gdb but it returns: Attaching to process 29139 Could not attach to process. If your uid matches the uid of the target process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf ptrace: Operation not permitted. gdb-debugger returns "Failed to attach to process, please check privileges and try again." strace returns "attach: ptrace(PTRACE_ATTACH, ...): Operation not permitted" I changed "kernel.yama.ptrace_scope" 1 to 0 and /proc/sys/kernel/yama/ptrace_scope 1 to 0 and

how to intercept linux signals ? (in C)

喜夏-厌秋 提交于 2019-11-28 12:46:20
I need to intercept and trace signals from any binaries, like strace does it under linux. I don't need a so verbose output like the real one strace. I just want to know how it works, how can I intercept signal and how can I trace them. Thanks in advance :) strace uses the ptrace() system call for tracing, which also allows you to intercept (and possibly manipulate) signals sent to the process. Here's a tiny example: #include <sys/ptrace.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv)