db: store "too common" functions in the database
[smatch.git] / smatch_data / db / fill_db_caller_info.pl
blob3a708e10c4aa1b9748a64db477610434159f77a9
1 #!/usr/bin/perl -w
3 use strict;
4 use DBI;
5 use Scalar::Util qw(looks_like_number);
7 sub usage()
9 print "usage: $0 <project> <warns.txt>\n";
10 exit(1);
13 my %too_common_funcs;
14 sub get_too_common_functions($$$)
16 my $path = shift;
17 my $project = shift;
18 my $warns = shift;
20 open(FUNCS, "cat $warns | grep 'SQL_caller_info: ' | grep '%call_marker%' | cut -d \"'\" -f 6 | sort | uniq -c | ");
22 while (<FUNCS>) {
23 if ($_ =~ /(\d+) (.*)/) {
24 if (int($1) > 200) {
25 $too_common_funcs{$2} = 1;
30 close(FUNCS);
32 open(FILE, "$path/../$project.common_functions");
33 while (<FILE>) {
34 s/\n//;
35 $too_common_funcs{$_} = 1;
37 close(FILE);
40 my $exec_name = $0;
41 my $path = $exec_name;
42 $path =~ s/(.*)\/.*/$1/;
43 my $project = shift;
44 my $warns = shift;
46 if (!defined($warns)) {
47 usage();
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, '', '');");
64 my $call_id = 0;
65 my ($fn, $dummy, $sql);
67 open(WARNS, "<$warns");
68 while (<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: /)) {
72 next;
74 ($dummy, $dummy, $dummy, $dummy, $dummy, $fn, $dummy) = split(/'/);
76 if ($fn =~ /__builtin_/) {
77 next;
79 if ($fn =~ /(printk|memset|memcpy|kfree|printf|dev_err|writel)/) {
80 next;
83 if (defined($too_common_funcs{$fn})) {
84 next;
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.
92 $call_id++;
95 $db->do($sql);
97 $db->commit();
98 $db->disconnect();