42 #include <px4_platform_common/posix.h> 54 #include <mach/mach.h> 59 #define dprintf(_fd, _text, ...) ((_fd) == 1 ? PX4_INFO((_text), ##__VA_ARGS__) : (void)(_fd)) 64 #define CL "\033[K" // clear line 86 char *clear_line =
"";
90 dprintf(fd,
"\033[H");
94 #if defined(__PX4_LINUX) || defined(__PX4_CYGWIN) || defined(__PX4_QURT) 95 dprintf(fd,
"%sTOP NOT IMPLEMENTED ON LINUX, QURT, WINDOWS (ONLY ON NUTTX, APPLE)\n", clear_line);
97 #elif defined(__PX4_DARWIN) 100 task_for_pid(mach_task_self(), pid, &task_handle);
102 task_info_data_t tinfo;
103 mach_msg_type_number_t th_info_cnt;
105 th_info_cnt = TASK_INFO_MAX;
106 kern_return_t kr = task_info(task_handle, TASK_BASIC_INFO, (task_info_t)tinfo, &th_info_cnt);
108 if (kr != KERN_SUCCESS) {
112 thread_array_t thread_list;
113 mach_msg_type_number_t th_cnt;
115 thread_info_data_t th_info_data;
116 mach_msg_type_number_t thread_info_count;
118 thread_basic_info_t basic_info_th;
119 uint32_t stat_thread = 0;
122 kr = task_threads(task_handle, &thread_list, &th_cnt);
124 if (kr != KERN_SUCCESS) {
125 PX4_WARN(
"ERROR getting thread list");
130 stat_thread += th_cnt;
137 dprintf(fd,
"%sThreads: %d total\n",
141 for (
unsigned j = 0; j < th_cnt; j++) {
142 thread_info_count = THREAD_INFO_MAX;
143 kr = thread_info(thread_list[j], THREAD_BASIC_INFO,
144 (thread_info_t)th_info_data, &thread_info_count);
146 if (kr != KERN_SUCCESS) {
147 PX4_WARN(
"ERROR getting thread info");
151 basic_info_th = (thread_basic_info_t)th_info_data;
153 if (!(basic_info_th->flags & TH_FLAGS_IDLE)) {
154 tot_sec = tot_sec + basic_info_th->user_time.seconds + basic_info_th->system_time.seconds;
155 tot_usec = tot_usec + basic_info_th->system_time.microseconds + basic_info_th->system_time.microseconds;
156 tot_cpu = tot_cpu + basic_info_th->cpu_usage;
164 dprintf(fd,
"thread %d\t\t %d\n", j, basic_info_th->cpu_usage);
167 kr = vm_deallocate(mach_task_self(), (vm_offset_t)thread_list,
168 th_cnt *
sizeof(thread_t));
170 if (kr != KERN_SUCCESS) {
171 PX4_WARN(
"ERROR cleaning up thread info");
void init_print_load_s(uint64_t t, struct print_load_s *s)
High-resolution timer with callouts and timekeeping.
void(* print_load_callback_f)(void *user)
Print the current system load.
struct system_load_s system_load
float interval_time_ms_inv
void print_load_buffer(uint64_t t, char *buffer, int buffer_length, print_load_callback_f cb, void *user, struct print_load_s *print_state)
Print load to a buffer, and call cb after each written line (buffer will not include ' ') ...
uint64_t interval_start_time
void print_load(uint64_t t, int fd, struct print_load_s *print_state)
uint32_t last_times[CONFIG_MAX_TASKS]