smatch: change all remaining references from warns.txt to smatch_warns.txt
[smatch.git] / smatch_data / db / fill_db_caller_info.pl
blobb9faa1aae18e441f86489a4d70ea67c0464c2554
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 <-p=project> <smatch_warns.txt> <db_file>\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;
45 my $db_file = shift;
47 if (!defined($db_file)) {
48 usage();
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, '', '');");
65 my $call_id = 0;
66 my ($fn, $dummy, $sql);
68 open(WARNS, "<$warns");
69 while (<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: /)) {
73 next;
75 ($dummy, $dummy, $dummy, $dummy, $dummy, $fn, $dummy) = split(/'/);
77 if ($fn =~ /__builtin_/) {
78 next;
80 if ($fn =~ /^(printk|memset|memcpy|kfree|printf|dev_err|writel)$/) {
81 next;
84 if (defined($too_common_funcs{$fn})) {
85 next;
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.
93 $call_id++;
96 $db->do($sql);
98 $db->commit();
99 $db->disconnect();