78f92c21cd457c6e08e02bb2b8d07a0d69008288
[smatch.git] / smatch_data / db / fill_db_caller_info.pl
blob78f92c21cd457c6e08e02bb2b8d07a0d69008288
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 <warns.txt>\n";
10 exit(1);
13 my %too_common_funcs;
14 sub get_too_common_functions($)
16 my $warns = shift;
18 open(FUNCS, "cat $warns | grep 'SQL_caller_info: ' | grep '%call_marker%' | cut -d \"'\" -f 6 | sort | uniq -c | ");
20 while (<FUNCS>) {
21 if ($_ =~ /(\d+) (.*)/) {
22 if (int($1) > 200) {
23 $too_common_funcs{$2} = 1;
28 close(FUNCS);
31 my $warns = shift;
33 if (!defined($warns)) {
34 usage();
37 get_too_common_functions($warns);
39 my $db = DBI->connect("dbi:SQLite:smatch_db.sqlite", "", "", {AutoCommit => 0});
40 $db->do("PRAGMA synchronous = OFF");
41 $db->do("PRAGMA cache_size = 800000");
42 $db->do("PRAGMA journal_mode = OFF");
43 $db->do("PRAGMA count_changes = OFF");
44 $db->do("PRAGMA temp_store = MEMORY");
45 $db->do("PRAGMA locking = EXCLUSIVE");
47 my $call_id = 0;
48 my ($fn, $dummy, $sql);
50 open(WARNS, "<$warns");
51 while (<WARNS>) {
52 # test.c:11 frob() SQL_caller_info: insert into caller_info values ('test.c', 'frob', '__smatch_buf_size', %CALL_ID%, 1, 0, -1, '', ');
54 if (!($_ =~ /^.*? \w+\(\) SQL_caller_info: /)) {
55 next;
57 ($dummy, $dummy, $dummy, $dummy, $dummy, $fn, $dummy) = split(/'/);
59 if ($fn =~ /__builtin_/) {
60 next;
62 if ($fn =~ /(printk|memset|memcpy|kfree|printf|dev_err|writel)/) {
63 next;
66 if (defined($too_common_funcs{$fn})) {
67 next;
70 ($dummy, $dummy, $sql) = split(/:/, $_, 3);
72 $sql =~ s/%CALL_ID%/$call_id/;
73 if ($sql =~ /%call_marker%/) {
74 $sql =~ s/%call_marker%//; # don't need this taking space in the db.
75 $call_id++;
78 $db->do($sql);
80 $db->commit();
81 $db->disconnect();