h**o 发帖数: 548 | 1 I have a files which records some activities of all functions.
I want to count how many times each of the function is called.
How to write a unix shell to count them?
or is there any other way?
Thanks |
i***h 发帖数: 12655 | 2 What function? You mean C/C++ function?
if in C,
void f() {
static int count = 0;
count++;
} |
h**o 发帖数: 548 | 3 forget about the function. Please think it as strings.
What I want is to count how many times each function name appear in this
file. While the size of the file is too large, I cannot count it with my
eyes and therefore want to write some shell. But I am a beginner of unix
shell. so I want to get some answers or hints here.
BTW, the format of the functions in this file is sth. like:
ADDR BUFADDR TIMESTAMP THREAD
CACHE LA
【在 h**o 的大作中提到】 : I have a files which records some activities of all functions. : I want to count how many times each of the function is called. : How to write a unix shell to count them? : or is there any other way? : Thanks
|
i***h 发帖数: 12655 | 4 if function name appears at most 1 time in one line:
grep function_name log_file | wc -l
【在 h**o 的大作中提到】 : forget about the function. Please think it as strings. : What I want is to count how many times each function name appear in this : file. While the size of the file is too large, I cannot count it with my : eyes and therefore want to write some shell. But I am a beginner of unix : shell. so I want to get some answers or hints here. : BTW, the format of the functions in this file is sth. like: : ADDR BUFADDR TIMESTAMP THREAD : CACHE LA
|
h**o 发帖数: 548 | 5 But I do not know what function appear in this files.
I only know there are some format which I can use to parse the names of
these function (see the attachment in the previous response)
I think I can first use grep to parse these function name, then count them
using for, sort,etc.
But I do not know how to grep them.
【在 i***h 的大作中提到】 : if function name appears at most 1 time in one line: : grep function_name log_file | wc -l
|
i***h 发帖数: 12655 | 6 So you don't have a list of all possible functions?
In that case, you'll need to know in what format the function names appeared
in the log file and find them using regex (I probably would do with Perl,
using hash to store the count of the appearances of each function).
【在 h**o 的大作中提到】 : But I do not know what function appear in this files. : I only know there are some format which I can use to parse the names of : these function (see the attachment in the previous response) : I think I can first use grep to parse these function name, then count them : using for, sort,etc. : But I do not know how to grep them.
|
h**o 发帖数: 548 | 7 yes, I don't have. Here are some format I can parse the name of the
functions:
90861840 90001000 d80ca215c298 1
cd9028 cc69c0 0
libumem.so.1`umem_cache_alloc_debug+0x12b
libumem.so.1`umem_cache_alloc+0xc8
libumem.so.1`umem_alloc+0xaf
libumem.so.1`malloc+0x2e
libumem.so.1`calloc+0x35
xcalloc+0x3b
memPoolAlloc+0x28d
0x4e6f81
functionA+0x130
0x4eaa53
functionB+0x11b
libwebproxy.so.1`functionC+0x6ab
libwebproxy.so.1`functionD+0xa8
libwebproxy.so.1`functionE+0x6dc
libwebproxy.so.1`functionF+0x6d4
...
【在 i***h 的大作中提到】 : So you don't have a list of all possible functions? : In that case, you'll need to know in what format the function names appeared : in the log file and find them using regex (I probably would do with Perl, : using hash to store the count of the appearances of each function).
|
h**o 发帖数: 548 | 8 besides. It seems grep only find the line which satisfies the requirement of
regular exp. but how to just get the name of the file, cutting other things
like address, lib names, etc? expecially if each line has different format,
then I cannot use 'cut'.
appeared
【在 i***h 的大作中提到】 : So you don't have a list of all possible functions? : In that case, you'll need to know in what format the function names appeared : in the log file and find them using regex (I probably would do with Perl, : using hash to store the count of the appearances of each function).
|
i***h 发帖数: 12655 | 9 In Perl (not familiar with shell programming and regex) something like:
$line = 'libumem.so.1`umem_cache_alloc_debug+0x12b';
$line =~ /^lib.*\`(\S+)\+0x/;
$func_name = $1;
func_name will be "umem_cache_alloc_debug"
【在 h**o 的大作中提到】 : yes, I don't have. Here are some format I can parse the name of the : functions: : 90861840 90001000 d80ca215c298 1 : cd9028 cc69c0 0 : libumem.so.1`umem_cache_alloc_debug+0x12b : libumem.so.1`umem_cache_alloc+0xc8 : libumem.so.1`umem_alloc+0xaf : libumem.so.1`malloc+0x2e : libumem.so.1`calloc+0x35 : xcalloc+0x3b
|
h**o 发帖数: 548 | 10 Thanks. I will try to understand it.
【在 i***h 的大作中提到】 : In Perl (not familiar with shell programming and regex) something like: : $line = 'libumem.so.1`umem_cache_alloc_debug+0x12b'; : $line =~ /^lib.*\`(\S+)\+0x/; : $func_name = $1; : func_name will be "umem_cache_alloc_debug"
|