在Linux下做性能分析3:perf - 知乎 https://zhuanlan.zhihu.com/p/22194920
Linux Perf 性能分析工具及火焰图浅析 - 知乎 https://zhuanlan.zhihu.com/p/54276509
perf record -a -g -e cycles -e cs #系统整体采样
查看指定进程
redis-server
perf report --pid 7070
mysqld
perf report --pid 5634
Samples: 25K of event 'cs', Event count (approx.): 463138
Children Self Command Shared Object Symbol
0.04% 0.00% mysqld [unknown] [.] 0xffffffff83b100f0 ▒
0.04% 0.00% mysqld [unknown] [.] 0xffffffff83b0fbd6 ▒
0.04% 0.00% mysqld [unknown] [.] 0xffffffff83b0de8b ▒
0.04% 0.00% mysqld [unknown] [.] 0xffffffff83b0d1a6 ▒
0.03% 0.00% mysqld mysqld [.] os_event::wait_time_low ▒
0.03% 0.00% mysqld libpthread-2.17.so;5d9ff4e7 (deleted) [.] 0x00007f23ef6b0d12 ◆
0.02% 0.00% mysqld mysqld [.] lock_wait_timeout_thread ▒
0.01% 0.00% mysqld mysqld [.] thd_prepare_connection ▒
0.01% 0.00% mysqld mysqld [.] check_connection ▒
0.01% 0.00% mysqld mysqld [.] acl_authenticate ▒
0.01% 0.00% mysqld mysqld [.] do_auth_once ▒
0.01% 0.00% mysqld mysqld [.] native_password_authenticate ▒
0.01% 0.00% mysqld mysqld [.] server_mpvio_read_packet ▒
0.01% 0.00% mysqld mysqld [.] parse_client_handshake_packet ▒
0.01% 0.00% mysqld libpthread-2.17.so;5d9ff4e7 (deleted) [.] 0x00007f23ef6b0965 ▒
0.01% 0.00% mysqld mysqld [.] srv_master_thread ▒
0.01% 0.00% mysqld libpthread-2.17.so;5d9ff4e7 (deleted) [.] 0x00007f23ef6b3e3d ▒
0.01% 0.00% mysqld [unknown] [.] 0xffffffff83ac6d36 ▒
0.01% 0.00% mysqld [unknown] [.] 0xffffffff83ac6bdb ▒
0.01% 0.00% mysqld [unknown] [.] 0xffffffff84167f06 ▒
0.01% 0.00% mysqld mysqld [.] buf_flush_page_cleaner_coordinator ▒
0.01% 0.00% mysqld mysqld [.] sslaccept ▒
0.01% 0.00% mysqld mysqld [.] yaSSL_accept ▒
0.00% 0.00% mysqld mysqld [.] srv_monitor_thread ▒
0.00% 0.00% mysqld libc-2.17.so;5d9ff4e7 (deleted) [.] 0x00007f23ee08a3d5 ▒
0.00% 0.00% mysqld mysqld [.] mysqld_main ▒
0.00% 0.00% mysqld [unknown] [.] 0xffffffff8416813d ▒
0.00% 0.00% mysqld mysqld [.] srv_error_monitor_thread ▒
3793a0 3793b0 g std::string::_Rep::_M_dispose@plt ▒
▒
Samples: 159K of event 'cpu-clock', Event count (approx.): 39969500000
Children Self Command Shared Object Symbol
+ 0.72% 0.00% mysqld libpthread-2.17.so;5d9ff4e7 (deleted) [.] 0x00007f23ef6acdd5
+ 0.71% 0.00% mysqld mysqld [.] pfs_spawn_thread
+ 0.71% 0.00% mysqld mysqld [.] handle_connection
+ 0.60% 0.00% mysqld mysqld [.] thd_prepare_connection
+ 0.60% 0.00% mysqld mysqld [.] check_connection
+ 0.60% 0.00% mysqld mysqld [.] acl_authenticate
+ 0.60% 0.00% mysqld mysqld [.] do_auth_once
+ 0.60% 0.00% mysqld mysqld [.] native_password_authenticate
+ 0.60% 0.00% mysqld mysqld [.] server_mpvio_read_packet
+ 0.60% 0.00% mysqld mysqld [.] parse_client_handshake_packet
+ 0.60% 0.00% mysqld mysqld [.] sslaccept
+ 0.58% 0.00% mysqld mysqld [.] TaoCrypt::a_exp_b_mod_c
+ 0.58% 0.00% mysqld mysqld [.] TaoCrypt::AbstractRing::Exponentiate
+ 0.58% 0.00% mysqld mysqld [.] TaoCrypt::ModularArithmetic::SimultaneousExponentiate
+ 0.58% 0.00% mysqld mysqld [.] TaoCrypt::AbstractGroup::SimultaneousMultiply
+ 0.54% 0.00% mysqld mysqld [.] yaSSL_accept
0.47% 0.00% mysqld mysqld [.] yaSSL::sendServerKeyExchange
0.47% 0.00% mysqld mysqld [.] yaSSL::ServerKeyExchange::build
0.47% 0.00% mysqld mysqld [.] yaSSL::DH_Server::build
0.47% 0.00% mysqld mysqld [.] TaoCrypt::MontgomeryRepresentation::Square
0.47% 0.00% mysqld mysqld [.] TaoCrypt::RSA_PublicKey::ApplyFunction
0.47% 0.00% mysqld mysqld [.] yaSSL::RSA::sign
0.47% 0.00% mysqld mysqld [.] TaoCrypt::RSA_Encryptor<TaoCrypt::RSA_BlockType1>::Encrypt
0.36% 0.00% mysqld mysqld [.] TaoCrypt::MontgomeryReduce
0.32% 0.03% mysqld mysqld [.] TaoCrypt::RecursiveMultiply
0.27% 0.24% mysqld mysqld [.] TaoCrypt::Portable::Multiply8
0.18% 0.01% mysqld mysqld [.] TaoCrypt::RecursiveMultiplyTop
0.17% 0.01% mysqld mysqld [.] TaoCrypt::RecursiveSquare
0.15% 0.00% mysqld mysqld [.] TaoCrypt::RecursiveMultiplyBottom
0.14% 0.13% mysqld mysqld [.] TaoCrypt::Portable::Add
0.10% 0.00% mysqld mysqld [.] TaoCrypt::MontgomeryRepresentation::Multiply
0.10% 0.00% mysqld mysqld [.] do_command
0.10% 0.00% mysqld mysqld [.] TaoCrypt::AbstractRing::MultiplicativeGroupT::Accumulate
0.08% 0.00% mysqld mysqld [.] dispatch_command
0.08% 0.00% mysqld mysqld [.] yaSSL::processReply
Tip: System-wide collection from all CPUs: perf record -a
Samples: 159K of event 'cpu-clock', Event count (approx.): 39969500000
Children Self Command Shared Object Symbol
0.00% 0.00% nginx [unknown] [.] 0xffffffff8417a6e8 ◆
0.00% 0.00% nginx [unknown] [.] 0xffffffff83aa13f5 ▒
0.00% 0.00% nginx [unknown] [.] 0xffffffff83a2e675 ▒
0.00% 0.00% nginx [unknown] [.] 0xffffffff8417932c ▒
0.00% 0.00% nginx [unknown] [.] 0xffffffff84175ddb ▒
0.00% 0.00% nginx [unknown] [.] 0x64222c3030323a22 ▒
0.00% 0.00% nginx [unknown] [.] 0x000055d5cf29c5d0 ▒
0.00% 0.00% nginx [unknown] [k] 0x0000000000000019 ▒
0.00% 0.00% nginx libpthread-2.17.so;5d9ff4e7 (deleted) [.] 0x00007f304e9c4680 ▒
0.00% 0.00% nginx [unknown] [.] 0xffffffff83c426af ▒
0.00% 0.00% nginx [unknown] [.] 0xffffffff83c41890 ▒
0.00% 0.00% nginx [unknown] [.] 0xffffffff83c40da3 ▒
0.00% 0.00% nginx [unknown] [.] 0xffffffffc04c1322 ▒
0.00% 0.00% nginx [unknown] [.] 0xffffffff83bb8e89 ▒
0.00% 0.00% nginx [unknown] [.] 0xffffffff83bb8c12 ▒
0.00% 0.00% nginx [unknown] [.] 0xffffffff83aa1075 ▒
0.00% 0.00% nginx [kernel.kallsyms] [k] run_timer_softirq ▒
0.00% 0.00% nginx libz.so.1.2.7 [.] 0x000000000000388e ▒
0.00% 0.00% nginx libz.so.1.2.7 [.] crc32 ▒
0.00% 0.00% nginx [unknown] [k] 0x000055d5cf29c6f0 ▒
0.00% 0.00% nginx [unknown] [.] 0x000055d5cf1847e8 ▒
0.00% 0.00% nginx libz.so.1.2.7 [.] 0x00007f304dc3688e ▒
0.00% 0.00% nginx [kernel.kallsyms] [k] do_get_write_access ▒
0.00% 0.00% nginx [kernel.kallsyms] [k] eth_type_trans ▒
0.00% 0.00% nginx [kernel.kallsyms] [k] radix_tree_descend ▒
0.00% 0.00% nginx [kernel.kallsyms] [k] copy_user_enhanced_fast_string ▒
0.00% 0.00% nginx [kernel.kallsyms] [k] __x86_indirect_thunk_rax ▒
0.00% 0.00% nginx [kernel.kallsyms] [k] _raw_spin_unlock_irqrestore ▒
0.00% 0.00% nginx [kernel.kallsyms] [k] check_for_new_grace_period.isra.26 ▒
0.00% 0.00% nginx [kernel.kallsyms] [k] __do_softirq ▒
0.00% 0.00% nginx nginx [.] ngx_http_create_request ▒
0.00% 0.00% nginx [kernel.kallsyms] [k] sys_epoll_ctl ▒
0.00% 0.00% nginx nginx [.] 0x0000000000067287 ▒
0.00% 0.00% nginx nginx [.] 0x000000000007a501 ▒
0.00% 0.00% nginx libz.so.1.2.7 [.] 0x0000000000002c52
Samples: 159K of event 'cpu-clock', 4000 Hz, Event count (approx.): 39969500000
TaoCrypt::Portable::Add /usr/sbin/mysqld [Percent: local period]
3.48 │ lea 0x1(%r8),%r9d ▒
3.48 │ mov (%rdx,%r9,8),%rbx ▒
│ _ZN8TaoCrypt5DWordplEm(): ▒
3.48 │ mov %rbx,%r10 ▒
2.99 │ add (%rsi,%r9,8),%r10 ▒
3.48 │ add %r10,%r11 ▒
4.48 │ setb %r12b ▒
6.97 │ xor %eax,%eax ▒
1.49 │ cmp %r10,%rbx ▒
1.00 │ seta %al ▒
│ _ZN8TaoCrypt8Portable3AddEPmPKmS3_j(): ▒
7.96 │ add $0x2,%r8d ▒
0.50 │ mov %r11,(%rdi,%r9,8) ▒
│ _ZN8TaoCrypt5DWordplEm(): ▒
1.99 │ add %r12,%rax ▒
│ _ZN8TaoCrypt8Portable3AddEPmPKmS3_j(): ▒
3.48 │ cmp %r8d,%ecx ▒
│ → ja 1318f70 <TaoCrypt::Portable::Add(unsigned long*, unsigned long const*, unsigned long const*, unsigned int)+0x10> ▒
0.50 │ pop %rbx ▒
│ pop %r12 ▒
│ pop %rbp ▒
│ ← retq ▒
│ DWord(): ▒
│ xor %eax,%eax ▒
│ ← retq ▒
▒
▒
Samples: 159K of event 'cpu-clock', 4000 Hz, Event count (approx.): 39969500000
TaoCrypt::Portable::Add /usr/sbin/mysqld [Percent: local period]
Percent│ ◆
│ ▒
│ ▒
│ Disassembly of section .text: ▒
│ ▒
│ 0000000001318f60 <TaoCrypt::Portable::Add(unsigned long*, unsigned long const*, unsigned long const*, unsigned int)>: ▒
│ _ZN8TaoCrypt8Portable3AddEPmPKmS3_j(): ▒
1.49 │ test %ecx,%ecx ▒
│ → je 1318fd0 <TaoCrypt::Portable::Add(unsigned long*, unsigned long const*, unsigned long const*, unsigned int)+0x70> ▒
│ push %rbp ▒
│ DWord(): ▒
│ xor %eax,%eax ▒
│ _ZN8TaoCrypt8Portable3AddEPmPKmS3_j(): ▒
│ xor %r8d,%r8d ▒
│ mov %rsp,%rbp ▒
1.49 │ push %r12 ▒
3.48 │ push %rbx ▒
5.47 │ mov %r8d,%r10d ▒
│ _ZN8TaoCrypt5DWordplEm(): ▒
1.49 │ xor %r11d,%r11d ▒
│ _ZN8TaoCrypt8Portable3AddEPmPKmS3_j(): ▒
1.49 │ mov (%rdx,%r10,8),%rbx ▒
│ _ZN8TaoCrypt5DWordplEm(): ▒
3.98 │ mov %rbx,%r9 ▒
1.00 │ add (%rsi,%r10,8),%r9 ▒
1.49 │ add %r9,%rax ▒
3.48 │ setb %r11b ▒
4.98 │ cmp %r9,%rbx ▒
│ _ZN8TaoCrypt8Portable3AddEPmPKmS3_j(): ▒
3.98 │ mov %rax,(%rdi,%r10,8) ▒
│ _ZN8TaoCrypt5DWordplEm(): ▒
5.97 │ seta %r9b ▒
6.47 │ xor %r12d,%r12d ▒
2.49 │ movzbl %r9b,%r9d ▒
5.97 │ add %r9,%r11 ▒
Press 'h' for help on key bindings ▒
深入理解Windows X64调试 - _懒人 - 博客园 https://www.cnblogs.com/lanrenxinxin/p/4762858.html
X86-64寄存器和栈帧 - 为程序员服务 http://ju.outofmemory.cn/entry/769
x86寄存器问题 - wang010366的专栏 - CSDN博客 https://blog.csdn.net/wang010366/article/details/52015264
x64 Architecture - Windows drivers | Microsoft Docs https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/x64-architecture
#include <stdio.h>
#include <malloc.h> int my_stack_heap(void){
/*在栈上分配*/
int i1=0;
int i2=0;
int i3=0;
int i4=0;
printf("---");
printf("栈:向下 i1=0x%08x,i2=0x%08x,i3=0x%08x,i4=0x%08x,\n",&i1,&i2,&i3,&i4);
/*在堆上分配*/
char *p1 = (char *)malloc(256);
char *p2 = (char *)malloc(256);
char *p3 = (char *)malloc(256);
char *p4 = (char *)malloc(256);
printf("堆:向上 p1=0x%08x,p2=0x%08x,p3=0x%08x,p4=0x%08x,\n",p1,p2,p3,p4);
/*释放堆内存*/
free(p1);
p1=NULL;
free(p2);
p2=NULL;
free(p3);
p3=NULL;
free(p4);
p4=NULL; /* 栈:向下
i1=0x0022fe2c
i2=0x0022fe28
i3=0x0022fe24
i4=0x0022fe20 -------------------- p1=0x004bfe40
p2=0x004bfe60
p3=0x004bfe80
p4=0x004bfea0
堆:向上 */
return 0;
}
int main(void) {
while (1==1)
{
/* code */
my_stack_heap();
} return 0;
}
gcc my_stack_heap.c -o my_stack_heap
Registers
x64 extends x86's 8 general-purpose registers to be 64-bit, and adds 8 new 64-bit registers. The 64-bit registers have names beginning with "r", so for example the 64-bit extension of eax is called rax. The new registers are named r8 through r15.
The lower 32 bits, 16 bits, and 8 bits of each register are directly addressable in operands. This includes registers, like esi, whose lower 8 bits were not previously addressable. The following table specifies the assembly-language names for the lower portions of 64-bit registers.