/* * builtin-top.c * * Builtin top command: Display a continuously updated profile of * any workload, CPU or specific PID. * * Copyright (C) 2008, Red Hat Inc, Ingo Molnar <mingo@redhat.com> * * Improvements and fixes by: * * Arjan van de Ven <arjan@linux.intel.com> * Yanmin Zhang <yanmin.zhang@intel.com> * Wu Fengguang <fengguang.wu@intel.com> * Mike Galbraith <efault@gmx.de> * Paul Mackerras <paulus@samba.org> * * Released under the GPL v2. (and only v2, not any later version) */#include"builtin.h"#include"perf.h"#include"util/symbol.h"#include"util/color.h"#include"util/util.h"#include<linux/rbtree.h>#include"util/parse-options.h"#include"util/parse-events.h"#include<assert.h>#include<fcntl.h>#include<stdio.h>#include<termios.h>#include<unistd.h>#include<errno.h>#include<time.h>#include<sched.h>#include<pthread.h>#include<sys/syscall.h>#include<sys/ioctl.h>#include<sys/poll.h>#include<sys/prctl.h>#include<sys/wait.h>#include<sys/uio.h>#include<sys/mman.h>#include<linux/unistd.h>#include<linux/types.h>staticintfd[MAX_NR_CPUS][MAX_COUNTERS];staticintsystem_wide=0;staticintdefault_interval=100000;staticintcount_filter=5;staticintprint_entries=15;staticinttarget_pid=-1;staticintinherit=0;staticintprofile_cpu=-1;staticintnr_cpus=0;staticunsignedintrealtime_prio=0;staticintgroup=0;staticunsignedintpage_size;staticunsignedintmmap_pages=16;staticintfreq=0;staticintverbose=0;staticchar*vmlinux=NULL;staticintdelay_secs=2;staticintzero;staticintdump_symtab;/* * Source */structsource_line{u64eip;unsignedlongcount[MAX_COUNTERS];char*line;structsource_line*next;};staticchar*sym_filter=NULL;structsym_entry*sym_filter_entry=NULL;staticintsym_pcnt_filter=5;staticintsym_counter=0;staticintdisplay_weighted=-1;/* * Symbols */staticu64min_ip;staticu64max_ip=-1ll;structsym_entry{structrb_noderb_node;structlist_headnode;unsignedlongcount[MAX_COUNTERS];unsignedlongsnap_count;doubleweight;intskip;structsource_line*source;structsource_line*lines;structsource_line**lines_tail;pthread_mutex_tsource_lock;};/* * Source functions */staticvoidparse_source(structsym_entry*syme){structsymbol*sym;structmodule*module;structsection*section=NULL;FILE*file;char