1 /* 2 * Copyright (c) 2023 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 unsigned long long cpu_usage_utime; 55 unsigned long long cpu_usage_stime; 56 unsigned long long cpu_load_time; 57 }; 58 59 struct ucollection_thread_filter { 60 int uid; 61 int pid; 62 int tid; 63 }; 64 65 struct ucollection_thread_cpu_entry { 66 int magic; 67 unsigned int total_count; 68 unsigned int cur_count; 69 struct ucollection_thread_filter filter; 70 struct ucollection_thread_cpu_item datas[]; 71 }; 72 73 enum collection_type { 74 COLLECT_ALL_PROC = 1, 75 COLLECT_THE_PROC, 76 COLLECT_APP_PROC, 77 COLLECT_PROC_COUNT, 78 COLLECT_THREAD_COUNT, 79 COLLECT_APP_THREAD, 80 COLLECT_THE_THREAD, 81 COLLECT_APP_THREAD_COUNT, 82 }; 83 84 #define PROCESS_TOTAL_COUNT 2500 85 #define IOCTRL_COLLECT_CPU_BASE 0 86 #define IOCTRL_COLLECT_ALL_PROC_CPU _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_ALL_PROC, \ 87 struct ucollection_process_cpu_entry) 88 #define IOCTRL_COLLECT_THE_PROC_CPU _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_THE_PROC, \ 89 struct ucollection_process_cpu_entry) 90 #define IOCTRL_COLLECT_PROC_COUNT _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_PROC_COUNT, unsigned int) 91 #define IOCTRL_COLLECT_THREAD_COUNT _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_THREAD_COUNT, \ 92 struct ucollection_process_thread_count) 93 #define IOCTRL_COLLECT_APP_THREAD_COUNT _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_APP_THREAD_COUNT, \ 94 struct ucollection_process_thread_count) 95 #define IOCTRL_COLLECT_APP_THREAD _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_APP_THREAD, struct ucollection_thread_cpu_entry) 96 #define IOCTRL_COLLECT_THE_THREAD _IOR(IOCTRL_COLLECT_CPU_BASE, COLLECT_THE_THREAD, struct ucollection_thread_cpu_entry) 97 #endif // FRAMEWORK_NATIVE_UNIFIED_COLLECTION_COLLECTOR_UNIFIED_COLLECTION_DATA 98