2006-07-16 01:46:36 +08:00
|
|
|
/*
|
2010-04-29 05:57:11 +08:00
|
|
|
* Copyright (c) 2004-2008 Hyperic, Inc.
|
|
|
|
* Copyright (c) 2009 SpringSource, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2006-07-16 01:46:36 +08:00
|
|
|
*/
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
#ifndef SIGAR_UTIL_H
|
|
|
|
#define SIGAR_UTIL_H
|
|
|
|
|
|
|
|
/* most of this is crap for dealing with linux /proc */
|
|
|
|
#define UITOA_BUFFER_SIZE \
|
|
|
|
(sizeof(int) * 3 + 1)
|
|
|
|
|
|
|
|
#define SSTRLEN(s) \
|
|
|
|
(sizeof(s)-1)
|
|
|
|
|
|
|
|
#define sigar_strtoul(ptr) \
|
|
|
|
strtoul(ptr, &ptr, 10)
|
|
|
|
|
2006-10-11 00:27:01 +08:00
|
|
|
#define sigar_strtoull(ptr) \
|
|
|
|
strtoull(ptr, &ptr, 10)
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
#define sigar_isspace(c) \
|
|
|
|
(isspace(((unsigned char)(c))))
|
|
|
|
|
|
|
|
#define sigar_isdigit(c) \
|
|
|
|
(isdigit(((unsigned char)(c))))
|
|
|
|
|
|
|
|
#define sigar_isalpha(c) \
|
|
|
|
(isalpha(((unsigned char)(c))))
|
|
|
|
|
2007-03-02 22:09:13 +08:00
|
|
|
#define sigar_isupper(c) \
|
|
|
|
(isupper(((unsigned char)(c))))
|
|
|
|
|
2008-03-27 05:29:17 +08:00
|
|
|
#define sigar_tolower(c) \
|
|
|
|
(tolower(((unsigned char)(c))))
|
|
|
|
|
2007-06-27 09:10:12 +08:00
|
|
|
#ifdef WIN32
|
|
|
|
#define sigar_fileno _fileno
|
|
|
|
#define sigar_isatty _isatty
|
|
|
|
#define sigar_write _write
|
|
|
|
#else
|
|
|
|
#define sigar_fileno fileno
|
|
|
|
#define sigar_isatty isatty
|
|
|
|
#define sigar_write write
|
|
|
|
#endif
|
|
|
|
|
2005-10-08 00:18:50 +08:00
|
|
|
#ifndef PROC_FS_ROOT
|
2004-06-22 06:37:04 +08:00
|
|
|
#define PROC_FS_ROOT "/proc/"
|
2005-10-08 00:18:50 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PROCP_FS_ROOT
|
|
|
|
#define PROCP_FS_ROOT "/proc/"
|
|
|
|
#endif
|
2004-06-22 06:37:04 +08:00
|
|
|
|
2008-03-17 03:19:35 +08:00
|
|
|
sigar_int64_t sigar_time_now_millis(void);
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
char *sigar_uitoa(char *buf, unsigned int n, int *len);
|
|
|
|
|
2007-05-19 11:50:27 +08:00
|
|
|
int sigar_inet_ntoa(sigar_t *sigar,
|
|
|
|
sigar_uint32_t address,
|
|
|
|
char *addr_str);
|
|
|
|
|
2006-03-03 06:53:09 +08:00
|
|
|
struct hostent *sigar_gethostbyname(const char *name,
|
|
|
|
sigar_hostent_t *data);
|
2006-02-27 09:21:07 +08:00
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
SIGAR_INLINE char *sigar_skip_line(char *buffer, int buflen);
|
|
|
|
|
|
|
|
SIGAR_INLINE char *sigar_skip_token(char *p);
|
|
|
|
|
|
|
|
SIGAR_INLINE char *sigar_skip_multiple_token(char *p, int count);
|
|
|
|
|
2005-12-13 09:33:33 +08:00
|
|
|
char *sigar_getword(char **line, char stop);
|
|
|
|
|
2008-03-27 05:29:17 +08:00
|
|
|
char *sigar_strcasestr(const char *s1, const char *s2);
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
int sigar_file2str(const char *fname, char *buffer, int buflen);
|
|
|
|
|
|
|
|
int sigar_proc_file2str(char *buffer, int buflen,
|
|
|
|
sigar_pid_t pid,
|
|
|
|
const char *fname,
|
|
|
|
int fname_len);
|
|
|
|
|
|
|
|
#define SIGAR_PROC_FILE2STR(buffer, pid, fname) \
|
|
|
|
sigar_proc_file2str(buffer, sizeof(buffer), \
|
|
|
|
pid, fname, SSTRLEN(fname))
|
|
|
|
|
|
|
|
#define SIGAR_PROC_FILENAME(buffer, pid, fname) \
|
|
|
|
sigar_proc_filename(buffer, sizeof(buffer), \
|
|
|
|
pid, fname, SSTRLEN(fname))
|
|
|
|
|
|
|
|
#define SIGAR_SKIP_SPACE(ptr) \
|
|
|
|
while (sigar_isspace(*ptr)) ++ptr
|
|
|
|
|
|
|
|
char *sigar_proc_filename(char *buffer, int buflen,
|
|
|
|
sigar_pid_t pid,
|
|
|
|
const char *fname, int fname_len);
|
|
|
|
|
|
|
|
int sigar_proc_list_procfs_get(sigar_t *sigar,
|
|
|
|
sigar_proc_list_t *proclist);
|
|
|
|
|
|
|
|
int sigar_proc_fd_count(sigar_t *sigar, sigar_pid_t pid,
|
|
|
|
sigar_uint64_t *total);
|
|
|
|
|
2005-02-09 15:29:31 +08:00
|
|
|
/* linux + freebsd */
|
|
|
|
int sigar_procfs_args_get(sigar_t *sigar, sigar_pid_t pid,
|
|
|
|
sigar_proc_args_t *procargs);
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
int sigar_mem_calc_ram(sigar_t *sigar, sigar_mem_t *mem);
|
|
|
|
|
2009-05-22 07:57:50 +08:00
|
|
|
int sigar_statvfs(sigar_t *sigar,
|
|
|
|
const char *dirname,
|
|
|
|
sigar_file_system_usage_t *fsusage);
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
double sigar_file_system_usage_calc_used(sigar_t *sigar,
|
|
|
|
sigar_file_system_usage_t *fs);
|
|
|
|
|
2008-03-16 09:54:24 +08:00
|
|
|
#define SIGAR_DEV_PREFIX "/dev/"
|
|
|
|
|
2008-03-16 10:21:25 +08:00
|
|
|
#define SIGAR_NAME_IS_DEV(dev) \
|
|
|
|
strnEQ(dev, SIGAR_DEV_PREFIX, SSTRLEN(SIGAR_DEV_PREFIX))
|
|
|
|
|
2008-03-16 09:54:24 +08:00
|
|
|
typedef struct {
|
|
|
|
char name[256];
|
|
|
|
int is_partition;
|
|
|
|
sigar_disk_usage_t disk;
|
|
|
|
} sigar_iodev_t;
|
|
|
|
|
|
|
|
sigar_iodev_t *sigar_iodev_get(sigar_t *sigar,
|
|
|
|
const char *dirname);
|
|
|
|
|
2008-04-09 14:29:08 +08:00
|
|
|
int sigar_cpu_core_count(sigar_t *sigar);
|
|
|
|
|
2008-04-11 11:28:33 +08:00
|
|
|
/* e.g. VM guest may have 1 virtual ncpu on multicore hosts */
|
|
|
|
#define sigar_cpu_socket_count(sigar) \
|
|
|
|
(sigar->ncpu < sigar->lcpu) ? sigar->ncpu : \
|
|
|
|
(sigar->ncpu / sigar->lcpu)
|
|
|
|
|
2008-04-09 14:29:08 +08:00
|
|
|
int sigar_cpu_core_rollup(sigar_t *sigar);
|
|
|
|
|
2004-07-02 09:25:35 +08:00
|
|
|
void sigar_cpu_model_adjust(sigar_t *sigar, sigar_cpu_info_t *info);
|
|
|
|
|
2006-01-04 05:47:26 +08:00
|
|
|
int sigar_cpu_mhz_from_model(char *model);
|
|
|
|
|
2005-12-15 02:40:13 +08:00
|
|
|
char *sigar_get_self_path(sigar_t *sigar);
|
|
|
|
|
2008-04-05 02:39:42 +08:00
|
|
|
#if defined(__sun) || defined(__FreeBSD__)
|
|
|
|
|
|
|
|
#define SIGAR_HAS_DLINFO_MODULES
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <link.h>
|
|
|
|
|
|
|
|
int sigar_dlinfo_modules(sigar_t *sigar, sigar_proc_modules_t *procmods);
|
|
|
|
#endif
|
|
|
|
|
2004-12-05 06:44:55 +08:00
|
|
|
typedef struct sigar_cache_entry_t sigar_cache_entry_t;
|
|
|
|
|
|
|
|
struct sigar_cache_entry_t {
|
|
|
|
sigar_cache_entry_t *next;
|
|
|
|
sigar_uint64_t id;
|
|
|
|
void *value;
|
2013-09-15 20:00:23 +08:00
|
|
|
sigar_uint64_t last_access_time;
|
2004-12-05 06:44:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
sigar_cache_entry_t **entries;
|
|
|
|
unsigned int count, size;
|
2004-12-06 04:48:35 +08:00
|
|
|
void (*free_value)(void *ptr);
|
2013-09-15 20:00:23 +08:00
|
|
|
sigar_uint64_t entry_expire_period;
|
|
|
|
sigar_uint64_t cleanup_period_millis;
|
|
|
|
sigar_uint64_t last_cleanup_time;
|
2004-12-05 06:44:55 +08:00
|
|
|
} sigar_cache_t;
|
|
|
|
|
2004-12-06 05:09:14 +08:00
|
|
|
sigar_cache_t *sigar_cache_new(int size);
|
2013-09-15 20:00:23 +08:00
|
|
|
sigar_cache_t *sigar_expired_cache_new(int size, sigar_uint64_t cleanup_period_millis, sigar_uint64_t entry_expire_period);
|
|
|
|
void sigar_cache_dump(sigar_cache_t *table);
|
2004-12-06 05:09:14 +08:00
|
|
|
|
|
|
|
sigar_cache_entry_t *sigar_cache_get(sigar_cache_t *table,
|
|
|
|
sigar_uint64_t key);
|
|
|
|
|
2006-06-20 08:13:12 +08:00
|
|
|
sigar_cache_entry_t *sigar_cache_find(sigar_cache_t *table,
|
|
|
|
sigar_uint64_t key);
|
|
|
|
|
2004-12-06 05:09:14 +08:00
|
|
|
void sigar_cache_destroy(sigar_cache_t *table);
|
|
|
|
|
2004-06-22 06:37:04 +08:00
|
|
|
#endif /* SIGAR_UTIL_H */
|