1 /* 2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef FRAMEWORK_NATIVE_UNIFIED_COLLECTION_COLLECTOR_UNIFIED_COLLECTION_DATA 16 #define FRAMEWORK_NATIVE_UNIFIED_COLLECTION_COLLECTOR_UNIFIED_COLLECTION_DATA 17 18 #include <cstdint> 19 #include <string> 20 #include <sys/ioctl.h> 21 22 // kernel struct, modify at the same time 23 struct ucollection_process_cpu_item { 24 int pid; 25 unsigned int thread_total; 26 unsigned long long min_flt; 27 unsigned long long maj_flt; 28 unsigned long long cpu_usage_utime; 29 unsigned long long cpu_usage_stime; 30 unsigned long long cpu_load_time; 31 }; 32 33 struct ucollection_process_filter { 34 int uid; 35 int pid; 36 int tid; 37 }; 38 39 struct ucollection_process_cpu_entry { 40 int magic; 41 unsigned int total_count; 42 unsigned int cur_count; 43 struct ucollection_process_filter filter; 44 struct ucollection_process_cpu_item datas[]; 45 }; 46 47 struct ucollection_process_thread_count { 48 int pid; 49 unsigned int thread_count; 50 }; 51 52 struct ucollection_thread_cpu_item { 53 int tid; 54 char name[16]; // 16 :max length of thread name 55 unsigned long long cpu_usage_utime; 56 unsigned long long cpu_usage_stime; 57 unsigned long long cpu_load_time; 58 }; 59 60 struct ucollection_thread_filter { 61 int uid; 62 int pid; 63 int tid; 64 }; 65 66 struct ucollection_thread_cpu_entry { 67 int magic; 68 unsigned int total_count; 69 unsigned int cur_count; 70 struct ucollection_thread_filter filter; 71 struct ucollection_thread_cpu_item datas[]; 72 }; 73 74 enum collection_type { 75 COLLECT_ALL_PROC = 1, 76 COLLECT_THE_PROC, 77 COLLECT_APP_PROC, 78 COLLECT_PROC_COUNT, 79 COLLECT_THREAD_COUNT, 80 COLLECT_APP_THREAD, 81 COLLECT_THE_THREAD, 82 COLLECT_APP_THREAD_COUNT, 83 }; 84 85 #define PROCESS_TOTAL_COUNT 2500 86 #define IOCTRL_COLLECT_CPU_BASE 0 87 #define IOCTRL_COLLECT_ALL_PROC_CPU _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_ALL_PROC, \ 88 struct ucollection_process_cpu_entry) 89 #define IOCTRL_COLLECT_THE_PROC_CPU _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_THE_PROC, \ 90 struct ucollection_process_cpu_entry) 91 #define IOCTRL_COLLECT_PROC_COUNT _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_PROC_COUNT, unsigned int) 92 #define IOCTRL_COLLECT_THREAD_COUNT _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_THREAD_COUNT, \ 93 struct ucollection_process_thread_count) 94 #define IOCTRL_COLLECT_APP_THREAD_COUNT _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_APP_THREAD_COUNT, \ 95 struct ucollection_process_thread_count) 96 #define IOCTRL_COLLECT_APP_THREAD _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_APP_THREAD, struct ucollection_thread_cpu_entry) 97 #define IOCTRL_COLLECT_THE_THREAD _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_THE_THREAD, struct ucollection_thread_cpu_entry) 98 #endif // FRAMEWORK_NATIVE_UNIFIED_COLLECTION_COLLECTOR_UNIFIED_COLLECTION_DATA 99