summaryrefslogtreecommitdiff
path: root/count.c
Commit message (Collapse)AuthorAge
* Tweaks for -c: fixed setitimer/getitimer hack; optimized call_summary_pers()Denys Vlasenko2013-03-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | count_syscall() was calling setitimer/getitimer once in order to find smallest "tick" OS uses in time accounting, in order to use it for syscalls which apparently spent less than that time in syscall. The code assumed that this "tick" is not zero... but it is zero on linux-3.6.11. Which means that this hack doesn't work... At least this change prevents this measurement from being done _repeatedly_, by initializing one_tick to -1, not 0. While at it, added comments in count_syscall() explaining what we are doing. Optimized call_summary_pers() a bit, by eliminating redundant tv -> float conversions, and prevented 0.0/0.0 which was resulting in "% time" being shown as "-nan" if total CPU time spent was 0.000000 (try "strace -c /bin/true"). The code seems to seriously underestimate CPU usage: "strace -c ls -lR /usr/share >/dev/null" shows total time spent in syscalls to be only ~10..20% of what "time ls -lR /usr/share >/dev/null" shows. It might be useful to have a mode where we show wall clock time spent in syscalls, not CPU time. It might also be more accurate. text data bss dec hex filename 245019 676 5708 251403 3d60b strace_old 244923 684 5676 251283 3d593 strace Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Eliminate many SCNO_IS_VALID checksDenys Vlasenko2013-02-21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | By adding tcp->s_ent pointer tot syscall table entry, we can replace sysent[tcp->scno] references by tcp->s_ent. More importantly, we may ensure that tcp->s_ent is always valid, regardless of tcp->scno value. This allows us to drop SCNO_IS_VALID(tcp->scno) checks before we access syscall table entry. We can optimize (qual_flags[tcp->scno] & QUAL_foo) checks with a similar technique. Resulting code shrink: text data bss dec hex filename 245975 700 19072 265747 40e13 strace.t3/strace 245703 700 19072 265475 40d03 strace.t4/strace * count.c (count_syscall): Use cheaper SCNO_IN_RANGE() check. * defs.h: Add "int qual_flg" and "const struct sysent *s_ent" to struct tcb. Remove "int u_nargs" from it. Add UNDEFINED_SCNO constant which will mark undefined scnos in tcp->qual_flg. * pathtrace.c (pathtrace_match): Drop SCNO_IS_VALID check. Use tcp->s_ent instead of sysent[tcp->scno]. * process.c (sys_prctl): Use tcp->s_ent->nargs instead of tcp->u_nargs. (sys_waitid): Likewise. * strace.c (init): Add compile-time check that DEFAULT_QUAL_FLAGS constant is consistent with init code. * syscall.c (decode_socket_subcall): Use tcp->s_ent->nargs instead of tcp->u_nargs. Set tcp->qual_flg and tcp->s_ent. (decode_ipc_subcall): Likewise. (printargs): Use tcp->s_ent->nargs instead of tcp->u_nargs. (printargs_lu): Likewise. (printargs_ld): Likewise. (get_scno): [MIPS,ALPHA] Use cheaper SCNO_IN_RANGE() check. If !SCNO_IS_VALID, set tcp->s_ent and tcp->qual_flg to default values. (internal_fork): Use tcp->s_ent instead of sysent[tcp->scno]. (syscall_fixup_for_fork_exec): Remove SCNO_IS_VALID check. Use tcp->s_ent instead of sysent[tcp->scno]. (get_syscall_args): Likewise. (get_error): Drop SCNO_IS_VALID check where it is redundant. (dumpio): Drop SCNO_IS_VALID check where it is redundant. Use tcp->s_ent instead of sysent[tcp->scno]. (trace_syscall_entering): Use (tcp->qual_flg & UNDEFINED_SCNO) instead of SCNO_IS_VALID check. Use tcp->s_ent instead of sysent[tcp->scno]. Drop SCNO_IS_VALID check where it is redundant. Print undefined syscall name with undefined_scno_name(tcp). (trace_syscall_exiting): Likewise. * util.c (setbpt): Use tcp->s_ent instead of sysent[tcp->scno]. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Mass rename of SCNO_IN_RANGE define to SCNO_IS_VALIDDenys Vlasenko2013-02-16
| | | | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Make sure current_wordsize and PERSONALITY0_WORDSIZE are ints in all archesDenys Vlasenko2012-05-15
| | | | | | | | | | | On 64bit systems with a single personality, they used to be sizeof(long), which has type "long", not "int", which complicates printf formats. * defs.h: Ensure that PERSONALITY0_WORDSIZE;s tyoe is int. This in turn makes sure current_wordsize is also an int. * count.c (call_summary): Revert the change which added cast to int. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Cast current_wordsize to an intMike Frysinger2012-04-27
| | | | | | | | | | | | | | On 64bit systems with a single personality, we see: count.c: In function 'call_summary': count.c:223:5: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'long unsigned int' Since on multi-personality systems this is an array of ints, cast the multiplication to an int and update the printf format. * count.c (call_summary): Change %u to %d and cast first argument to int. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* Optimize code if we have only one personalityDenys Vlasenko2012-03-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On i386: text data bss dec hex filename 238025 672 18980 257677 3ee8d strace.before 237389 704 18944 257037 3ec0d strace * defs.h: Define PERSONALITY0_WORDSIZE as sizeof(long) if not defined. Introduce new define, current_wordsize as (personality_wordsize[current_personality]). Make set_personality() no-op, current_personality constant zero, current_wordsize as PERSONALITY0_WORDSIZE if we have only one personality. * count.c (call_summary): Use current_wordsize instead of personality_wordsize[current_personality]. * desc.c (printflock): Likewise. * file.c (sys_utime): Likewise. * io.c (tprint_iov): Likewise. * process.c (printargv): Likewise. * resource.c (decode_rlimit): Likewise. * signal.c (sys_kill): Likewise. (sys_rt_sigaction): Likewise. * time.c (sprinttv): Likewise. (sprint_timespec): Likewise. (printitv_bitness): Likewise. (tprint_timex): Likewise. (printsigevent): Likewise. * util.c (dumpiov): Likewise. (umoven): Likewise. (umovestr): Likewise. * syscall.c: Initialize sysent to sysent0 etc. Make current_personality, personality_wordsize[], set_personality() conditional on SUPPORTED_PERSONALITIES > 1. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Tidy up includes and copyright notices, fix indentationDenys Vlasenko2012-03-16
| | | | | | | | | | | | | | | The files not mentioned in changelog below had only copyright notices fixes and indentation fixes. * defs.h: Include <stdint.h> and <inttypes.h>. * file.c: Do not include <inttypes.h>. Move struct kernel_dirent declaration below top include block. * block.c: Do not include <stdint.h> and <inttypes.h>. * quota.c: Likewise. * desc.c: Likewise. * signal.c: Likewise. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Trivial tweaks to error messagesDenys Vlasenko2012-03-08
| | | | | | | | | | | | | | * strace.c (test_ptrace_setoptions_followfork): Use kill_save_errno instead of kill. (trace): Use perror_msg instead of perror. * count.c (set_sortby): Use error_msg_and_die instead of fprintf. * syscall.c (qualify): Likewise. * util.c (ptrace_restart): Expand error message. (umoven): Likewise. (umovestr): Likewise. (upeek): Use perror_msg instead of sprintf + perror. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Automated removal of non-Linux codeDenys Vlasenko2012-02-25
| | | | | | | | | | This change is generated by running every source through the following command: unifdef -DLINUX -Dlinux -USUNOS4 -USVR4 -UUNIXWARE -UFREEBSD -USUNOS4_KERNEL_ARCH_KLUDGE -UHAVE_MP_PROCFS -UHAVE_POLLABLE_PROCFS -UHAVE_PR_SYSCALL -UUSE_PROCFS file.c Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
* Cast to long for %l in printfH.J. Lu2012-02-06
| | | | | | | | | | | Cast a value to long for %l in printf to avoid compiler warning on systems where it may be long long. * count.c (call_summary_pers): Cast to long. * ipc.c (sys_mq_open, printmqattr): Likewise. * quota.c (decode_cmd_data): Likewise. * resource.c (sys_sysinfo): Likewise. * time.c (tprint_timex): Likewise.
* Make out-of-memory handling more uniformDenys Vlasenko2011-08-31
| | | | | | | | | | | | | | | | | | | | | | | | | | This fixes one real bug in dumpstr(). * defs.h: Declare die_out_of_memory(). * strace.c (die_out_of_memory): New function. (strace_popen): If allocation fails, call die_out_of_memory(). (main): Likewise. (expand_tcbtab): Likewise. (rebuild_pollv): Likewise. * count.c (count_syscall): Likewise. (call_summary_pers): Likewise. * desc.c (decode_select): Likewise. * file.c (sys_getdents): Likewise. (sys_getdents64): Likewise. (sys_getdirentries): Likewise. * pathtrace.c (pathtrace_match): Likewise. * syscall.c (qualify): Likewise. * util.c (printstr): Likewise. (dumpiov): Likewise. (dumpstr): Likewise. (fixvfork): Likewise. * mem.c (sys_mincore): Don't check free() parameter for NULL. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* Opotimize "scno >= 0 && scno < nsyscalls" checkDenys Vlasenko2011-08-25
| | | | | | | | | | | | | | | | | | | | | | gcc can't figure out on its own that this check can be done with single compare, and does two compares. We can help it by casting scno to unsigned long: ((unsigned long)(scno) < nsyscalls) * defs.h: New macro SCNO_IN_RANGE(long_var). * count.c (count_syscall): Use SCNO_IN_RANGE() instead of open-coded check. * syscall.c (getrval2): Use SCNO_IN_RANGE() instead of open-coded check. This fixes a bug: missing check for scno < 0 and scno > nsyscalls instead of scno >= nsyscalls. (get_scno): Use SCNO_IN_RANGE() instead of open-coded check. This fixes a bug: scno > nsyscalls instead of scno >= nsyscalls. (known_scno): Use SCNO_IN_RANGE() instead of open-coded check. (internal_syscall): Likewise. (syscall_enter): Likewise. (trace_syscall_entering): Likewise. (get_error): Likewise. (trace_syscall_exiting): Likewise. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* count_syscall() always returns 0, optimize itDenys Vlasenko2011-08-23
| | | | | | | | | * defs.h (count_syscall): Change return type from int to void. * count.c (count_syscall): Change return type from int to void. * syscall.c (trace_syscall_exiting): Change code around call to count_syscall accordingly. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* Whitespace cleanups. No code changes.Denys Vlasenko2011-06-22
| | | | | | | | | | | | | | | | | | * count.c: Place opening curly brace after if (), not on the next line. Almost all strace code alredy uses this style. * desc.c: Likewise. * file.c: Likewise. * net.c: Likewise. * pathtrace.c: Likewise. * process.c: Likewise. * quota.c: Likewise. * signal.c: Likewise. * strace.c: Likewise. * syscall.c: Likewise. * time.c: Likewise. Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
* Fix const-correctness issues uncovered by gcc -Wwrite-stringsDmitry V. Levin2010-09-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * defs.h (struct xlat): Add const qualifier to the field of type "char *". (set_sortby, qualify, printnum, printnum_int): Add const qualifier to arguments of type "char *". * count.c (set_sortby): Add const qualifier to the argument and automatic variable of type "char *". * desc.c (decode_select): Add const qualifier to automatic variables of type "char *". * ioctlsort.c (struct ioctlent): Add const qualifier to fields of type "char *". (main): Add const qualifier to argv. * process.c (printargv): Add const qualifier to the argument and automatic variable of type "char *". (printargc) Add const qualifier to argument of type "char *". * signal.c (sprintsigmask, parse_sigset_t): Add const qualifier to arguments of type "char *". * strace.c (progname): Add const qualifier. (detach): Add const qualifier to automatic variable of type "char *". * stream.c (struct strbuf): Add const qualifier to the field of type "char *". * syscall.c (struct qual_options): Add const qualifier to fields of type "char *". (qual_syscall, qual_fault, qual_desc, lookup_class): Add const qualifier to arguments of type "char *". (qual_signal): Add const qualifier to the argument of type "char *", avoid modification of constant argument. (qualify): Likewise. * util.c (printflags): Add const qualifier to automatic variable of type "char *". (printnum, printnum_int): Add const qualifier to arguments of type "char *".
* Implement -C option to combine regular and -c outputDmitry V. Levin2010-04-07
| | | | | | | | | | | * defs.h (cflag_t): New enum. * strace.1: Document -C option. * strace.c (cflag): Update type. (main): Handle -C option. (trace): Update use of cflag. * count.c (count_syscall): Move clearing of TCB_INSYSCALL to ... * syscall.c (trace_syscall): ... here. Update use of cflag. Based on patch by Adrien Kunysz.
* 2008-04-19 Dmitry V. Levin <ldv@altlinux.org>Dmitry V. Levin2008-04-19
| | | | | * count.c (call_summary_pers): Check calloc() return value. Signed-off-by: "Yang Zhiguo" <yzgcsu@cn.fujitsu.com>
* 2007-07-11 Roland McGrath <roland@redhat.com>Roland McGrath2007-07-11
| | | | | | * count.c (call_summary_pers): Use tv_float conversion for output of cumulative time, in case it is negative from bogus -O value. From Lai JiangShan <laijs@cn.fujitsu.com>.
* 2006-12-21 Dmitry V. Levin <ldv@altlinux.org>Dmitry V. Levin2006-12-21
Move counts code to separate file. * count.c: New file. * Makefile.am (strace_SOURCES): Add count.c. * syscall.c (call_counts, countv, counts, shortest, time_cmp, syscall_cmp, count_cmp, sortfun, overhead, set_sortby, set_overhead, call_summary_pers, call_summary): Move to count.c * count.c (count_syscall): New function. * defs.h (count_syscall): Declare it. * syscall.c (trace_syscall): Use it.