2006-07-16 01:46:36 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
|
|
|
|
* This file is part of SIGAR.
|
|
|
|
*
|
|
|
|
* SIGAR is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation. This program is distributed
|
|
|
|
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
|
|
|
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
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))))
|
|
|
|
|
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
|
|
|
|
|
|
|
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);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
double sigar_file_system_usage_calc_used(sigar_t *sigar,
|
|
|
|
sigar_file_system_usage_t *fs);
|
|
|
|
|
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);
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
sigar_cache_entry_t **entries;
|
|
|
|
unsigned int count, size;
|
2004-12-06 04:48:35 +08:00
|
|
|
void (*free_value)(void *ptr);
|
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);
|
|
|
|
|
|
|
|
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 */
|