Debian Codegraph @

mysql-test/suite/ndb/include/memory_usage.inc

raw
1 --perl
2 ##
3 ## NDB Memory Usage
4 ##
5 ## Include script that sets two variables that can be used to evaluate actual memory
6 ## usage in NDB data nodes
7 ##
8 ## Parameters:
9 ## $ndb_node_id - The node ID to get the memory usage for, can be a number of the node, or 'ALL',
10 ## which returns the average useage over all nodes. ALL is the default value.
11 ##
12 ## Returned variables:
13 ## $MTR_NDB_DATA_USAGE_PERCENTAGE - The percentage of data memory used on all nodes
14 ## $MTR_NDB_INDEX_USAGE_PERCENTAGE - The percentage of index memory used on all nodes
15 ##
16 ## Values are read from ndb_mgm REPORT MemoryUsage
17 ##
18 ## Example output from ALL REPORT MemoryUsage
19 ## ndb_mgm -e "ALL REPORT MemoryUsage"
20 ## Connected to Management Server at: localhost:16660
21 ## Node 1: Data usage is 85%(548 32K pages of total 640)
22 ## Node 1: Index usage is 86%(138 8K pages of total 160)
23 ## Node 2: Data usage is 85%(548 32K pages of total 640)
24 ## Node 2: Index usage is 86%(138 8K pages of total 160)
25
26 use strict;
27
28 use IO::File;
29
30 #
31 # Set up paths
32 #
33 my $vardir = $ENV{MYSQLTEST_VARDIR} or die "Need MYSQLTEST_VARDIR";
34 my $ndb_connectstring = $ENV{NDB_CONNECTSTRING} or die "Need NDB_CONNECTSTRING";
35 my $ndb_mgm = $ENV{NDB_MGM} or die "Need NDB_MGM";
36
37 # Input parameters
38 my $ndb_node_id = $ENV{ndb_node_id} || 'ALL';
39
40 my $cmd = "$ndb_mgm --ndb-connectstring='$ndb_connectstring' -e \"$ndb_node_id REPORT MemoryUsage\"";
41 # print "Calling ndb_mgm: '$cmd'\n";
42 my $output = `$cmd`;
43
44 my $memory = {};
45 foreach my $line (split("\n", $output)) {
46 # Skip empty lines
47 next if ($line =~ m/^,+$/g);
48
49 if ($line =~ m/Node (\d+): (Index|Data) usage is \d+%\((\d+) (\d+)K pages of total (\d+)\)/g) {
50 my $node_id = $1;
51 my $type = lc($2);
52 my $used = $3;
53 my $size = $4;
54 my $total = $5;
55
56 if (!defined $memory->{$type}) {
57 $memory->{$type} = {}
58 }
59 if (!defined $memory->{$type}->{$node_id}) {
60 $memory->{$type}->{$node_id} = {};
61 }
62 $memory->{$type}->{$node_id}->{'used'} = $used;
63 $memory->{$type}->{$node_id}->{'total'} = $total;
64 $memory->{$type}->{$node_id}->{'size'} = $size;
65 }
66 }
67
68 sub usage_percentage {
69 my $type = lc(shift);
70 my $mem = shift;
71
72 my $used = 0;
73 my $total = 0;
74
75 foreach my $node (keys %{$mem->{$type}}) {
76 $used += $mem->{$type}->{$node}->{'used'};
77 $total += $mem->{$type}->{$node}->{'total'};
78 }
79 die "Parsing error - not able to detect total number of pages, output: '$output'" if ($total == 0);
80 return sprintf("%.2f", $used * 100 / $total);
81 }
82
83 my $num_nodes = scalar(keys %{$memory->{Data}});
84 my $data_usage_percentage = usage_percentage('Data', $memory);
85 my $index_usage_percentage = usage_percentage('Index', $memory);
86
87 my $file_name = "$vardir/tmp/ndb_memory_usage_result.inc";
88 my $F = IO::File->new($file_name, 'w') or die "Could not open '$file_name' for writing";
89 print $F "--let \$MTR_NDB_DATA_USAGE_PERCENTAGE= $data_usage_percentage\n";
90 print $F "--let \$MTR_NDB_INDEX_USAGE_PERCENTAGE= $index_usage_percentage\n";
91 $F->close();
92
93 EOF
94
95 --source $MYSQLTEST_VARDIR/tmp/ndb_memory_usage_result.inc