Debian Codegraph @

mysql-test/suite/innodb/include/check_core_dump_trim.inc

raw
1 # ------------------------------------------------------------------------------
2 # Test Summary
3 # ------------------------------------------------------------------------------
4 # This test checks whether the mariadbd core dump file is expected to be TRIMMED
5 # or NOT TRIMMED based on how memory is mapped by the mariadbd process.
6 #
7 # What this script does:
8 #
9 # 1. It retrieves MariaDB runtime values:
10 # - pid_file (location of mariadbd PID)
11 # - innodb_buffer_pool_size
12 #
13 # 2. Using the PID file, it finds the running mariadbd process ID.
14 #
15 # 3. It reads /proc/<pid>/smaps to inspect the memory regions allocated
16 # by the mariadbd process.
17 #
18 # 4. From the smaps output, it identifies candidate memory regions that:
19 # - are smaller than 192M
20 # - contain the "dd" VmFlag (indicating the region is eligible for
21 # core dump trimming)
22 #
23 # 5. It sums the size of these candidate memory regions.
24 #
25 # 6. If the candidate memory is large enough to cover the buffer pool,
26 # the script concludes that the buffer pool will not be part of core dump.
27 # Otherwise, it reports it to be part of core dump.
28 #
29 # Purpose:
30 # This helps verify whether InnoDB buffer pool will be excluded from the
31 # core dump, preventing unnecessarily large core files.
32 # ------------------------------------------------------------------------------
33
34 # Get the full path name of the PID file
35 --let $pid_file= query_get_value(SELECT @@pid_file, @@pid_file, 1)
36 --let PIDFILE= $pid_file
37
38 # Get innodb_buffer_pool_size
39 --let $innodb_buffer_pool_size= query_get_value(SELECT @@innodb_buffer_pool_size, @@innodb_buffer_pool_size, 1)
40 --let BUFFER_POOL_SIZE= $innodb_buffer_pool_size
41
42 perl;
43
44 use strict;
45 use warnings;
46
47 my $pid_file = $ENV{'PIDFILE'} or die "PIDFILE not set";
48
49 # Buffer pool size
50 my $buffer_pool_size = $ENV{'BUFFER_POOL_SIZE'};
51
52 # Convert to KB
53 my $buffer_pool_kb = int($buffer_pool_size / 1024);
54
55 # Ignore regions larger than 192M
56 my $max_region_kb = 192 * 1024;
57
58 # Sum of candidate regions
59 my $candidate_sum_kb = 0;
60
61 # Get PID of mariadbd
62 open(my $fh, '<', $pid_file) || die "Cannot open pid file $pid_file\n";
63 my $pid = <$fh>;
64 $pid =~ s/\s//g;
65 close($fh);
66
67 if ($pid eq "") {
68 die "Couldn't retrieve PID from PID file.\n";
69 }
70
71 # Open smaps
72 my $smaps_file = "/proc/$pid/smaps";
73
74 open(my $sm, '<', $smaps_file) or die "Cannot open $smaps_file\n";
75
76 my $current_size_kb = 0;
77
78 while (my $line = <$sm>) {
79
80 if ($line =~ /^Size:\s+(\d+)\s+kB/) {
81 $current_size_kb = $1;
82 }
83
84 if ($line =~ /^VmFlags:\s+(.*)/) {
85 my $flags = $1;
86
87 # Candidate region conditions
88 if ($current_size_kb <= $max_region_kb &&
89 $flags =~ /\bdd\b/) {
90 $candidate_sum_kb += $current_size_kb;
91 }
92 }
93 }
94
95 close($sm);
96
97 if ($candidate_sum_kb >= $buffer_pool_kb) {
98 print "Buffer pool not part of core dump.\n";
99 }
100 else {
101 print "Buffer pool part of core dump.\n";
102 }
103
104 EOF