MySQL 26.10.0
Source Code Documentation
system_info_macos.h
Go to the documentation of this file.
1/* Copyright (c) 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#pragma once
25
26#include <mach/mach.h>
27
28#include <chrono>
29#include <cstddef>
30#include <cstdint>
31#include <string>
32#include <system_error>
33#include <vector>
34
36
38
39/** Result of collecting one native macOS thread. */
41
42/** Native macOS values collected for one thread. */
45 uint64_t tid{0};
46 std::string name;
47 int run_state{0};
48 int64_t user_seconds{0};
50 int64_t system_seconds{0};
52};
53
54/** Callbacks used to release native macOS thread resources. */
56 void *context{nullptr};
57 kern_return_t (*deallocate_port)(void *context, mach_port_t port){nullptr};
58 kern_return_t (*deallocate_memory)(void *context, vm_address_t address,
59 vm_size_t size){nullptr};
60};
61
62/** Own native thread ports and the Mach allocated thread array. */
64 public:
65 macOS_thread_resources(thread_act_array_t threads,
66 mach_msg_type_number_t thread_count,
67 macOS_thread_deallocator deallocator);
71
72 /** Release every owned right and the thread array exactly once. */
73 [[nodiscard]] std::error_code release();
74
75 private:
76 thread_act_array_t m_threads;
77 mach_msg_type_number_t m_thread_count;
79 bool m_released{false};
80 std::error_code m_release_error;
81};
82
83/** Map a macOS native thread run state to the public thread state. */
84[[nodiscard]] Thread_state macos_thread_state(int run_state);
85
86/** Convert a macOS time value to whole milliseconds. */
87[[nodiscard]] bool macos_time_value_to_milliseconds(
88 int64_t seconds, int64_t microseconds,
90
91/** Copy a possibly unterminated native thread name without exceeding size. */
92[[nodiscard]] std::string copy_bounded_macos_thread_name(const char *name,
93 size_t size);
94
95/** Build aligned thread inventory and CPU snapshots from native samples. */
96[[nodiscard]] std::error_code map_macos_thread_samples(
97 std::vector<macOS_thread_sample> samples,
98 std::error_code disappearance_error, Thread_inventory &inventory,
100
101/** Release native resources and publish only after successful cleanup. */
103 std::error_code collection_error,
104 Thread_inventory inventory,
107
108} // namespace mysql::system_info::internal
Own native thread ports and the Mach allocated thread array.
Definition: system_info_macos.h:63
mach_msg_type_number_t m_thread_count
Definition: system_info_macos.h:77
macOS_thread_resources & operator=(const macOS_thread_resources &)=delete
~macOS_thread_resources()
Release owned Mach resources if the collector has not released them.
Definition: system_info_macos.cc:171
thread_act_array_t m_threads
Definition: system_info_macos.h:76
bool m_released
Definition: system_info_macos.h:79
std::error_code release()
Release every owned right and the thread array exactly once.
Definition: system_info_macos.cc:183
macOS_thread_resources(thread_act_array_t threads, mach_msg_type_number_t thread_count, macOS_thread_deallocator deallocator)
Take ownership of the thread ports and array returned by task_threads().
Definition: system_info_macos.cc:163
macOS_thread_resources(const macOS_thread_resources &)=delete
macOS_thread_deallocator m_deallocator
Definition: system_info_macos.h:78
std::error_code m_release_error
Definition: system_info_macos.h:80
std::chrono::seconds seconds
Definition: authorize_manager.cc:71
std::chrono::milliseconds milliseconds
Definition: authorize_manager.cc:70
Definition: system_info_linux.cc:46
Thread_state macos_thread_state(int run_state)
Map a native Mach thread state to the portable thread state.
Definition: system_info_macos.cc:234
macOS_thread_sample_state
Result of collecting one native macOS thread.
Definition: system_info_macos.h:40
std::error_code map_macos_thread_samples(std::vector< macOS_thread_sample > samples, std::error_code disappearance_error, Thread_inventory &inventory, Thread_cpu_snapshot &cpu)
Build matching thread inventory and CPU snapshots from native samples.
Definition: system_info_macos.cc:306
bool macos_time_value_to_milliseconds(int64_t seconds, int64_t microseconds, std::chrono::milliseconds &milliseconds)
Convert a Mach time_value_t value to whole milliseconds.
Definition: system_info_macos.cc:260
void complete_macos_thread_collection(macOS_thread_resources &resources, std::error_code collection_error, Thread_inventory inventory, Thread_cpu_snapshot cpu, Process_threads_snapshot &result)
Release native thread resources before publishing the collected snapshots.
Definition: system_info_macos.cc:368
std::string copy_bounded_macos_thread_name(const char *name, size_t size)
Copy a thread name from a fixed size native buffer.
Definition: system_info_macos.cc:290
Thread_state
Portable execution state of a process thread.
Definition: system_info.h:370
size_t size(const char *const c)
Definition: base64.h:46
required uint64 port
Definition: replication_asynchronous_connection_failover.proto:33
Process thread capabilities collected at one collection point.
Definition: system_info.h:450
Portable thread CPU times collected at one collection point.
Definition: system_info.h:407
Process threads visible at one collection point.
Definition: system_info.h:387
Callbacks used to release native macOS thread resources.
Definition: system_info_macos.h:55
kern_return_t(* deallocate_port)(void *context, mach_port_t port)
Definition: system_info_macos.h:57
kern_return_t(* deallocate_memory)(void *context, vm_address_t address, vm_size_t size)
Definition: system_info_macos.h:58
void * context
Definition: system_info_macos.h:56
Native macOS values collected for one thread.
Definition: system_info_macos.h:43
int run_state
Definition: system_info_macos.h:47
int64_t user_seconds
Definition: system_info_macos.h:48
std::string name
Definition: system_info_macos.h:46
macOS_thread_sample_state sample_state
Definition: system_info_macos.h:44
int64_t user_microseconds
Definition: system_info_macos.h:49
uint64_t tid
Definition: system_info_macos.h:45
int64_t system_microseconds
Definition: system_info_macos.h:51
int64_t system_seconds
Definition: system_info_macos.h:50
Definition: result.h:30