1 /* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap 2 * 3 * Copyright 2012 Matthew McCormick 4 * Copyright 2015 Pawel 'l0ner' Soltys 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #ifndef CPU_H_ 20 #define CPU_H_ 21 22 #include <sys/types.h> 23 24 #if defined(__APPLE__) && defined(__MACH__) 25 #define CP_USER 0 26 #define CP_SYS 1 27 #define CP_IDLE 2 28 #define CP_NICE 3 29 #define CP_STATES 4 30 #else 31 #define CP_USER 0 32 #define CP_NICE 1 33 #define CP_SYS 2 34 35 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) 36 // *BSD or OSX 37 #define CP_INTR 3 38 #define CP_IDLE 4 39 #define CP_STATES 5 40 #else 41 //linux 42 #define CP_IDLE 3 43 #define CP_STATES 4 44 #endif 45 #endif 46 47 float cpu_percentage( unsigned ); 48 uint32_t get_cpu_count(); 49 50 /** CPU percentage output mode. 51 * 52 * Examples: 53 * 54 * CPU_MODE_DEFAULT: 100% 55 * CPU_MODE_THREADS: 800% (8 cores, fully loaded) 56 */ 57 enum CPU_MODE 58 { 59 CPU_MODE_DEFAULT, 60 CPU_MODE_THREADS 61 }; 62 63 #endif 64