/* * (C) 2007-2010 Alibaba Group Holding Limited. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * * Version: $Id: func.h 983 2011-10-31 09:59:33Z duanfei $ * * Authors: * duolong * - initial release * */ #ifndef TFS_COMMON_FUNC_H_ #define TFS_COMMON_FUNC_H_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace common { class Func { public: static int make_directory(char* path); static char* str_to_lower(char* psz_buf); static char* str_to_upper(char* psz_buf); static uint32_t crc(uint32_t crc, const char* data, const int32_t len); static int64_t curr_time(); static std::string time_to_str(time_t t, int f = 0); //added by zzy //static void sleep(const float f_heart_interval, bool& stop); //static void sleep(const float f_heart_interval, int32_t& stop); //added by zzy /* bit opertion */ static int32_t set_bit(int32_t& data, int32_t index); static int32_t clr_bit(int32_t& data, int32_t index); static int32_t test_bit(int32_t data, int32_t index); static const uint32_t _crc32tab[]; static const uint32_t CRC_VALUE; static int32_t split_string(const char* line, const char del, std::vector& fields); static int GetLocalIP (const char *dev_name, char *ip); static int get_load_avg(); static int get_base_name(const char* path, char* dirpath); static int write_pid(const char* lock_file); static uint64_t getphymemsize (); static uint32_t get_local_addr(const char* dev_name); static bool get_cpu_mem(float &cpu,size_t &mem, int pid,int tid); //added by zzy static bool get_sys_cpu_mem(float & sys_cpu_prec, float & sys_mem_prec, size_t & sys_mem_used); static bool get_sys_net_io(float & sys_net_io); //added by zzy static int get_disk_usage (const char *path, int64_t * used_bytes,int64_t * total_bytes, int64_t *used_rate); }; } #endif //TFS_COMMON_FUNC_H_