5 use Scalar
::Util
qw(looks_like_number);
9 print "usage: $0 <-p=project> <smatch_warns.txt> <db_file>\n";
14 sub get_too_common_functions
($$$)
20 open(FUNCS
, "cat $warns | grep 'SQL_caller_info: ' | 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");
35 $too_common_funcs{$_} = 1;
41 my $path = $exec_name;
42 $path =~ s/(.*)\/.*/$1/;
47 if (!defined($db_file)) {
51 get_too_common_functions
($path, $project, $warns);
53 my $db = DBI
->connect("dbi:SQLite:$db_file", "", "", {AutoCommit
=> 0});
54 $db->do("PRAGMA synchronous = OFF");
55 $db->do("PRAGMA cache_size = 800000");
56 $db->do("PRAGMA journal_mode = OFF");
57 $db->do("PRAGMA count_changes = OFF");
58 $db->do("PRAGMA temp_store = MEMORY");
59 $db->do("PRAGMA locking = EXCLUSIVE");
61 foreach my $func (keys %too_common_funcs) {
62 $db->do("insert into caller_info values ('unknown', 'too common', '$func', 0, 0, 0, -1, '', '');");
66 my ($fn, $dummy, $sql);
68 open(WARNS
, "<$warns");
70 # test.c:11 frob() SQL_caller_info: insert into caller_info values ('test.c', 'frob', '__smatch_buf_size', %CALL_ID%, 1, 0, -1, '', ');
72 if (!($_ =~ /^.*? \w+\(\) SQL_caller_info: /)) {
75 ($dummy, $dummy, $dummy, $dummy, $dummy, $fn, $dummy) = split(/'/);
77 if ($fn =~ /__builtin_/) {
80 if ($fn =~ /^(printk|memset|memcpy|kfree|printf|dev_err|writel)$/) {
84 if (defined($too_common_funcs{$fn})) {
88 ($dummy, $dummy, $sql) = split(/:/, $_, 3);
90 $sql =~ s/%CALL_ID%/$call_id/;
91 if ($sql =~ /%call_marker%/) {
92 $sql =~ s/%call_marker%//; # don't need this taking space in the db.