5 use Scalar
::Util
qw(looks_like_number);
9 print "usage: $0 <project> <warns.txt>\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/;
46 if (!defined($warns)) {
50 get_too_common_functions
($path, $project, $warns);
52 my $db = DBI
->connect("dbi:SQLite:smatch_db.sqlite", "", "", {AutoCommit
=> 0});
53 $db->do("PRAGMA synchronous = OFF");
54 $db->do("PRAGMA cache_size = 800000");
55 $db->do("PRAGMA journal_mode = OFF");
56 $db->do("PRAGMA count_changes = OFF");
57 $db->do("PRAGMA temp_store = MEMORY");
58 $db->do("PRAGMA locking = EXCLUSIVE");
60 foreach my $func (keys %too_common_funcs) {
61 $db->do("insert into caller_info values ('unknown', 'too common', '$func', 0, 0, 0, -1, '', '');");
65 my ($fn, $dummy, $sql);
67 open(WARNS
, "<$warns");
69 # test.c:11 frob() SQL_caller_info: insert into caller_info values ('test.c', 'frob', '__smatch_buf_size', %CALL_ID%, 1, 0, -1, '', ');
71 if (!($_ =~ /^.*? \w+\(\) SQL_caller_info: /)) {
74 ($dummy, $dummy, $dummy, $dummy, $dummy, $fn, $dummy) = split(/'/);
76 if ($fn =~ /__builtin_/) {
79 if ($fn =~ /(printk|memset|memcpy|kfree|printf|dev_err|writel)/) {
83 if (defined($too_common_funcs{$fn})) {
87 ($dummy, $dummy, $sql) = split(/:/, $_, 3);
89 $sql =~ s/%CALL_ID%/$call_id/;
90 if ($sql =~ /%call_marker%/) {
91 $sql =~ s/%call_marker%//; # don't need this taking space in the db.