sigar/include/sigar_private.h

351 lines
9.2 KiB
C
Raw Normal View History

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_PRIVATE_DOT_H
#define SIGAR_PRIVATE_DOT_H
#include "sigar_log.h"
#include "sigar_ptql.h"
2004-06-22 06:37:04 +08:00
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifndef WIN32
#include <unistd.h>
2006-12-18 13:51:45 +08:00
#include <stddef.h>
2006-09-26 21:23:48 +08:00
#ifndef DARWIN
2004-06-22 06:37:04 +08:00
#include <strings.h>
#endif
2006-09-26 21:23:48 +08:00
#endif
2004-06-22 06:37:04 +08:00
2005-11-10 02:26:10 +08:00
#ifdef DMALLOC
2005-11-10 09:23:15 +08:00
#define _MEMORY_H /* exclude memory.h on solaris */
#define DMALLOC_FUNC_CHECK
2005-11-10 02:26:10 +08:00
#include <dmalloc.h>
#endif
2004-06-22 06:37:04 +08:00
/* common to all os sigar_t's */
/* XXX: this is ugly; but don't want the same stuffs
* duplicated on 4 platforms and am too lazy to change
* sigar_t to the way it was originally where sigar_t was
* common and contained a sigar_os_t.
* feel free trav ;-)
*/
#define SIGAR_T_BASE \
int cpu_list_cores; \
2004-06-22 06:37:04 +08:00
int log_level; \
void *log_data; \
sigar_log_impl_t log_impl; \
void *ptql_re_data; \
sigar_ptql_re_impl_t ptql_re_impl; \
2004-06-22 06:37:04 +08:00
unsigned int ncpu; \
unsigned long version; \
unsigned long boot_time; \
int ticks; \
sigar_pid_t pid; \
char errbuf[256]; \
char *ifconf_buf; \
2005-12-15 02:35:19 +08:00
int ifconf_len; \
char *self_path; \
2007-11-05 00:29:19 +08:00
sigar_cache_t *fsdev; \
sigar_cache_t *proc_cpu; \
2007-09-17 02:32:56 +08:00
sigar_cache_t *net_listen; \
sigar_cache_t *net_services_tcp; \
sigar_cache_t *net_services_udp
2004-06-22 06:37:04 +08:00
#if defined(WIN32)
# define SIGAR_INLINE __inline
#elif defined(__GNUC__)
# define SIGAR_INLINE inline
#else
# define SIGAR_INLINE
#endif
2005-11-10 02:26:10 +08:00
#ifdef DMALLOC
/* linux has its own strdup macro, make sure we use dmalloc's */
#define sigar_strdup(s) \
dmalloc_strndup(__FILE__, __LINE__, (s), -1, 0)
2005-11-10 02:26:10 +08:00
#else
2007-06-27 09:10:12 +08:00
# ifdef WIN32
# define sigar_strdup(s) _strdup(s)
# else
# define sigar_strdup(s) strdup(s)
# endif
2005-11-10 02:26:10 +08:00
#endif
2004-06-22 06:37:04 +08:00
#define SIGAR_ZERO(s) \
memset(s, '\0', sizeof(*(s)))
#define SIGAR_STRNCPY(dest, src, len) \
strncpy(dest, src, len); \
dest[len-1] = '\0'
/* we use fixed size buffers pretty much everywhere */
/* this is strncpy + ensured \0 terminator */
#define SIGAR_SSTRCPY(dest, src) \
SIGAR_STRNCPY(dest, src, sizeof(dest))
#ifndef strEQ
#define strEQ(s1, s2) (strcmp(s1, s2) == 0)
#endif
#ifndef strnEQ
#define strnEQ(s1, s2, n) (strncmp(s1, s2, n) == 0)
#endif
2006-12-18 13:51:45 +08:00
#ifdef offsetof
#define sigar_offsetof offsetof
#else
#define sigar_offsetof(type, field) ((size_t)(&((type *)0)->field))
#endif
#define SIGAR_MSEC 1000L
2006-12-05 02:44:28 +08:00
#define SIGAR_NSEC 1000000000L
2004-11-17 13:45:14 +08:00
#define SIGAR_SEC2NANO(s) \
2006-12-05 02:44:28 +08:00
((sigar_uint64_t)(s) * (sigar_uint64_t)SIGAR_NSEC)
2005-05-12 08:10:17 +08:00
/* cpu ticks to milliseconds */
#define SIGAR_TICK2MSEC(s) \
((sigar_uint64_t)(s) * ((sigar_uint64_t)SIGAR_MSEC / (double)sigar->ticks))
#define SIGAR_TICK2NSEC(s) \
((sigar_uint64_t)(s) * ((sigar_uint64_t)SIGAR_NSEC / (double)sigar->ticks))
/* nanoseconds to milliseconds */
#define SIGAR_NSEC2MSEC(s) \
((sigar_uint64_t)(s) / ((sigar_uint64_t)1000000L))
#define IFTYPE_LO 2
#define IFTYPE_ETH 3
2004-06-22 06:37:04 +08:00
#define SIGAR_LAST_PROC_EXPIRE 2
#define SIGAR_FS_MAX 10
#define SIGAR_CPU_INFO_MAX 4
#define SIGAR_CPU_LIST_MAX 4
#define SIGAR_PROC_LIST_MAX 256
#define SIGAR_PROC_ARGS_MAX 12
#define SIGAR_NET_ROUTE_LIST_MAX 6
#define SIGAR_NET_IFLIST_MAX 20
#define SIGAR_NET_CONNLIST_MAX 20
2005-02-22 09:50:16 +08:00
#define SIGAR_WHO_LIST_MAX 12
2004-06-22 06:37:04 +08:00
int sigar_os_open(sigar_t **sigar);
int sigar_os_close(sigar_t *sigar);
2005-03-12 14:19:34 +08:00
char *sigar_os_error_string(sigar_t *sigar, int err);
2004-06-22 06:37:04 +08:00
char *sigar_strerror_get(int err, char *errbuf, int buflen);
2007-04-16 07:06:57 +08:00
void sigar_strerror_set(sigar_t *sigar, char *msg);
void sigar_strerror_printf(sigar_t *sigar, const char *format, ...);
int sigar_sys_info_get_uname(sigar_sys_info_t *sysinfo);
int sigar_os_sys_info_get(sigar_t *sigar, sigar_sys_info_t *sysinfo);
2007-04-22 11:54:04 +08:00
int sigar_os_proc_list_get(sigar_t *sigar,
sigar_proc_list_t *proclist);
2004-06-22 06:37:04 +08:00
2007-04-23 01:54:36 +08:00
int sigar_proc_list_create(sigar_proc_list_t *proclist);
2004-06-22 06:37:04 +08:00
int sigar_proc_list_grow(sigar_proc_list_t *proclist);
#define SIGAR_PROC_LIST_GROW(proclist) \
if (proclist->number >= proclist->size) { \
sigar_proc_list_grow(proclist); \
}
2007-04-23 03:57:34 +08:00
int sigar_proc_args_create(sigar_proc_args_t *proclist);
2004-06-22 06:37:04 +08:00
int sigar_proc_args_grow(sigar_proc_args_t *procargs);
#define SIGAR_PROC_ARGS_GROW(procargs) \
if (procargs->number >= procargs->size) { \
sigar_proc_args_grow(procargs); \
}
2007-04-22 13:37:39 +08:00
int sigar_os_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_args_t *procargs);
2004-06-22 06:37:04 +08:00
int sigar_file_system_list_create(sigar_file_system_list_t *fslist);
int sigar_file_system_list_grow(sigar_file_system_list_t *fslist);
#define SIGAR_FILE_SYSTEM_LIST_GROW(fslist) \
if (fslist->number >= fslist->size) { \
sigar_file_system_list_grow(fslist); \
}
int sigar_os_fs_type_get(sigar_file_system_t *fsp);
/* os plugins that set fsp->type call fs_type_get directly */
#define sigar_fs_type_init(fsp) \
fsp->type = SIGAR_FSTYPE_UNKNOWN; \
sigar_fs_type_get(fsp)
void sigar_fs_type_get(sigar_file_system_t *fsp);
int sigar_cpu_info_list_create(sigar_cpu_info_list_t *cpu_infos);
2004-06-22 06:37:04 +08:00
int sigar_cpu_info_list_grow(sigar_cpu_info_list_t *cpu_infos);
2004-06-22 06:37:04 +08:00
#define SIGAR_CPU_INFO_LIST_GROW(cpu_infos) \
2004-06-22 06:37:04 +08:00
if (cpu_infos->number >= cpu_infos->size) { \
sigar_cpu_info_list_grow(cpu_infos); \
2004-06-22 06:37:04 +08:00
}
int sigar_cpu_list_create(sigar_cpu_list_t *cpulist);
int sigar_cpu_list_grow(sigar_cpu_list_t *cpulist);
#define SIGAR_CPU_LIST_GROW(cpulist) \
if (cpulist->number >= cpulist->size) { \
sigar_cpu_list_grow(cpulist); \
}
int sigar_net_route_list_create(sigar_net_route_list_t *routelist);
int sigar_net_route_list_grow(sigar_net_route_list_t *net_routelist);
#define SIGAR_NET_ROUTE_LIST_GROW(routelist) \
if (routelist->number >= routelist->size) { \
sigar_net_route_list_grow(routelist); \
}
int sigar_net_interface_list_create(sigar_net_interface_list_t *iflist);
int sigar_net_interface_list_grow(sigar_net_interface_list_t *iflist);
#define SIGAR_NET_IFLIST_GROW(iflist) \
if (iflist->number >= iflist->size) { \
sigar_net_interface_list_grow(iflist); \
}
int sigar_net_connection_list_create(sigar_net_connection_list_t *connlist);
int sigar_net_connection_list_grow(sigar_net_connection_list_t *connlist);
#define SIGAR_NET_CONNLIST_GROW(connlist) \
if (connlist->number >= connlist->size) { \
sigar_net_connection_list_grow(connlist); \
}
#define sigar_net_address_set(a, val) \
(a).addr.in = val; \
(a).family = SIGAR_AF_INET
2006-07-06 05:12:10 +08:00
#define sigar_net_address6_set(a, val) \
memcpy(&((a).addr.in6), val, sizeof((a).addr.in6)); \
(a).family = SIGAR_AF_INET6
2006-07-06 05:38:44 +08:00
#define SIGAR_IFHWADDRLEN 6
2006-07-06 05:33:59 +08:00
2006-07-06 05:12:10 +08:00
#define sigar_net_address_mac_set(a, val, len) \
memcpy(&((a).addr.mac), val, len); \
2006-07-06 05:12:10 +08:00
(a).family = SIGAR_AF_LINK
2006-07-06 05:33:59 +08:00
#define sigar_hwaddr_set_null(ifconfig) \
SIGAR_ZERO(&ifconfig->hwaddr.addr.mac); \
ifconfig->hwaddr.family = SIGAR_AF_LINK
2006-07-06 05:33:59 +08:00
2007-08-08 13:34:21 +08:00
int sigar_tcp_curr_estab(sigar_t *sigar, sigar_tcp_t *tcp);
2007-07-15 06:51:38 +08:00
2005-02-22 09:50:16 +08:00
int sigar_who_list_create(sigar_who_list_t *wholist);
int sigar_who_list_grow(sigar_who_list_t *wholist);
#define SIGAR_WHO_LIST_GROW(wholist) \
if (wholist->number >= wholist->size) { \
sigar_who_list_grow(wholist); \
}
2004-06-22 06:37:04 +08:00
int sigar_user_id_get(sigar_t *sigar, const char *name, int *uid);
int sigar_user_name_get(sigar_t *sigar, int uid, char *buf, int buflen);
int sigar_group_name_get(sigar_t *sigar, int gid, char *buf, int buflen);
#define SIGAR_PROC_ENV_KEY_LOOKUP() \
if ((procenv->type == SIGAR_PROC_ENV_KEY) && \
(pid == sigar->pid)) \
{ \
char *value = getenv(procenv->key); \
if (value != NULL) { \
procenv->env_getter(procenv->data, \
procenv->key, \
procenv->klen, \
value, strlen(value)); \
} \
return SIGAR_OK; \
}
2007-10-14 05:56:18 +08:00
#define SIGAR_DISK_STATS_INIT(disk) \
(disk)->reads = (disk)->writes = \
(disk)->read_bytes = (disk)->write_bytes = \
2007-11-04 07:01:20 +08:00
(disk)->queue = (disk)->time = \
(disk)->service_time = SIGAR_FIELD_NOTIMPL; \
(disk)->snaptime = 0
2007-10-14 05:56:18 +08:00
2007-10-10 05:53:34 +08:00
/* key used for filesystem (/) -> device (/dev/hda1) mapping */
2007-11-05 02:17:57 +08:00
/* and disk_usage cache for service_time */
#define SIGAR_FSDEV_ID(sb) \
(S_ISBLK((sb).st_mode) ? (sb).st_rdev : ((sb).st_ino + (sb).st_dev))
2007-10-10 05:53:34 +08:00
#if defined(WIN32) || defined(NETWARE)
int sigar_get_iftype(const char *name, int *type, int *inst);
#endif
2005-11-19 03:54:23 +08:00
#define SIGAR_NIC_LOOPBACK "Local Loopback"
#define SIGAR_NIC_ETHERNET "Ethernet"
#define SIGAR_NIC_NETROM "AMPR NET/ROM"
2006-03-03 10:31:21 +08:00
#ifndef WIN32
#include <netdb.h>
#endif
2006-03-03 10:31:21 +08:00
#define SIGAR_HOSTENT_LEN 512
#if defined(_AIX)
#define SIGAR_HAS_HOSTENT_DATA
#endif
typedef struct {
2006-03-03 10:31:21 +08:00
char buffer[SIGAR_HOSTENT_LEN];
int error;
2006-03-03 10:31:21 +08:00
#ifndef WIN32
struct hostent hs;
#endif
#ifdef SIGAR_HAS_HOSTENT_DATA
struct hostent_data hd;
#endif
} sigar_hostent_t;
2004-06-22 06:37:04 +08:00
#endif