5 use Scalar
::Util
qw(looks_like_number);
9 print "usage: $0 <project> <smatch_warns.txt> <db_file>\n";
14 sub get_too_common_functions
($$$)
20 open(FUNCS
, "grep 'SQL_caller_info: ' $warns | grep '%call_marker%' | cut -d \"'\" -f 6 | sort | uniq -c | ");
23 if ($_ =~ /(\d+) (.*)/) {
25 $too_common_funcs{$2} = 1;
32 open(FILE
, ">", "$path/../$project.common_functions");
33 foreach my $func (keys %too_common_funcs) {
43 my $path = $exec_name;
44 $path =~ s/(.*)\/.*/$1/;
49 if (!defined($db_file)) {
53 get_too_common_functions
($path, $project, $warns);
55 my $db = DBI
->connect("dbi:SQLite:$db_file", "", "", {AutoCommit
=> 0});
56 $db->do("PRAGMA cache_size = 800000");
57 $db->do("PRAGMA journal_mode = OFF");
58 $db->do("PRAGMA count_changes = OFF");
59 $db->do("PRAGMA temp_store = MEMORY");
60 $db->do("PRAGMA locking = EXCLUSIVE");
62 foreach my $func (keys %too_common_funcs) {
63 $db->do("insert into common_caller_info values ('unknown', 'too common', '$func', 0, 0, 0, -1, '', '');");
67 my ($fn, $dummy, $sql);
69 open(WARNS
, "<$warns");
71 # test.c:11 frob() SQL_caller_info: insert into caller_info values ('test.c', 'frob', '__smatch_buf_size', %CALL_ID%, 1, 0, -1, '', ');
73 if (!($_ =~ /^.*? \w+\(\) SQL_caller_info: /)) {
76 ($dummy, $dummy, $dummy, $dummy, $dummy, $fn, $dummy) = split(/'/);
78 if ($fn =~ /__builtin_/) {
81 if ($fn =~ /^(printk|memset|memcpy|kfree|printf|dev_err|writel)$/) {
85 ($dummy, $dummy, $sql) = split(/:/, $_, 3);
87 if ($sql =~ /%call_marker%/) {
88 $sql =~ s/%call_marker%//; # don't need this taking space in the db.
91 $sql =~ s/%CALL_ID%/$call_id/;