Debian Codegraph @

crt/aws-c-common/include/aws/common/system_info.h

raw symbols SCIP
1 #ifndef AWS_COMMON_SYSTEM_INFO_H
2 #define AWS_COMMON_SYSTEM_INFO_H
3
4 /**
5 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6 * SPDX-License-Identifier: Apache-2.0.
7 */
8
9 #include <aws/common/byte_buf.h>
10 #include <aws/common/common.h>
11
12 AWS_PUSH_SANE_WARNING_LEVEL
13
14 /**
15 * Platform OS enumeration and their corresponding string representations.
16 *
17 * String mappings:
18 * - AWS_PLATFORM_OS_WINDOWS → "Windows" (Microsoft Windows family)
19 * - AWS_PLATFORM_OS_MAC → "macOS" (Apple desktop/laptop)
20 * - AWS_PLATFORM_OS_IOS → "iOS" (Apple mobile platforms, covers iOS, watchOS, tvOS,
21 * and other non-macOS Apple platforms)
22 * - AWS_PLATFORM_OS_ANDROID → "Android" (Google Android)
23 * - AWS_PLATFORM_OS_UNIX → "Unix" (Linux, BSD, other Unix-like)
24 */
25 enum aws_platform_os {
26 AWS_PLATFORM_OS_WINDOWS,
27 AWS_PLATFORM_OS_MAC,
28 AWS_PLATFORM_OS_IOS,
29 AWS_PLATFORM_OS_ANDROID,
30 AWS_PLATFORM_OS_UNIX,
31 };
32
33 struct aws_cpu_info {
34 int32_t cpu_id;
35 bool suspected_hyper_thread;
36 };
37
38 struct aws_system_environment;
39
40 AWS_EXTERN_C_BEGIN
41
42 /**
43 * Allocates and initializes information about the system the current process is executing on.
44 * If successful returns an instance of aws_system_environment. If it fails, it will return NULL.
45 *
46 * Note: This api is used internally and is still early in its evolution.
47 * It may change in incompatible ways in the future.
48 */
49 AWS_COMMON_API
50 struct aws_system_environment *aws_system_environment_load(struct aws_allocator *allocator);
51
52 AWS_COMMON_API
53 struct aws_system_environment *aws_system_environment_acquire(struct aws_system_environment *env);
54
55 AWS_COMMON_API
56 void aws_system_environment_release(struct aws_system_environment *env);
57
58 /**
59 * Returns the virtualization vendor for the specified compute environment, e.g. "Xen, Amazon EC2, etc..."
60 *
61 * The return value may be empty and in that case no vendor was detected.
62 */
63 AWS_COMMON_API
64 struct aws_byte_cursor aws_system_environment_get_virtualization_vendor(const struct aws_system_environment *env);
65
66 /**
67 * Returns the product name for the specified compute environment. For example, the Amazon EC2 Instance type.
68 *
69 * The return value may be empty and in that case no vendor was detected.
70 */
71 AWS_COMMON_API
72 struct aws_byte_cursor aws_system_environment_get_virtualization_product_name(const struct aws_system_environment *env);
73
74 /**
75 * Returns the number of processors for the specified compute environment.
76 */
77 AWS_COMMON_API
78 size_t aws_system_environment_get_processor_count(struct aws_system_environment *env);
79
80 /**
81 * Returns the number of separate cpu groupings (multi-socket configurations or NUMA).
82 */
83 AWS_COMMON_API
84 size_t aws_system_environment_get_cpu_group_count(const struct aws_system_environment *env);
85
86 /* Returns the OS this was built under */
87 AWS_COMMON_API
88 enum aws_platform_os aws_get_platform_build_os(void);
89
90 /* Returns the OS this was built under as a string */
91 AWS_COMMON_API
92 struct aws_byte_cursor aws_get_platform_build_os_string(void);
93
94 /* Returns the number of online processors available for usage. */
95 AWS_COMMON_API
96 size_t aws_system_info_processor_count(void);
97
98 /* Returns the system page size in bytes. */
99 AWS_COMMON_API
100 size_t aws_system_info_page_size(void);
101
102 /**
103 * Returns the logical processor groupings on the system (such as multiple numa nodes).
104 */
105 AWS_COMMON_API
106 uint16_t aws_get_cpu_group_count(void);
107
108 /**
109 * For a group, returns the number of CPUs it contains.
110 */
111 AWS_COMMON_API
112 size_t aws_get_cpu_count_for_group(uint16_t group_idx);
113
114 /**
115 * Fills in cpu_ids_array with the cpu_id's for the group. To obtain the size to allocate for cpu_ids_array
116 * and the value for argument for cpu_ids_array_length, call aws_get_cpu_count_for_group().
117 */
118 AWS_COMMON_API
119 void aws_get_cpu_ids_for_group(uint16_t group_idx, struct aws_cpu_info *cpu_ids_array, size_t cpu_ids_array_length);
120
121 /* Returns true if a debugger is currently attached to the process. */
122 AWS_COMMON_API
123 bool aws_is_debugger_present(void);
124
125 /* If a debugger is attached to the process, trip a breakpoint. */
126 AWS_COMMON_API
127 void aws_debug_break(void);
128
129 #if defined(AWS_HAVE_EXECINFO) || defined(_WIN32) || defined(__APPLE__)
130 # define AWS_BACKTRACE_STACKS_AVAILABLE
131 #endif
132
133 /*
134 * Records a stack trace from the call site.
135 * Returns the number of stack entries/stack depth captured, or 0 if the operation
136 * is not supported on this platform
137 */
138 AWS_COMMON_API
139 size_t aws_backtrace(void **stack_frames, size_t num_frames);
140
141 /*
142 * Converts stack frame pointers to symbols, if symbols are available
143 * Returns an array up to stack_depth long, that needs to be free()ed.
144 * stack_depth should be the length of frames.
145 * Returns NULL if the platform does not support stack frame translation
146 * or an error occurs
147 */
148 char **aws_backtrace_symbols(void *const *stack_frames, size_t stack_depth);
149
150 /*
151 * Converts stack frame pointers to symbols, using all available system
152 * tools to try to produce a human readable result. This call will not be
153 * quick, as it shells out to addr2line or similar tools.
154 * On Windows, this is the same as aws_backtrace_symbols()
155 * Returns an array up to stack_depth long that needs to be free()ed. Missing
156 * frames will be NULL.
157 * Returns NULL if the platform does not support stack frame translation
158 * or an error occurs
159 */
160 char **aws_backtrace_addr2line(void *const *stack_frames, size_t stack_depth);
161
162 /**
163 * Print a backtrace from either the current stack, or (if provided) the current exception/signal
164 * call_site_data is siginfo_t* on POSIX, and LPEXCEPTION_POINTERS on Windows, and can be null
165 */
166 AWS_COMMON_API
167 void aws_backtrace_print(FILE *fp, void *call_site_data);
168
169 /* Log the callstack from the current stack to the currently configured aws_logger */
170 AWS_COMMON_API
171 void aws_backtrace_log(int log_level);
172
173 AWS_EXTERN_C_END
174 AWS_POP_SANE_WARNING_LEVEL
175
176 #endif /* AWS_COMMON_SYSTEM_INFO_H */