Skip to content

Commit 141f621

Browse files
committed
WL#16940 Log available Server resources at Startup
Description: The MySQL server uses different methods to identify the total number of logical CPUs and total physical memory it can access. This worklog allows the MySQL server to log this information at startup. This change is seen only during normal startup i.e., when neither of `help`, `validate-config`, `initialize` or `initialize-insecure` is passed. This information is printed after the PID of the process is logged. Change-Id: Ifb34a6c867f6a957f8ce2d7c66ce051d2cd35409
1 parent a62cba1 commit 141f621

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

mysql-test/suite/perfschema/r/error_log.result

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ ORDER BY logged, error_code;
9898
prio error_code subsystem
9999
System MY-015015 Server
100100
System MY-010116 Server
101+
System MY-015569 Server
102+
System MY-015569 Server
101103
Warning MY-010075 Server
102104
System MY-013576 InnoDB
103105
Note MY-012944 InnoDB
@@ -161,7 +163,7 @@ AND prio!="Note"
161163
"MY-000067", "MY-010159", "MY-013595", "MY-013602",
162164
"MY-010108", "MY-012363", "MY-013711", "MY-013908",
163165
"MY-013930", "MY-000068", "MY-015015", "MY-010101",
164-
"MY-010099", "MY-011070")
166+
"MY-010099", "MY-011070", "MY-015569")
165167
ORDER BY logged;
166168
prio error_code subsystem data
167169
System MY-013576 InnoDB InnoDB initialization has started.

mysql-test/suite/perfschema/t/error_log.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ SELECT prio,error_code,subsystem
182182
# MY-010099: ER_SEC_FILE_PRIV_DIRECTORY_INSECURE
183183
# MY-010101: ER_SEC_FILE_PRIV_DIRECTORY_PERMISSIONS
184184
# MY-011070: ER_DEPRECATE_MSG_NO_REPLACEMENT
185+
# MY-015569: ER_SERVER_STARTING_WITH_RESOURCE, emits vcpus count and memory which varies with system
185186
SELECT prio,error_code,subsystem,data
186187
FROM performance_schema.error_log
187188
WHERE logged>=@startup
@@ -191,7 +192,7 @@ SELECT prio,error_code,subsystem,data
191192
"MY-000067", "MY-010159", "MY-013595", "MY-013602",
192193
"MY-010108", "MY-012363", "MY-013711", "MY-013908",
193194
"MY-013930", "MY-000068", "MY-015015", "MY-010101",
194-
"MY-010099", "MY-011070")
195+
"MY-010099", "MY-011070", "MY-015569")
195196
ORDER BY logged;
196197

197198
--echo

share/messages_to_error_log.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13137,6 +13137,9 @@ ER_VAR_REGISTRATION
1313713137
ER_VAR_DEREGISTRATION
1313813138
eng "Cannot unregister variable '%s.%s'. Please check if it was registered properly in the first place."
1313913139

13140+
ER_SERVER_STARTING_WITH_RESOURCE
13141+
eng "MySQL Server has access to %llu %s."
13142+
1314013143
################################################################################
1314113144
# Error numbers 50000 to 51999 are reserved. Please do not use them for
1314213145
# other error messages.

sql/mysqld.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,7 @@ MySQL clients support the protocol:
721721
#include "myisam.h"
722722
#include "mysql/binlog/event/binlog_event.h"
723723
#include "mysql/binlog/event/control_events.h"
724+
#include "mysql/components/library_mysys/my_system.h" // my_num_vcpus
724725
#include "mysql/components/services/bits/psi_bits.h"
725726
#include "mysql/components/services/log_builtins.h"
726727
#include "mysql/components/services/log_shared.h"
@@ -6579,6 +6580,20 @@ void unregister_server_telemetry_loggers() {
65796580
mysql_log_client_unregister(err_loggers, std::size(err_loggers));
65806581
}
65816582

6583+
/**
6584+
Log the system resources available to the server. The resources includes the
6585+
number of logical CPUs and total physical memory.
6586+
*/
6587+
static inline void print_available_resources() {
6588+
if (!(opt_help || opt_validate_config || opt_initialize ||
6589+
opt_initialize_insecure)) {
6590+
LogErr(SYSTEM_LEVEL, ER_SERVER_STARTING_WITH_RESOURCE, my_num_vcpus(),
6591+
"logical CPUs");
6592+
LogErr(SYSTEM_LEVEL, ER_SERVER_STARTING_WITH_RESOURCE, my_physical_memory(),
6593+
"bytes of physical memory");
6594+
}
6595+
}
6596+
65826597
int init_common_variables() {
65836598
#if defined(HAVE_BUILD_ID_SUPPORT)
65846599
my_find_build_id(server_build_id);
@@ -6779,6 +6794,8 @@ int init_common_variables() {
67796794
DBUG_PRINT("info", ("%s Ver %s for %s on %s\n", my_progname, server_version,
67806795
SYSTEM_TYPE, MACHINE_TYPE));
67816796

6797+
print_available_resources();
6798+
67826799
#ifdef HAVE_LINUX_LARGE_PAGES
67836800
/* Initialize large page size */
67846801
if (opt_large_pages && (opt_large_page_size = my_get_large_page_size())) {

0 commit comments

Comments
 (0)