libsysactivity-0.6.5/0000755000175000017500000000000012220245632013572 5ustar hazelhazellibsysactivity-0.6.5/build/0000755000175000017500000000000012220245632014671 5ustar hazelhazellibsysactivity-0.6.5/test/0000755000175000017500000000000012220245547014556 5ustar hazelhazellibsysactivity-0.6.5/test/test_swap.c0000644000175000017500000001125612220245547016740 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include "libsysactivity.h" int error = 0; void print_swap_info(struct sa_swap* swap) { #ifdef SA_SWAP_NAME printf("swap name: %s", swap->name); #endif #ifdef SA_SWAP_TYPE printf(swap->type == 1 ? ", type: partition" : ", type: file"); #endif #ifdef SA_SWAP_TOTAL printf(", total: %"PRIu64, swap->total); #endif #ifdef SA_SWAP_FREE printf(", free: %"PRIu64, swap->free); #endif printf("\n"); } void test_swap_info(struct sa_swap* swap) { if (swap->free > swap->total) { printf("%s:%d ERROR: The free swap space is larger than the total space\n", __FILE__, __LINE__); error = 1; } #ifdef SA_SWAP_NAME #ifdef __NetBSD__ size_t len = strlen(swap->name); #else size_t len = strnlen(swap->name, SA_SWAP_NAME); #endif if (len == 0) { printf("%s:%d ERROR: The length of the swap name is zero\n", __FILE__, __LINE__); error = 1; } if (len == SA_SWAP_NAME) { printf("%s:%d ERROR: The length of the swap name is equals to the maximum name length\n", __FILE__, __LINE__); error = 1; } #endif #ifdef SA_SWAP_TYPE if (swap->type != 1 && swap->type != 2) { printf("%s:%d ERROR: The value of the swap type is: %d\n", __FILE__, __LINE__, swap->type); error = 1; } #endif } void* get_swap_info(void* arg) { int i; int ret; #ifdef SA_OPEN_SWAP ret = sa_open_swap(); if (ret != 0) { printf("%s:%d ERROR: sa_open_swap(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif ret = sa_reset_swaps(); if (ret != 0) { printf("%s:%d ERROR: sa_reset_swaps(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } struct sa_swap swap; ret = sa_get_swap(0, &swap); if (ret == ENODEV) { printf("%s:%d WARNING: sa_get_swap() couldn't find any swap.\n", __FILE__, __LINE__); exit(EXIT_SUCCESS); } if (ret != 0) { printf("%s:%d ERROR: sa_get_swap(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } print_swap_info(&swap); printf("\n"); test_swap_info(&swap); struct sa_swap* swaps = NULL; for (i = 0; i < 5; i++) { uint16_t number_swaps = 0; ret = sa_count_swaps(&number_swaps); if (ret != 0) { printf("%s:%d ERROR: sa_count_swaps(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } printf("number of swaps: %d\n", number_swaps); ret = sa_reset_swaps(); if (ret != 0) { printf("%s:%d ERROR: sa_reset_swaps(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } swaps = (struct sa_swap*) realloc(swaps, number_swaps * sizeof (struct sa_swap)); uint16_t written = 0; ret = sa_get_swaps(swaps, number_swaps, &written); if (ret != 0) { printf("%s:%d ERROR: sa_get_swaps(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } int j; for (j = 0; j < written; j++) { printf("swap number %d\n", j); print_swap_info(&swaps[j]); printf("\n"); test_swap_info(&swaps[j]); } sleep(1); } if (swaps != NULL) free(swaps); #ifdef SA_CLOSE_SWAP ret = sa_close_swap(); if (ret != 0) { printf("%s:%d ERROR: sa_close_swap(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif #ifdef SA_OPEN_SWAP ret = sa_open_swap(); if (ret != 0) { printf("%s:%d ERROR: sa_open_swap(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif #ifdef SA_CLOSE_SWAP ret = sa_close_swap(); if (ret != 0) { printf("%s:%d ERROR: sa_close_swap(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif return NULL; } int main() { pthread_t thread1; struct timespec delay; delay.tv_sec = 0; delay.tv_nsec = 500000000; pthread_create(&thread1, NULL, get_swap_info, NULL); nanosleep(&delay, NULL); get_swap_info(NULL); if (error) return EXIT_FAILURE; return EXIT_SUCCESS; } libsysactivity-0.6.5/test/test_process.c0000644000175000017500000001747312220245547017453 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include "libsysactivity.h" int error = 0; pid_t self_pid; void print_process_activity(struct sa_process_activity* activity) { #ifdef SA_PROCESS_PID printf("pid %d, ", (int) activity->pid); #endif #ifdef SA_PROCESS_STATE printf("state %d, ", activity->state); #endif #ifdef SA_PROCESS_USER_TIME printf("user_time %"PRIu64", ", activity->user_time); #endif #ifdef SA_PROCESS_SYS_TIME printf("sys_time %"PRIu64", ", activity->sys_time); #endif #ifdef SA_PROCESS_THREADS printf("threads %"PRIu32", ", activity->threads); #endif #ifdef SA_PROCESS_VM_SIZE printf("vm_size %"PRIu32", ", activity->vm_size); #endif #ifdef SA_PROCESS_RSS printf("rss %d ", activity->rss); #endif printf("\n"); } void print_process(struct sa_process* process) { #ifdef SA_PROCESS_PID printf("pid %d, ", (int) process->pid); #endif #ifdef SA_PROCESS_UID printf("uid %d, ", process->uid); #endif #ifdef SA_PROCESS_GID printf("gid %d, ", process->gid); #endif #ifdef SA_PROCESS_FILENAME printf("filename %s, ", process->filename); #endif #ifdef SA_PROCESS_CMDLINE printf("cmdline %s, ", process->cmdline); #endif #ifdef SA_PROCESS_PARENT_PID printf("parent pid %d, ", (int) process->parent_pid); #endif #ifdef SA_PROCESS_PGRP printf("pgrp %d, ", (int) process->pgrp); #endif #ifdef SA_PROCESS_SID printf("sid %d, ", (int) process->sid); #endif #ifdef SA_PROCESS_TTY printf("tty %d, ", (int) process->tty); #endif #ifdef SA_PROCESS_NICE printf("nice %d, ", process->nice); #endif #ifdef SA_PROCESS_START_TIME printf("start_time %"PRIu64", ", process->start_time); #endif print_process_activity(&process->activity); } void test_process_activity(struct sa_process_activity* activity) { #if !defined(__DragonFly__) && defined(SA_PROCESS_THREADS) // gcc -E -dM -x c /dev/null if (activity->threads == 0) { printf("%s:%d ERROR: The number of threads of the process %d is zero.\n", __FILE__, __LINE__, (int) activity->pid); error = 1; } #endif } void test_process(struct sa_process* process) { #ifdef SA_PROCESS_FILENAME #ifdef __NetBSD__ size_t len = strlen(process->filename); #else size_t len = strnlen(process->filename, SA_PROCESS_FILENAME); #endif if (len == 0) { printf("%s:%d ERROR: The length of the filename of the process %d is zero\n", __FILE__, __LINE__, (int) process->pid); error = 1; } #endif #ifdef SA_PROCESS_PARENT_PID if (process->parent_pid > 1) { struct sa_process parent; int ret = sa_get_process(process->parent_pid, &parent); if (ret != 0 && sa_get_process(process->pid, process) == 0) { // Checking if the current process still exists printf("%s:%d ERROR: Can't retrieve the parent (%d) of the process %d\n", __FILE__, __LINE__, (int) parent.pid, (int) process->pid); error = 1; } } #endif #ifdef SA_PROCESS_NICE if (process->nice < -20 || process->nice > 19) { printf("%s:%d ERROR: Nice value of the process %d is out of range (%d).\n", __FILE__, __LINE__, (int) process->pid, process->nice); error = 1; } #endif if (process->pid != process->activity.pid) { printf("%s:%d ERROR: The PIDs of the both structures are different.\n", __FILE__, __LINE__); error = 1; } test_process_activity(&process->activity); } void* get_process(void* arg) { int ret; #ifdef SA_OPEN_PROCESS ret = sa_open_process(); if (ret != 0) { printf("%s:%d ERROR: sa_open_process(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif pid_t pid; uint32_t written, size; ret = sa_get_processes_ids(&pid, 1, &written); if (ret != ENOMEM || written != 1) { // The value returned has to be ENOMEM because i asked for just one pid printf("%s:%d ERROR: sa_get_processes_ids(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } ret = sa_count_processes(&size); if (ret != 0) { printf("%s:%d ERROR: sa_count_processes(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } pid_t* pids = malloc(size * sizeof(pid_t)); ret = sa_get_processes_ids(pids, size, &written); if (ret != 0) { printf("%s:%d ERROR: sa_get_processes_ids(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } uint32_t i; printf("pids:"); for (i = 0; i < written; i++) printf(" %d", (int) pids[i]); printf("\n"); struct sa_process proc_beginning; ret = sa_get_process(self_pid, &proc_beginning); if (ret != 0) { printf("%s:%d ERROR: sa_get_process(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } print_process(&proc_beginning); printf("\n"); test_process(&proc_beginning); struct sa_process proc; struct sa_process_activity proc_activity; for (i = 0; i < 6; i++) { ret = sa_count_processes(&size); if (ret != 0 || size < 2) { printf("%s:%d ERROR: sa_count_processes(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } printf("there are %d processes\n", (int) size); pids = realloc(pids, size * sizeof(pid_t)); ret = sa_get_processes_ids(pids, size, &written); if (ret != 0) { printf("%s:%d ERROR: sa_get_processes_ids(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } uint32_t j; if (i % 2 == 0) { for (j = 0; j < written; j++) { ret = sa_get_process(pids[j], &proc); if (ret != 0) { printf("%s:%d ERROR: sa_get_process(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } print_process(&proc); test_process(&proc); } } else { for (j = 0; j < written; j++) { ret = sa_get_process_activity(pids[written - j - 1], &proc_activity); if (ret != 0) { printf("%s:%d ERROR: sa_get_process_activity(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } print_process_activity(&proc_activity); test_process_activity(&proc_activity); } } printf("\n"); sleep(1); } free(pids); #ifdef SA_CLOSE_PROCESS ret = sa_close_process(); if (ret != 0) { printf("%s:%d ERROR: sa_close_process(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif #ifdef SA_OPEN_PROCESS ret = sa_open_process(); if (ret != 0) { printf("%s:%d ERROR: sa_open_process(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif #if defined(SA_PROCESS_SYS_TIME) && defined(__linux__) if (proc.activity.sys_time <= proc_beginning.activity.sys_time) { printf("%s:%d ERROR: The sys_time of the process %d (self process) is not growing\n", __FILE__, __LINE__, (int) self_pid); exit(EXIT_FAILURE); } #endif #ifdef SA_CLOSE_PROCESS ret = sa_close_process(); if (ret != 0) { printf("%s:%d ERROR: sa_close_process(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif return NULL; } int main() { self_pid = getpid(); pthread_t thread1; struct timespec delay; delay.tv_sec = 0; delay.tv_nsec = 500000000; pthread_create(&thread1, NULL, get_process, NULL); nanosleep(&delay, NULL); get_process(NULL); if (error) return EXIT_FAILURE; return EXIT_SUCCESS; } libsysactivity-0.6.5/test/test_network.c0000644000175000017500000001504312220245547017455 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include "libsysactivity.h" char param_name[SA_NET_INTERFACE_NAME]; int error = 0; void print_net_info(struct sa_net_interface* dev) { #ifdef SA_NET_INTERFACE_NAME printf("%s\n received: ", dev->name); #endif #ifdef SA_NET_INTERFACE_RECEIVED_BYTES printf("%"PRIu64" bytes, ", dev->received_bytes); #endif #ifdef SA_NET_INTERFACE_RECEIVED_PACKETS printf("%"PRIu64" packets, ", dev->received_packets); #endif #ifdef SA_NET_INTERFACE_RECEIVED_ERRORS printf("%"PRIu64" errors, ", dev->received_errors); #endif #ifdef SA_NET_INTERFACE_RECEIVED_DROP printf("%"PRIu64" dropped, ", dev->received_drop); #endif #ifdef SA_NET_INTERFACE_RECEIVED_FIFO printf("%"PRIu64" fifo, ", dev->received_fifo); #endif #ifdef SA_NET_INTERFACE_RECEIVED_MULTICAST printf("%"PRIu64" multicast, ", dev->received_multicast); #endif printf("\n sent: "); #ifdef SA_NET_INTERFACE_SENT_BYTES printf("%"PRIu64" bytes, ", dev->sent_bytes); #endif #ifdef SA_NET_INTERFACE_SENT_PACKETS printf("%"PRIu64" packets, ", dev->sent_packets); #endif #ifdef SA_NET_INTERFACE_SENT_ERRORS printf("%"PRIu64" errors, ", dev->sent_errors); #endif #ifdef SA_NET_INTERFACE_SENT_DROP printf("%"PRIu64" dropped, ", dev->sent_drop); #endif #ifdef SA_NET_INTERFACE_SENT_FIFO printf("%"PRIu64" fifo, ", dev->sent_fifo); #endif #ifdef SA_NET_INTERFACE_SENT_MULTICAST printf("%"PRIu64" multicast, ", dev->sent_multicast); #endif printf("\n"); } void test_net_info(struct sa_net_interface* dev) { #ifdef SA_NET_INTERFACE_NAME #ifdef __NetBSD__ size_t len = strlen(dev->name); #else size_t len = strnlen(dev->name, SA_NET_INTERFACE_NAME); #endif if (len == 0) { printf("%s:%d ERROR: The length of the device name is zero\n", __FILE__, __LINE__); error = 1; } #endif } void* get_net_info(void* arg) { int ret; struct sa_net_interface* interfaces = NULL; #ifdef SA_OPEN_NET ret = sa_open_net(); if (ret != 0) { printf("%s:%d ERROR: sa_open_net(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif ret = sa_reset_net_interfaces(); if (ret != 0) { printf("%s:%d ERROR: sa_reset_net_interfaces(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } struct sa_net_interface dev; if (param_name[0] == '\0') #ifdef __linux__ // gcc -E -dM -x c /dev/null ret = sa_get_net_interface("lo", &dev); #else ret = sa_get_net_interface("lo0", &dev); #endif else ret = sa_get_net_interface(param_name, &dev); if (ret != 0) { printf("%s:%d ERROR: sa_get_net_interface(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } print_net_info(&dev); printf("\n"); test_net_info(&dev); int i; uint16_t number_interfaces, number_ids, written, j; char* ids = NULL; for (i = 0; i < 6; i++) { ret = sa_count_net_interfaces(&number_interfaces); if (ret != 0 || number_interfaces < 2) { printf("%s:%d ERROR: sa_count_net_interfaces(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } printf("There are %d network interfaces\n", number_interfaces); ret = sa_reset_net_interfaces(); if (ret != 0) { printf("%s:%d ERROR: sa_reset_net_interfaces(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } if (number_interfaces == 0) continue; if (i % 2 == 0) { ids = realloc(ids, number_interfaces * SA_NET_INTERFACE_NAME); ret = sa_get_net_interfaces_ids(ids, number_interfaces, &number_ids); if (ret != 0) { printf("%s:%d ERROR: sa_get_net_interfaces_ids(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } ret = sa_reset_net_interfaces(); if (ret != 0) { printf("%s:%d ERROR: sa_reset_net_interfaces(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } for (j = 0; j < number_ids; j++) { ret = sa_get_net_interface(&ids[(number_ids - j - 1) * SA_NET_INTERFACE_NAME], &dev); if (ret != 0) { printf("%s:%d ERROR: sa_get_net_interface(): %s, device: %s\n", __FILE__, __LINE__, strerror(ret), &ids[(number_ids - j - 1) * SA_NET_INTERFACE_NAME]); exit(EXIT_FAILURE); } print_net_info(&dev); test_net_info(&dev); } } else { interfaces = (struct sa_net_interface*) realloc(interfaces, number_interfaces * sizeof(struct sa_net_interface)); written = 0; ret = sa_get_net_interfaces(interfaces, number_interfaces, &written); if (ret != 0 || written < 2) { printf("%s:%d ERROR: sa_get_net_interfaces(): %s\n", __FILE__, __LINE__, strerror( ret)); exit(EXIT_FAILURE); } for (j = 0; j < written; j++) { print_net_info(&interfaces[j]); test_net_info(&interfaces[j]); } } printf("\n"); sleep(1); } if (interfaces != NULL) free(interfaces); #ifdef SA_CLOSE_NET ret = sa_close_net(); if (ret != 0) { printf("%s:%d ERROR: sa_close_net(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif #ifdef SA_OPEN_NET ret = sa_open_net(); if (ret != 0) { printf("%s:%d ERROR: sa_open_net(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif #ifdef SA_CLOSE_NET ret = sa_close_net(); if (ret != 0) { printf("%s:%d ERROR: sa_close_net(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif return NULL; } int main(int argc, char *argv[]) { if (argc > 1) strncpy(param_name, argv[1], SA_NET_INTERFACE_NAME); else param_name[0] = '\0'; pthread_t thread1; struct timespec delay; delay.tv_sec = 0; delay.tv_nsec = 500000000; pthread_create(&thread1, NULL, get_net_info, NULL); nanosleep(&delay, NULL); get_net_info(NULL); if (error) return EXIT_FAILURE; return EXIT_SUCCESS; } libsysactivity-0.6.5/test/test_memory.c0000644000175000017500000001265212220245547017277 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include "libsysactivity.h" int error = 0; void print_memory_info(struct sa_memory* memory) { #ifdef SA_MEMORY_TOTAL printf("total: %"PRIu64, memory->total); #endif #ifdef SA_MEMORY_FREE printf(", free: %"PRIu64, memory->free); #endif #ifdef SA_MEMORY_ACTIVE printf(", active: %"PRIu64, memory->active); #endif #ifdef SA_MEMORY_INACTIVE printf(", inactive: %"PRIu64, memory->inactive); #endif #ifdef SA_MEMORY_BUFFERS printf(", buffers: %"PRIu64, memory->buffers); #endif #ifdef SA_MEMORY_SWAP_TOTAL printf(", swap_total: %"PRIu64, memory->swap_total); #endif #ifdef SA_MEMORY_SWAP_FREE printf(", swap_free: %"PRIu64, memory->swap_free); #endif #ifdef SA_MEMORY_SWAP_CACHED printf(", swap_cached: %"PRIu64, memory->swap_cached); #endif #ifdef SA_MEMORY_DIRTY printf(", dirty: %"PRIu64, memory->dirty); #endif #ifdef SA_MEMORY_CACHED printf(", cached: %"PRIu64, memory->cached); #endif #ifdef SA_MEMORY_WIRED printf(", wired: %"PRIu64, memory->wired); #endif #ifdef SA_MEMORY_EXECUTABLE printf(", executable: %"PRIu64, memory->executable); #endif #ifdef SA_MEMORY_FILES printf(", files: %"PRIu64, memory->files); #endif #ifdef SA_MEMORY_LOCKED printf(", locked: %"PRIu64, memory->locked); #endif printf("\n"); } void test_memory_info(struct sa_memory* memory) { #if defined(SA_MEMORY_TOTAL) if (memory->total == 0) { printf("%s:%d ERROR: The total memory space is zero\n", __FILE__, __LINE__); error = 1; } #endif #if defined(SA_MEMORY_TOTAL) && defined(SA_MEMORY_FREE) if (memory->free >= memory->total) { printf("%s:%d ERROR: The free memory space is larger or equal than the total space\n", __FILE__, __LINE__); error = 1; } #endif #if defined(SA_MEMORY_TOTAL) && defined(SA_MEMORY_ACTIVE) if (memory->active > memory->total) { printf("%s:%d ERROR: Active memory is larger than total memory\n", __FILE__, __LINE__); error = 1; } if (memory->active < 1000) { printf("%s:%d ERROR: Active memory is lower than 1 kb\n", __FILE__, __LINE__); error = 1; } #endif #if defined(SA_MEMORY_TOTAL) && defined(SA_MEMORY_INACTIVE) if (memory->inactive > memory->total) { printf("%s:%d ERROR: Inactive memory is larger than total memory\n", __FILE__, __LINE__); error = 1; } #if !defined(__NetBSD__) // In my NetBSD 5.1rc4 system vmstat -s gives 0 inactive pages so it seems to be ok if (memory->inactive < 1000) { printf("%s:%d ERROR: Inactive memory is lower than 1 kb\n", __FILE__, __LINE__); error = 1; } #endif #endif #if defined(SA_MEMORY_TOTAL) && defined(SA_MEMORY_BUFFERS) if (memory->buffers > memory->total) { printf("%s:%d ERROR: Memory used in buffers is larger than total memory\n", __FILE__, __LINE__); error = 1; } #endif #ifdef SA_MEMORY_SWAP_TOTAL #ifdef SA_MEMORY_SWAP_FREE if (memory->swap_free > memory->swap_total) { printf("%s:%d ERROR: Free swap space is larger than total swap space\n", __FILE__, __LINE__); error = 1; } #endif #ifdef SA_MEMORY_SWAP_CACHED if (memory->swap_cached > memory->swap_total) { printf("%s:%d ERROR: Cached swap space is larger than total swap space\n", __FILE__, __LINE__); error = 1; } #endif #endif } void* get_memory_info(void* arg) { int i; int ret; struct sa_memory memory; #ifdef SA_OPEN_MEMORY ret = sa_open_memory(); if (ret != 0) { printf("%s:%d ERROR: sa_open_memory(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif for (i = 0; i < 6; i++) { ret = sa_get_memory(&memory); if (ret != 0) { printf("%s:%d ERROR: sa_get_memory(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } print_memory_info(&memory); printf("\n"); test_memory_info(&memory); sleep(1); } #ifdef SA_CLOSE_MEMORY ret = sa_close_memory(); if (ret != 0) { printf("%s:%d ERROR: sa_close_memory(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif #ifdef SA_OPEN_MEMORY ret = sa_open_memory(); if (ret != 0) { printf("%s:%d ERROR: sa_open_memory(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif #ifdef SA_CLOSE_MEMORY ret = sa_close_memory(); if (ret != 0) { printf("%s:%d ERROR: sa_close_memory(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif return NULL; } int main() { pthread_t thread1; struct timespec delay; delay.tv_sec = 0; delay.tv_nsec = 500000000; pthread_create(&thread1, NULL, get_memory_info, NULL); nanosleep(&delay, NULL); get_memory_info(NULL); if (error) return EXIT_FAILURE; return EXIT_SUCCESS; } libsysactivity-0.6.5/test/test_disk.c0000644000175000017500000001502212220245547016713 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include "libsysactivity.h" char param_name[SA_DISK_NAME]; int error = 0; void print_disk_info(struct sa_disk* hd) { #ifdef SA_DISK_NAME printf("%s: ", hd->name); #endif #ifdef SA_DISK_READS printf("%"PRIu64" reads, ", hd->reads); #endif #ifdef SA_DISK_READS_MERGED printf("%"PRIu64" reads merged, ", hd->reads_merged); #endif #ifdef SA_DISK_SECTORS_READ printf("%"PRIu64" sectors read, ", hd->sectors_read); #endif #ifdef SA_DISK_TIME_SPENT_READING printf("%"PRIu64" time spent reading, ", hd->time_spent_reading); #endif #ifdef SA_DISK_WRITES printf("%"PRIu64" writes, ", hd->writes); #endif #ifdef SA_DISK_SECTORS_WRITTEN printf("%"PRIu64" sectors written, ", hd->sectors_written); #endif #ifdef SA_DISK_TIME_SPENT_WRITING printf("%"PRIu64" time spent writing, ", hd->time_spent_writing); #endif #ifdef SA_DISK_BYTES_READ printf("%"PRIu64" bytes read, ", hd->bytes_read); #endif #ifdef SA_DISK_BYTES_WRITTEN printf("%"PRIu64" bytes written", hd->bytes_written); #endif printf("\n"); } void test_disk_info(struct sa_disk* hd) { #ifdef SA_DISK_READS #ifdef SA_DISK_SECTORS_READ if (hd->sectors_read < hd->reads) { printf("%s:%d ERROR: The number of sectors read is lower than the reads\n", __FILE__, __LINE__); error = 1; } #endif if (hd->reads != 0) { #if defined(SA_DISK_BYTES_READ) && !defined(__DragonFly__) if (hd->bytes_read == 0) { printf("%s:%d ERROR: The number of bytes read is zero\n", __FILE__, __LINE__); error = 1; } #endif } #endif #ifdef SA_DISK_WRITES #ifdef SA_DISK_SECTORS_WRITTEN if (hd->sectors_written < hd->writes) { printf("%s:%d ERROR: The number of sectors written is lower than the writes\n", __FILE__, __LINE__); error = 1; } #endif if (hd->writes != 0) { #ifdef SA_DISK_TIME_SPENT_WRITING if (hd->time_spent_writing == 0) { printf("%s:%d ERROR: The time spent writing is zero\n", __FILE__, __LINE__); error = 1; } #endif } #endif } void* get_disk_info(void* arg) { int ret; #ifdef SA_OPEN_DISK ret = sa_open_disk(); if (ret != 0) { printf("%s:%d ERROR: sa_open_disk(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif ret = sa_reset_disks(); if (ret != 0) { printf("%s:%d ERROR: sa_reset_disks(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } struct sa_disk dev; if (param_name[0] == '\0') #if defined(__linux__) // gcc -E -dM -x c /dev/null ret = sa_get_disk("sda", &dev); #elif defined(__OpenBSD__) || defined(__NetBSD__) ret = sa_get_disk("wd0", &dev); #elif defined(__sun__) ret = sa_get_disk("cmdk0", &dev); #elif defined(__DragonFly__) ret = sa_get_disk("ad1", &dev); #else ret = sa_get_disk("ad0", &dev); #endif else ret = sa_get_disk(param_name, &dev); if (ret != 0) { printf("%s:%d ERROR: sa_get_disk(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } print_disk_info(&dev); printf("\n"); test_disk_info(&dev); struct sa_disk* hds = NULL; char* ids = NULL; uint16_t number_disks, number_ids, written, i; for (i = 0; i < 6; i++) { ret = sa_count_disks(&number_disks); if (ret != 0 || number_disks == 0) { printf("%s:%d ERROR: sa_count_disks(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } printf("there are %d disks\n", number_disks); ret = sa_reset_disks(); if (ret != 0) { printf("%s:%d ERROR: sa_reset_disks(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } uint16_t j; if (i % 2 == 0) { ids = realloc(ids, number_disks * SA_DISK_NAME); ret = sa_get_disks_ids(ids, number_disks, &number_ids); if (ret != 0) { printf("%s:%d ERROR: sa_get_disks_ids(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } ret = sa_reset_disks(); if (ret != 0) { printf("%s:%d ERROR: sa_reset_disks(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } for (j = 0; j < number_ids; j++) { ret = sa_get_disk(&ids[(number_ids - j - 1) * SA_DISK_NAME], &dev); if (ret != 0) { printf("%s:%d ERROR: sa_get_disk(): %s, device: %s\n", __FILE__, __LINE__, strerror(ret), &ids[(number_ids - j - 1) * SA_DISK_NAME]); exit(EXIT_FAILURE); } print_disk_info(&dev); test_disk_info(&dev); } } else { hds = (struct sa_disk*) realloc(hds, number_disks * sizeof(struct sa_disk)); written = 0; ret = sa_get_disks(hds, number_disks, &written); if (ret != 0 || written == 0) { printf("%s:%d ERROR: sa_get_disks(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } for (j = 0; j < written; j++) { print_disk_info(&hds[j]); test_disk_info(&hds[j]); } } printf("\n"); sleep(1); } if (hds != NULL) free(hds); #ifdef SA_CLOSE_DISK ret = sa_close_disk(); if (ret != 0) { printf("%s:%d ERROR: sa_close_disk(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif #ifdef SA_OPEN_DISK ret = sa_open_disk(); if (ret != 0) { printf("%s:%d ERROR: sa_open_disk(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif #ifdef SA_CLOSE_DISK ret = sa_close_disk(); if (ret != 0) { printf("%s:%d ERROR: sa_close_disk(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif return NULL; } int main(int argc, char *argv[]) { if (argc > 1) strncpy(param_name, argv[1], SA_DISK_NAME); else param_name[0] = '\0'; pthread_t thread1; struct timespec delay; delay.tv_sec = 0; delay.tv_nsec = 500000000; pthread_create(&thread1, NULL, get_disk_info, NULL); nanosleep(&delay, NULL); get_disk_info(NULL); if (error) return EXIT_FAILURE; return EXIT_SUCCESS; } libsysactivity-0.6.5/test/test_cpu.c0000644000175000017500000001237512220245547016560 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include "libsysactivity.h" int error = 0; void print_cpu_info(struct sa_cpu* cpu) { #ifdef SA_CPU_USER printf("user: %f", cpu->user); #endif #ifdef SA_CPU_NICE printf(", nice: %f", cpu->nice); #endif #ifdef SA_CPU_SYSTEM printf(", system: %f", cpu->system); #endif #ifdef SA_CPU_IDLE printf(", idle: %f", cpu->idle); #endif #ifdef SA_CPU_WAITING_FOR_IO printf(", waiting_for_io: %f", cpu->waiting_for_io); #endif #ifdef SA_CPU_HARDWARE_IRQ printf(", hardware_irq: %f", cpu->hardware_irq); #endif #ifdef SA_CPU_SOFTWARE_IRQ printf(", software_irq: %f", cpu->software_irq); #endif #ifdef SA_CPU_STOLEN printf(", stolen: %f", cpu->stolen); #endif #ifdef SA_CPU_INTR printf(", intr: %f", cpu->intr); #endif printf("\n"); } void check_range(float cpu_time) { cpu_time = roundf(cpu_time); if (cpu_time > 100.0 || cpu_time < 0.0) { printf("%s:%d ERROR: cpu time out of range: %f\n", __FILE__, __LINE__, cpu_time); error = 1; } } void test_cpu_info(struct sa_cpu* cpu) { float sum = 0; #ifdef SA_CPU_USER check_range(cpu->user); sum += cpu->user; #endif #ifdef SA_CPU_NICE check_range(cpu->nice); sum += cpu->nice; #endif #ifdef SA_CPU_SYSTEM check_range(cpu->system); sum += cpu->system; #endif #ifdef SA_CPU_IDLE check_range(cpu->idle); sum += cpu->idle; #endif #ifdef SA_CPU_WAITING_FOR_IO check_range(cpu->waiting_for_io); sum += cpu->waiting_for_io; #endif #ifdef SA_CPU_HARDWARE_IRQ check_range(cpu->hardware_irq); sum += cpu->hardware_irq; #endif #ifdef SA_CPU_SOFTWARE_IRQ check_range(cpu->software_irq); sum += cpu->software_irq; #endif #ifdef SA_CPU_STOLEN check_range(cpu->stolen); sum += cpu->stolen; #endif #ifdef SA_CPU_INTR check_range(cpu->intr); sum += cpu->intr; #endif check_range(sum); if (sum < 90.0) // Sometimes it happens: user: 0.000000, nice: 0.000000, system: 0.000000, idle: 0.000000, waiting_for_io: 0.000000, hardware_irq: 0.000000, software_irq: 0.000000, stolen: 0.000000 printf("%s:%d WARNING: Summatory of all cpu times is lower than 90.0: %f\n", __FILE__, __LINE__, sum); } void* get_cpu_info(void* arg) { int i; int j; uint16_t number_cpus; uint16_t written; int ret; #ifdef SA_OPEN_CPU ret = sa_open_cpu(); if (ret != 0) { printf("%s:%d ERROR: sa_open_cpu(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif ret = sa_count_cpus(&number_cpus); if (ret != 0 || number_cpus == 0) { printf("%s:%d ERROR: sa_count_cpus(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } printf("Number of cpus: %u\n", number_cpus); ret = sa_reset_cpus(); if (ret != 0) { printf("%s:%d ERROR: sa_reset_cpus(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } struct sa_cpu* cpus = malloc(number_cpus * sizeof(struct sa_cpu)); ret = sa_get_cpu(0, cpus); if (ret != 0) { printf("%s:%d ERROR: sa_get_cpu(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } print_cpu_info(cpus); printf("\n"); sleep(1); for (i = 0; i < 6; i++) { ret = sa_reset_cpus(); if (ret != 0) { printf("%s:%d ERROR: sa_reset_cpus(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } written = 0; ret = sa_get_cpus(cpus, number_cpus, &written); if (ret != 0 || written == 0) { printf("%s:%d ERROR: sa_get_cpus(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } for (j = 0; j < written; j++) { printf("cpu index: %d\n", cpus[j].id); print_cpu_info(&cpus[j]); if (i > 0) test_cpu_info(&cpus[j]); } printf("\n"); sleep(1); } free(cpus); #ifdef SA_CLOSE_CPU ret = sa_close_cpu(); if (ret != 0) { printf("%s:%d ERROR: sa_close_cpu(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif #ifdef SA_OPEN_CPU ret = sa_open_cpu(); if (ret != 0) { printf("%s:%d ERROR: sa_open_cpu(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif #ifdef SA_CLOSE_CPU ret = sa_close_cpu(); if (ret != 0) { printf("%s:%d ERROR: sa_close_cpu(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif return NULL; } int main() { pthread_t thread1; struct timespec delay; delay.tv_sec = 0; delay.tv_nsec = 500000000; pthread_create(&thread1, NULL, get_cpu_info, NULL); nanosleep(&delay, NULL); get_cpu_info(NULL); if (error) return EXIT_FAILURE; return EXIT_SUCCESS; } libsysactivity-0.6.5/test/stress_swap.c0000644000175000017500000000470212220245547017302 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include int main() { int i; int ret; #ifdef SA_OPEN_SWAP ret = sa_open_swap(); if (ret != 0) { printf("%s:%d ERROR: sa_open_swap(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif uint16_t number; ret = sa_count_swaps(&number); if (ret != 0) { printf("%s:%d ERROR: sa_count_swaps(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } size_t swaps_size = number * 2; struct sa_swap* swaps = (struct sa_swap*) malloc(swaps_size * sizeof(struct sa_swap)); struct sa_swap swap; uint16_t written; for (i = 0; i < 1100000; ++i) { ret = sa_count_swaps(&number); if (ret != 0) { printf("%s:%d ERROR: sa_count_swaps(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } ret = sa_reset_swaps(); if (ret != 0) { printf("%s:%d ERROR: sa_reset_swaps(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } ret = sa_get_swap(0, &swap); if (ret != 0) { printf("%s:%d ERROR: sa_get_swap(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } ret = sa_get_swaps(swaps, swaps_size, &written); if (ret != 0) { printf("%s:%d ERROR: sa_get_swaps(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } } free(swaps); #ifdef SA_CLOSE_SWAP ret = sa_close_swap(); if (ret != 0) { printf("%s:%d ERROR: sa_close_swap(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif return EXIT_SUCCESS; } libsysactivity-0.6.5/test/stress_process.c0000644000175000017500000000512412220245547020005 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2010-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include int main() { int ret; #ifdef SA_OPEN_PROCESS ret = sa_open_process(); if (ret != 0) { printf("%s:%d ERROR: sa_open_process(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif uint32_t number; ret = sa_count_processes(&number); if (ret != 0) { printf("%s:%d ERROR: sa_count_processes(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } size_t pids_size = number * 2; pid_t* pids = malloc(pids_size * sizeof(pid_t)); int i; struct sa_process proc; struct sa_process_activity proc_activity; uint32_t written; for (i = 0; i < 22000; ++i) { ret = sa_count_processes(&number); if (ret != 0) { printf("%s:%d ERROR: sa_count_processes(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } ret = sa_get_processes_ids(pids, pids_size, &written); if (ret != 0) { printf("%s:%d ERROR: sa_get_processes_ids(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } ret = sa_get_process_activity(pids[2], &proc_activity); if (ret != 0) { printf("%s:%d ERROR: sa_get_process_activity(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } ret = sa_get_process(pids[3], &proc); if (ret != 0) { printf("%s:%d ERROR: sa_get_process(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } } free(pids); #ifdef SA_CLOSE_PROCESS ret = sa_close_process(); if (ret != 0) { printf("%s:%d ERROR: sa_close_process(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif return EXIT_SUCCESS; } libsysactivity-0.6.5/test/stress_network.c0000644000175000017500000000474512220245547020030 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include int main() { int ret, i; #ifdef SA_OPEN_NET ret = sa_open_net(); if (ret != 0) { printf("sa_open_network(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } #endif uint16_t number, written; ret = sa_count_net_interfaces(&number); if (ret != 0) { printf("sa_count_net_interfaces(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } size_t interfaces_size = number * 2; struct sa_net_interface* interfaces = (struct sa_net_interface*) malloc(interfaces_size * sizeof(struct sa_net_interface)); char* interface_names = (char*) malloc(interfaces_size * SA_NET_INTERFACE_NAME); for (i = 0; i < 65000; i++) { ret = sa_count_net_interfaces(&number); if (ret != 0) { printf("sa_count_net_interfaces(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } ret = sa_reset_net_interfaces(); if (ret != 0) { printf("sa_reset_net_interfaces(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } ret = sa_get_net_interfaces_ids(interface_names, interfaces_size, &written); if (ret != 0) { printf("sa_get_net_interfaces_ids(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } ret = sa_get_net_interfaces(interfaces, interfaces_size, &written); if (ret != 0) { printf("sa_get_network_interfaces(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } } free(interfaces); free(interface_names); #ifdef SA_CLOSE_NET ret = sa_close_net(); if (ret != 0) { printf("sa_close_network(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } #endif return EXIT_SUCCESS; } libsysactivity-0.6.5/test/stress_memory.c0000644000175000017500000000306112220245547017635 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include int main() { int i; int ret; struct sa_memory memory; #ifdef SA_OPEN_MEMORY ret = sa_open_memory(); if (ret != 0) { printf("sa_open_memory(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } #endif for (i = 0; i < 500000; i++) { ret = sa_get_memory(&memory); if (ret != 0) { printf("sa_get_memory(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } } #ifdef SA_CLOSE_MEMORY ret = sa_close_memory(); if (ret != 0) { printf("sa_close_memory(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } #endif return EXIT_SUCCESS; } libsysactivity-0.6.5/test/stress_disk.c0000644000175000017500000000534612220245547017267 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include int main() { int ret; #ifdef SA_OPEN_DISK ret = sa_open_disk(); if (ret != 0) { printf("%s:%d ERROR: sa_open_disk(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif uint16_t number; ret = sa_count_disks(&number); if (ret != 0) { printf("%s:%d ERROR: sa_count_disks(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } struct sa_disk* hds = (struct sa_disk*) malloc(number * sizeof(struct sa_disk)); if (hds == NULL) exit(EXIT_FAILURE); struct sa_disk dev; uint16_t written, i; for (i = 0; i < 9000; i++) { ret = sa_count_disks(&number); if (ret != 0) { printf("%s:%d ERROR: sa_count_disks(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } ret = sa_reset_disks(); if (ret != 0) { printf("%s:%d ERROR: sa_reset_disks(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #if defined(__linux__) // gcc -E -dM -x c /dev/null ret = sa_get_disk("sda", &dev); #elif defined(__OpenBSD__) || defined(__NetBSD__) ret = sa_get_disk("wd0", &dev); #elif defined(__sun__) ret = sa_get_disk("cmdk0", &dev); #elif defined(__DragonFly__) ret = sa_get_disk("ad1", &dev); #else ret = sa_get_disk("ad0", &dev); #endif if (ret != 0) { printf("%s:%d ERROR: sa_get_disk(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } ret = sa_get_disks(hds, number, &written); if (ret != 0) { printf("%s:%d ERROR: sa_get_disks(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } } free(hds); #ifdef SA_CLOSE_DISK ret = sa_close_disk(); if (ret != 0) { printf("%s:%d ERROR: sa_close_disk(): %s\n", __FILE__, __LINE__, strerror(ret)); exit(EXIT_FAILURE); } #endif return EXIT_SUCCESS; } libsysactivity-0.6.5/test/stress_cpu.c0000644000175000017500000000423112220245547017114 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include int main() { int i; uint16_t number_cpus; uint16_t written; int ret; #ifdef SA_OPEN_CPU ret = sa_open_cpu(); if (ret != 0) { printf("sa_open_cpu(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } #endif ret = sa_count_cpus(&number_cpus); if (ret != 0 || number_cpus == 0) { printf("sa_count_cpus(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } struct sa_cpu* cpus = malloc(number_cpus * sizeof(struct sa_cpu)); for (i = 0; i < 30000; ++i) { ret = sa_count_cpus(&number_cpus); if (ret != 0 || number_cpus == 0) { printf("sa_count_cpus(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } ret = sa_reset_cpus(); if (ret != 0) { printf("sa_reset_cpus(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } ret = sa_get_cpu(0, cpus); if (ret != 0) { printf("sa_get_cpu(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } written = 0; ret = sa_get_cpus(cpus, number_cpus, &written); if (ret != 0) { printf("sa_get_cpus(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } } free(cpus); #ifdef SA_CLOSE_CPU ret = sa_close_cpu(); if (ret != 0) { printf("sa_close_cpu(): %s\n", strerror(ret)); exit(EXIT_FAILURE); } #endif return EXIT_SUCCESS; } libsysactivity-0.6.5/test/CMakeLists.txt0000644000175000017500000000071212220245547017316 0ustar hazelhazel if (${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD") include_directories(../src/FreeBSD/) else () include_directories(../src/${CMAKE_SYSTEM_NAME}/) endif () include_directories(../src/common/) foreach(TEST_NAME cpu disk memory network process swap) add_executable(${TEST_NAME} test_${TEST_NAME}.c) add_dependencies(${TEST_NAME} sysactivity) target_link_libraries(${TEST_NAME} sysactivity pthread m) add_test(${TEST_NAME} ${TEST_NAME}) endforeach(TEST_NAME) libsysactivity-0.6.5/src/0000755000175000017500000000000012220245547014366 5ustar hazelhazellibsysactivity-0.6.5/src/common/0000755000175000017500000000000012220245547015656 5ustar hazelhazellibsysactivity-0.6.5/src/common/swap.h0000644000175000017500000000755112220245547017011 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * \defgroup swap Swap devices interface * @{ */ #ifndef SA_SWAP_H_ #define SA_SWAP_H_ /** \struct sa_swap swap.h * This structure gathers the details about a swap device. Each value is measured in bytes. */ struct sa_swap { #ifdef SA_SWAP_NAME char name[SA_SWAP_NAME]; //!< The name of the swap device. #endif #ifdef SA_SWAP_TOTAL uint64_t total; //!< Total amount of swap in this device. #endif #ifdef SA_SWAP_FREE uint64_t free; //!< Available amount of swap in this device. #endif #ifdef SA_SWAP_TYPE int8_t type; //!< The type of swap media. If it's in a device the value is 1. If it's based in a file the value is 2. #endif }; #ifdef SA_OPEN_SWAP /** * Prepares the resources needed for retrieving swap statistics. This function exists (and is needed) only when SA_OPEN_SWAP is defined. * @return If successful 0 is returned, otherwise an error code is returned. If the operating system is not supported the return value will be ENOTSUP. * @see sa_close_swap() */ int sa_open_swap(void) SA_EXPORT; #endif #ifdef SA_CLOSE_SWAP /** * This function closes the resources used for retrieving swap statistics. You should call it even when there was a previous error in another function of this API. This function exists (and is needed) only when SA_CLOSE_SWAP is defined. * @return If successful 0 is returned, otherwise an error code is returned. * @see sa_open_swap() */ int sa_close_swap(void) SA_EXPORT; #endif /** * Gives the total number of swap file systems. * You don't need to call sa_reset_swaps() before this function. * @param number The number will be stored here * @return If successful 0 is returned, otherwise an error code is returned. */ int sa_count_swaps(uint16_t* number) SA_EXPORT SA_NONNULL; /** * Refreshes the underlying operating system cache. * @return If successful 0 is returned, otherwise an error code is returned. */ int sa_reset_swaps() SA_EXPORT; /** * Retrieves statistics from a given swap index. * sa_reset_swaps() should be called at least once before this function and everytime you need fresh values. * @param index The swap index. It starts from 0. * @param dst Where the statistics will be stored. * @return If successful 0 is returned, otherwise an error code is returned. ENODEV is returned when the requested swap index was out of range. */ int sa_get_swap(uint16_t index, struct sa_swap* dst) SA_EXPORT SA_NONNULL; /** * Retrieves statistics from as many swap fs as possible. * sa_reset_swaps() should be called at least once before this function and everytime you need fresh values. * @param dst A buffer where the statistics will be stored. * @param dst_size The number of swap fs that fits in the dst buffer. If it's not big enough dst will be filled but ENOMEM will be returned. * @param written The amount of swap fs statistics written. * @return If successful 0 is returned, otherwise an error code is returned. */ int sa_get_swaps(struct sa_swap* dst, uint16_t dst_size, uint16_t* written) SA_EXPORT SA_NONNULL; /*@}*/ #endif /* SA_SWAP_H_ */ libsysactivity-0.6.5/src/common/process.h0000644000175000017500000001317112220245547017510 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * \defgroup process Process interface * @{ */ #ifndef SA_PROCESS_H_ #define SA_PROCESS_H_ #include /** \enum sa_process_state * The different types of states of a process. */ enum sa_process_state { SA_UNKNOWN = 0, //!< The state is unknown. SA_RUNNING = 1, //!< The process is running. SA_SLEEPING = 2, //!< The process is sleeping. SA_SLEEPING_UNINTERRUPTIBLE = 3, //!< The process is an uninterruptible sleep SA_ZOMBIE = 4, //!< It has completed execution but still has an entry in the process table. SA_STOPPED = 5, //!< The process is traced or stopped. }; /** \struct sa_process_activity process.h * This structure holds the information of the activity of a process. */ struct sa_process_activity { #ifdef SA_PROCESS_PID pid_t pid; //!< The id of the process #endif #ifdef SA_PROCESS_STATE enum sa_process_state state; //!< The current state of the process. #endif #ifdef SA_PROCESS_USER_TIME // TODO Explain these better uint64_t user_time; //!< User mode jiffies #endif #ifdef SA_PROCESS_SYS_TIME uint64_t sys_time; //!< Kernel mode jiffies #endif #ifdef SA_PROCESS_THREADS uint32_t threads; //!< Number of threads #endif #ifdef SA_PROCESS_VM_SIZE uint32_t vm_size; //!< Virtual memory size #endif #ifdef SA_PROCESS_RSS uint32_t rss; //!< Resident Set memory Size #endif }; /** \struct sa_process process.h * This structure holds the static information about a process. */ struct sa_process { #ifdef SA_PROCESS_PID pid_t pid; //!< The id of the process #endif #ifdef SA_PROCESS_UID uid_t uid; //!< The id of the user running this process #endif #ifdef SA_PROCESS_GID gid_t gid; //!< Id of the user's group running this process #endif #ifdef SA_PROCESS_FILENAME char filename[SA_PROCESS_FILENAME]; //!< The name of the running file. #endif #ifdef SA_PROCESS_CMDLINE char cmdline[SA_PROCESS_CMDLINE]; //!< The command executed to launch this process. #endif #ifdef SA_PROCESS_PARENT_PID pid_t parent_pid; //!< The id of its parent #endif #ifdef SA_PROCESS_PGRP pid_t pgrp; //!< The group id the process #endif #ifdef SA_PROCESS_SID pid_t sid; //!< Session id of this process #endif #ifdef SA_PROCESS_TTY pid_t tty; //!< The id of the tty this process is running on. #endif #ifdef SA_PROCESS_NICE int8_t nice; //!< Priority of this process. #endif #ifdef SA_PROCESS_START_TIME uint64_t start_time; //!< Process start time in hundredths of second since system boot #endif struct sa_process_activity activity; }; #ifdef SA_OPEN_PROCESS /** * Prepares the resources needed for retrieving process statistics. This function exists (and is needed) only when SA_OPEN_PROCESS is defined. * @return If successful 0 is returned, otherwise an error code is returned. If the operating system is not supported the return value will be ENOTSUP. * @see sa_close_process() */ int sa_open_process() SA_EXPORT; #endif #ifdef SA_CLOSE_PROCESS /** * This function closes the resources used for retrieving process statistics. You should call it even when there was a previous error in another function of this API. This function exists (and is needed) only when SA_CLOSE_PROCESS is defined. * @return If successful 0 is returned, otherwise an error code is returned. * @see sa_open_process() */ int sa_close_process() SA_EXPORT; #endif /** * Gives the total number of processes on the systems. * @param number The number will be stored here * @return If successful 0 is returned, otherwise an error code is returned. */ int sa_count_processes(uint32_t* number) SA_EXPORT SA_NONNULL; /** * Gets a list of the existing processes ids. The array will be fully populated even if it's not big enough (but ENOMEM is returned). * @param dst A pointer to the array to populate. * @param dst_size The number of pid_t that fits in the array. * @param written The number of pids written is stored here. * @return If successful 0 is returned, otherwise an error code is returned. * @since 0.4.1 */ int sa_get_processes_ids(pid_t* dst, uint32_t dst_size, uint32_t* written) SA_EXPORT SA_NONNULL; /** * Retrieves statistics from a process identified by its pid. * @param pid The pid of the process. * @param dst Where the statistics will be stored. * @return If successful 0 is returned, otherwise an error code is returned. ESRCH is returned if the requested process was not found. */ int sa_get_process(pid_t pid, struct sa_process* dst) SA_EXPORT SA_NONNULL; /** * Retrieves the activity of a process on the dst parameter. * @param pid The pid of the process. * @param dst Where the statistics will be stored. * @return If successful 0 is returned, otherwise an error code is returned. ESRCH is returned if the requested process was not found. * @since 0.6.0 */ int sa_get_process_activity(pid_t pid, struct sa_process_activity* dst) SA_EXPORT SA_NONNULL; /*@}*/ #endif /* SA_PROCESS_H_ */ libsysactivity-0.6.5/src/common/network.h0000644000175000017500000001421512220245547017523 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * \defgroup network Network interface * @{ */ #ifndef SA_NET_H_ #define SA_NET_H_ /** \struct sa_net_interface network.h * This structure gathers the details about the activity of one network interface. */ struct sa_net_interface { #ifdef SA_NET_INTERFACE_NAME char name[SA_NET_INTERFACE_NAME]; //!< Interface's name. It's used as the unique identifier of the interface. #endif #ifdef SA_NET_INTERFACE_RECEIVED_BYTES uint64_t received_bytes; //!< Total number of received bytes. #endif #ifdef SA_NET_INTERFACE_RECEIVED_PACKETS uint64_t received_packets; //!< Total number of received packets. #endif #ifdef SA_NET_INTERFACE_RECEIVED_ERRORS uint64_t received_errors; //!< Amount of received errors. #endif #ifdef SA_NET_INTERFACE_RECEIVED_DROP uint64_t received_drop; //!< Total number of received packets that had been dropped. #endif #ifdef SA_NET_INTERFACE_RECEIVED_FIFO uint64_t received_fifo; //!< The number of fifo buffer errors received. #endif #ifdef SA_NET_INTERFACE_RECEIVED_COMPRESSED uint64_t received_compressed; //!< The number of compressed packets received by the device driver. #endif #ifdef SA_NET_INTERFACE_RECEIVED_MULTICAST uint64_t received_multicast; //!< Number of packets received which were sent by link-layer multicast. #endif #ifdef SA_NET_INTERFACE_SENT_BYTES uint64_t sent_bytes; //!< Total number of transmitted bytes. #endif #ifdef SA_NET_INTERFACE_SENT_PACKETS uint64_t sent_packets; //!< Total number of sent packets. #endif #ifdef SA_NET_INTERFACE_SENT_ERRORS uint64_t sent_errors; //!< Amount of sent errors. #endif #ifdef SA_NET_INTERFACE_SENT_DROP uint64_t sent_drop; //!< Total number of sent packets that had been dropped. #endif #ifdef SA_NET_INTERFACE_SENT_FIFO uint64_t sent_fifo; //!< The number of fifo buffer errors sent. #endif #ifdef SA_NET_INTERFACE_SENT_COMPRESSED uint64_t sent_compressed; //!< The number of compressed packets transmitted by the device driver. #endif #ifdef SA_NET_INTERFACE_SENT_MULTICAST uint64_t sent_multicast; //!< Number of packets sent by link-layer multicast. #endif }; #ifdef SA_OPEN_NET /** * Prepares the resources needed for retrieving network statistics. This function exists (and is needed) only when SA_OPEN_NET is defined. * @return If successful 0 is returned, otherwise an error code is returned. If the operating system is not supported the return value will be ENOTSUP. * @see sa_close_net() * @since 0.6.0 */ int sa_open_net(void) SA_EXPORT; #endif #ifdef SA_CLOSE_NET /** * This function closes the resources used for retrieving network statistics. You should call it even when there was a previous error in another function of this API. This function exists (and is needed) only when SA_CLOSE_NET is defined. * @return If successful 0 is returned, otherwise an error code is returned. * @see sa_open_net() * @since 0.6.0 */ int sa_close_net(void) SA_EXPORT; #endif /** * Gives the total number of network interfaces. * You don't need to call sa_reset_net_interfaces() before this function. * @param number The number will be stored here * @return If successful 0 is returned, otherwise an error code is returned. * @since 0.6.0 */ int sa_count_net_interfaces(uint16_t* number) SA_EXPORT SA_NONNULL; /** * Refreshes the underlying operating system cache. * @return If successful 0 is returned, otherwise an error code is returned. * @since 0.6.0 */ int sa_reset_net_interfaces() SA_EXPORT; /** * Returns a list of the existing the network interfaces ids. The array will be fully populated even if it's not big enough (but ENOMEM is returned). * sa_reset_net_interfaces() should be called at least once before this function and everytime you need fresh values. * @param dst Where the statistics will be stored. * @param dst_size The number of ids that fits on the dst pointer. * @param written The number of network interfaces ids written. * @return If successful 0 is returned, otherwise an error code is returned. ENODEV is returned when there are no more disks available. * @since 0.6.0 */ int sa_get_net_interfaces_ids(char* dst, uint16_t dst_size, uint16_t* written) SA_EXPORT SA_NONNULL; /** * Retrieves statistics from a network interface identified by its name. * sa_reset_net_interfaces() should be called at least once before this function and everytime you need fresh values. * @param name The name of the network interface. * @param dst Where the statistics will be stored. * @return If successful 0 is returned, otherwise an error code is returned. ENODEV is returned when the requested device was not found. * @since 0.6.0 */ int sa_get_net_interface(char* name, struct sa_net_interface* dst) SA_EXPORT SA_NONNULL; /** * Retrieves statistics about all the network interfaces' activity. * sa_reset_net_interfaces() should be called at least once before this function and everytime you need fresh values. * @param dst A buffer where the statistics will be stored. * @param dst_size The number of interfaces that fits in the dst buffer. If it's not big enough dst will be filled but ENOMEM will be returned. * @param written The amount of interface statistics written. * @return If successful 0 is returned, otherwise an error code is returned. * @since 0.6.0 */ int sa_get_net_interfaces(struct sa_net_interface* dst, uint16_t dst_size, uint16_t* written) SA_EXPORT SA_NONNULL; /*@}*/ #endif /* SA_NET_H_ */ libsysactivity-0.6.5/src/common/memory.h0000644000175000017500000000676612220245547017356 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * \defgroup memory Memory interface * @{ */ #ifndef SA_MEMORY_H_ #define SA_MEMORY_H_ /** \struct sa_memory memory.h * This structure gathers the details about the memory usage. Each value is measured in bytes. */ struct sa_memory { #ifdef SA_MEMORY_TOTAL uint64_t total; //!< Total amount of RAM available in the system. #endif #ifdef SA_MEMORY_FREE uint64_t free; //!< Unused amount of memory. #endif #ifdef SA_MEMORY_ACTIVE uint64_t active; //!< Amount of memory in use or recently used. #endif #ifdef SA_MEMORY_INACTIVE uint64_t inactive; //!< Amount of memory that has not been recently used. #endif #ifdef SA_MEMORY_BUFFERS uint64_t buffers; //!< Memory used for cached files. Useless for metrics nowadays. #endif #ifdef SA_MEMORY_SWAP_TOTAL uint64_t swap_total; //!< Total amount of swap present in the system. #endif #ifdef SA_MEMORY_SWAP_FREE uint64_t swap_free; //!< Free amount of swap available. #endif #ifdef SA_MEMORY_SWAP_CACHED uint64_t swap_cached; //!< Amount of swap that is cached. #endif #ifdef SA_MEMORY_WIRED uint64_t wired; //!< Memory not placed on any queue. #endif #ifdef SA_MEMORY_CACHED uint64_t cached; //!< Amount of cached memory. #endif #ifdef SA_MEMORY_DIRTY uint64_t dirty; //!< Amount of memory waiting for been written to the disk. #endif #ifdef SA_MEMORY_EXECUTABLE uint64_t executable; //!< Memory used to hold executable data #endif #ifdef SA_MEMORY_FILES uint64_t files; //!< Memory used by cached file data #endif #ifdef SA_MEMORY_LOCKED uint64_t locked; //!< Memory that can not be moved to swap #endif }; #ifdef SA_OPEN_MEMORY /** * Prepares the resources needed for retrieving memory statistics. This function exists (and is needed) only when SA_OPEN_MEMORY is defined. * @return If successful 0 is returned, otherwise an error code is returned. If the operating system is not supported the return value will be ENOTSUP. * @see sa_close_memory() */ int sa_open_memory(void) SA_EXPORT; #endif #ifdef SA_CLOSE_MEMORY /** * This function closes the resources used for retrieving memory statistics. You should call it even when there was a previous error in another function of this API. This function exists (and is needed) only when SA_CLOSE_MEMORY is defined. * @return If successful 0 is returned, otherwise an error code is returned. * @see sa_open_memory() */ int sa_close_memory(void) SA_EXPORT; #endif /** * Retrieves statistics about the usage of the memory. * @param dst Where the statistics will be stored. * @return If successful 0 is returned, otherwise an error code is returned. */ int sa_get_memory(struct sa_memory* dst) SA_EXPORT SA_NONNULL; /*@}*/ #endif /* SA_MEMORY_H_ */ libsysactivity-0.6.5/src/common/global.h0000644000175000017500000000347712220245547017302 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef SA_GLOBAL_H_ #define SA_GLOBAL_H_ #ifndef LIBSYSACTIVITY_H_ #warning You should not include this file directly from your source code. Include instead. #endif #define SA_VERSION_MAJOR 0 #define SA_VERSION_SMALL 6 #define SA_VERSION_MINOR 5 #if __GNUC__ >= 4 #define SA_EXPORT __attribute__ ((visibility("default"))) #else #define SA_EXPORT #endif #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) #define SA_HOT __attribute__ ((hot)) #else #define SA_HOT #endif #define SA_NONNULL __attribute__((nonnull)) #if __STDC_VERSION__ < 199901L #define SA_INLINE inline #else #define SA_INLINE //In C99, inline means that a function's definition is provided only for inlining, and that there is another definition (without inline) somewhere else in the program #endif #include "cpu.h" #include "disk.h" #include "memory.h" #include "network.h" #include "process.h" #include "swap.h" #endif /* SA_CPU_H_ */ libsysactivity-0.6.5/src/common/disk.h0000644000175000017500000001226012220245547016762 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * \defgroup disk Disk statistics interface * @{ */ #ifndef SA_DISK_H_ #define SA_DISK_H_ /** \struct sa_disk disk.h * This structure gathers the details about the activity of one disk. */ struct sa_disk { #ifdef SA_DISK_NAME char name[SA_DISK_NAME]; //!< Device's name. It's used as the unique identifier of the device. #endif #ifdef SA_DISK_READS uint64_t reads; //!< Number of reads. #endif #ifdef SA_DISK_READS_MERGED uint64_t reads_merged; //!< Number of reads which are adjacent to each other and have been merged for efficiency #endif #ifdef SA_DISK_SECTORS_READ uint64_t sectors_read; //!< Total number of sectors read #endif #ifdef SA_DISK_TIME_SPENT_READING uint64_t time_spent_reading; //!< Number of seconds spent performing read operations #endif #ifdef SA_DISK_WRITES uint64_t writes; //!< Number of writes. #endif #ifdef SA_DISK_SECTORS_WRITTEN uint64_t sectors_written; //!< Total number of sectors written #endif #ifdef SA_DISK_TIME_SPENT_WRITING uint64_t time_spent_writing; //!< Number of seconds spent performing write operations #endif #ifdef SA_DISK_BYTES_READ uint64_t bytes_read; //!< Total number of bytes read #endif #ifdef SA_DISK_BYTES_WRITTEN uint64_t bytes_written; //!< Total number of bytes written #endif }; #ifdef SA_OPEN_DISK /** * Prepares the resources needed for retrieving disk statistics. This function exists (and is needed) only when SA_OPEN_DISK is defined. * @return If successful 0 is returned, otherwise an error code is returned. If the operating system is not supported the return value will be ENOTSUP. * @see sa_close_disk() * @since 0.6.0 */ int sa_open_disk(void) SA_EXPORT; #endif #ifdef SA_CLOSE_DISK /** * This function closes the resources used for retrieving disk statistics. You should call it even when there was a previous error in another function of this API. This function exists (and is needed) only when SA_CLOSE_DISK is defined. * @return If successful 0 is returned, otherwise an error code is returned. * @see sa_open_disk() * @since 0.6.0 */ int sa_close_disk(void) SA_EXPORT; #endif /** * Gives the total number of disks. * You don't need to call sa_reset_disks() before this function. * @param number The number will be stored here * @return If successful 0 is returned, otherwise an error code is returned. * @since 0.6.0 */ int sa_count_disks(uint16_t* number) SA_EXPORT SA_NONNULL; /** * Refreshes the underlying operating system cache. * @return If successful 0 is returned, otherwise an error code is returned. * @since 0.6.0 */ int sa_reset_disks() SA_EXPORT; /** * Returns a list of the existing disks ids. The array will be fully populated even if it's not big enough (but ENOMEM is returned). * sa_reset_disks() should be called at least once before this function and everytime you need fresh values. * @param dst Where the statistics will be stored. * @param dst_size The number of ids that fits on the dst pointer. * @param written The number of disks ids written. * @return If successful 0 is returned, otherwise an error code is returned. ENODEV is returned when there are no more disks available. * @since 0.6.0 */ int sa_get_disks_ids(char* dst, uint16_t dst_size, uint16_t* written) SA_EXPORT SA_NONNULL; /** * Retrieves statistics from a disk identified by its device name. * sa_reset_disks() should be called at least once before this function and everytime you need fresh values. * @param name The name of the disk. * @param dst Where the statistics will be stored. * @return If successful 0 is returned, otherwise an error code is returned. ENODEV is returned when the requested device was not found. * @since 0.6.0 */ int sa_get_disk(char* name, struct sa_disk* dst) SA_EXPORT SA_NONNULL; /** * Retrieves statistics about all the disks' activity. * sa_reset_disks() should be called at least once before this function and everytime you need fresh values. * @param dst A buffer where the statistics will be stored. * @param dst_size The number of devices that fits in the dst buffer. If it's not big enough dst will be filled but ENOMEM will be returned. * @param written The amount of device statistics written. * @return If successful 0 is returned, otherwise an error code is returned. * @since 0.6.0 */ int sa_get_disks(struct sa_disk* dst, uint16_t dst_size, uint16_t* written) SA_EXPORT SA_NONNULL; /*@}*/ #endif /* SA_DISK_H_ */ libsysactivity-0.6.5/src/common/cpu.h0000644000175000017500000001153112220245547016617 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /** * \defgroup cpu CPU interface * @{ */ #ifndef SA_CPU_H_ #define SA_CPU_H_ /** \struct sa_cpu cpu.h * This structure gathers the details about one cpu's activity. */ struct sa_cpu { #ifdef SA_CPU_ID uint16_t id; //!< Cpu identificator. 0 is the first one. #endif #ifdef SA_CPU_USER float user; //!< Percentage of time spent on user tasks #endif #ifdef SA_CPU_NICE float nice; //!< Percentage of time spent on nice prioriced tasks #endif #ifdef SA_CPU_SYSTEM float system; //!< Percentage of time spent on system tasks #endif #ifdef SA_CPU_IDLE float idle; //!< Percentage of time with no activity #endif #ifdef SA_CPU_WAITING_FOR_IO float waiting_for_io; //!< Percentage of time spent waiting for io transferences #endif #ifdef SA_CPU_HARDWARE_IRQ float hardware_irq; //!< Percentage of time spent working on hardware irqs #endif #ifdef SA_CPU_SOFTWARE_IRQ float software_irq; //!< Percentage of time spent working on software irqs #endif #ifdef SA_CPU_STOLEN float stolen; //!< Percentage of time spent in other operating systems when running in a virtualized environment #endif #ifdef SA_CPU_INTR float intr; #endif }; #ifdef SA_OPEN_CPU /** * Prepares the resources needed for retrieving cpu statistics. This function exists (and is needed) only when SA_OPEN_CPU is defined. * @return If successful 0 is returned, otherwise an error code is returned. If the operating system is not supported the return value will be ENOTSUP. * @see sa_close_cpu() */ int sa_open_cpu(void) SA_EXPORT; #endif #ifdef SA_CLOSE_CPU /** * This function closes the resources used for retrieving cpu statistics. You should call it even when there was a previous error in another function of this API. This function exists (and is needed) only when SA_CLOSE_CPU is defined. * @return If successful 0 is returned, otherwise an error code is returned. * @see sa_open_cpu() */ int sa_close_cpu(void) SA_EXPORT; #endif /** * Refreshes the underlying operating system cache. * @return If successful 0 is returned, otherwise an error code is returned. * @since 0.6.0 */ int sa_reset_cpus() SA_EXPORT; /** * Gives the number of processors that you can take statistics from. * You don't need to call sa_reset_cpus() before this function. * @param number If the underlying platform does not support per-process stats this number will be 1 (even when there are many real CPUs). See the \ref matrix_cpu_sec "cpu matrix" for further information. * @return If successful 0 is returned, otherwise an error code is returned. */ int sa_count_cpus(uint16_t* number) SA_EXPORT SA_NONNULL; /** * \brief Retrieves statistics from a given cpu index. * This data is an average calculated since last time it was retrieved. If it was never calculated before it makes an average of the entire life of the cpu. * sa_reset_cpus() should be called at least once before this function and everytime you need fresh values. * @param index The cpu index. The first index value is 0. * @param dst Where the statistics will be stored. * @return If successful 0 is returned, otherwise an error code is returned. ENODEV is returned when the requested cpu index was out of range. */ int sa_get_cpu(uint16_t index, struct sa_cpu* dst) SA_EXPORT SA_NONNULL; /** * \brief Retrieves statistics from as many processors as possible. * The data of each cpu is an average calculated since last time it was retrieved. If it was never calculated before it makes an average of the entire life of the cpu. * sa_reset_cpus() should be called at least once before this function and everytime you need fresh values. * @param dst A buffer where the statistics will be stored. * @param dst_size The number of cpus that fits in the dst buffer. If it's not big enough dst will be filled but ENOMEM will be returned. * @param written The amount of cpu statistics written. * @return If successful 0 is returned, otherwise an error code is returned. */ int sa_get_cpus(struct sa_cpu* dst, uint16_t dst_size, uint16_t* written) SA_EXPORT SA_NONNULL; /*@}*/ #endif /* SA_CPU_H_ */ libsysactivity-0.6.5/src/common/CMakeLists.txt0000644000175000017500000000015712220245547020421 0ustar hazelhazel FILE(GLOB LIBSA_COMMON_HDRS *.h) INSTALL(FILES ${LIBSA_COMMON_HDRS} DESTINATION ${HEADERS_INSTALLATION_DIR}) libsysactivity-0.6.5/src/SunOS/0000755000175000017500000000000012220245547015375 5ustar hazelhazellibsysactivity-0.6.5/src/SunOS/utils.h0000644000175000017500000000204512220245547016707 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include int get_ks(kstat_ctl_t* kc, kstat_t** ks, char* module, char* name) SA_HOT SA_NONNULL; int safe_realloc(void** ptr, size_t* size) SA_NONNULL; libsysactivity-0.6.5/src/SunOS/utils.c0000644000175000017500000000252112220245547016701 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include "utils.h" int get_ks(kstat_ctl_t* kc, kstat_t** ks, char* module, char* name) { *ks = kstat_lookup(kc, module, 0, name); if (*ks == NULL) return ENOSYS; if (kstat_read(kc, *ks, 0) == -1) return ENOSYS; return 0; } int safe_realloc(void** ptr, size_t* size) { void* tmp = realloc(*ptr, *size); if (tmp == NULL) { free(*ptr); *ptr = NULL; *size = 0; return ENOMEM; } *ptr = tmp; return 0; } libsysactivity-0.6.5/src/SunOS/swap.c0000644000175000017500000000655412220245547016525 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include "utils.h" static int populate_swaptable(uint16_t nswt_ent); __thread int s_pagesize = 0; __thread swaptbl_t* swaptable; __thread size_t swaptable_size; __thread uint16_t number_swaps; int sa_open_swap() { swaptable = NULL; swaptable_size = 0; s_pagesize = sysconf(_SC_PAGESIZE); return 0; } int sa_close_swap() { if (swaptable != NULL) { int i; for (i = 0; i < swaptable_size / sizeof(struct swapent); ++i) free(swaptable->swt_ent[i].ste_path); free(swaptable); } return 0; } int sa_count_swaps(uint16_t* number) { if (number == NULL) return EINVAL; int ret = swapctl(SC_GETNSWP, NULL); if (ret == -1) return errno; *number = (uint16_t) ret; return 0; } int sa_reset_swaps() { int nswaps = swapctl(SC_GETNSWP, NULL); if (nswaps == -1) return errno; int ret = populate_swaptable(nswaps); if (ret != 0) return ret; number_swaps = nswaps; return 0; } int sa_get_swap(uint16_t index, struct sa_swap* dst) { if (dst == NULL) return EINVAL; if (index >= number_swaps) return ENODEV; strncpy(dst->name, swaptable->swt_ent[index].ste_path, sizeof(dst->name)); dst->total = (uint64_t) swaptable->swt_ent[index].ste_pages * s_pagesize; dst->free = (uint64_t) swaptable->swt_ent[index].ste_free * s_pagesize; return 0; } int sa_get_swaps(struct sa_swap* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 0; uint16_t i; for (i = 0; i < number_swaps; ++i) { if (i == dst_size) return ENOMEM; strncpy(dst[i].name, swaptable->swt_ent[i].ste_path, sizeof(dst->name)); dst[i].total = (uint64_t) swaptable->swt_ent[i].ste_pages * s_pagesize; dst[i].free = (uint64_t) swaptable->swt_ent[i].ste_free * s_pagesize; ++(*written); } return 0; } static int populate_swaptable(uint16_t nswt_ent) { size_t len = sizeof(int) + (nswt_ent * sizeof(struct swapent)); if (len > swaptable_size) { safe_realloc((void*) &swaptable, &len); if (swaptable == NULL) { swaptable_size = len; return ENOMEM; } int i; for (i = swaptable_size / sizeof(struct swapent); i < nswt_ent; ++i) { swaptable->swt_ent[i].ste_path = (char*) malloc(MAXPATHLEN); if (swaptable->swt_ent[i].ste_path == NULL) return ENOMEM; } swaptable_size = len; } swaptable->swt_n = nswt_ent; if (swapctl(SC_LIST, swaptable) == -1) return errno; return 0; } libsysactivity-0.6.5/src/SunOS/process.c0000644000175000017500000001172212220245547017222 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include "utils.h" static int get_psinfo(psinfo_t* p_info, pid_t pid) SA_HOT SA_NONNULL; static int read_stats(struct sa_process* dst, pid_t pid) SA_HOT SA_NONNULL; static int read_stats_activity(struct sa_process_activity* dst, psinfo_t* p_info) SA_HOT SA_NONNULL; __thread DIR* dir_proc; __thread kstat_ctl_t* process_kc; __thread uint32_t boot_time = 0; // seconds from epoch __thread char usage_path[32]; int sa_open_process() { process_kc = NULL; dir_proc = opendir("/proc/"); if (dir_proc == NULL) return EIO; process_kc = kstat_open(); if (process_kc == NULL) return ENOSYS; kstat_t* ks; if (get_ks(process_kc, &ks, "unix", "system_misc") != 0) return ENOSYS; kstat_named_t* kn = kstat_data_lookup(ks, "boot_time"); if (kn == NULL) return ENOSYS; boot_time = kn->value.ui32; strcpy(usage_path, "/proc/"); return 0; } int sa_close_process() { if (dir_proc != NULL) closedir(dir_proc); if (process_kc != NULL) kstat_close(process_kc); return 0; } int sa_count_processes(uint32_t* number) { kstat_t* ks; if (get_ks(process_kc, &ks, "unix", "system_misc") != 0) return ENOSYS; kstat_named_t* kn = kstat_data_lookup(ks, "nproc"); if (kn == NULL) return ENOSYS; *number = kn->value.ui32; return 0; } int sa_get_processes_ids(pid_t* dst, uint32_t dst_size, uint32_t* written) { if (dst == NULL || dst_size <= 0 || written == NULL) return EINVAL; rewinddir(dir_proc); *written = 0; struct dirent* entry; pid_t pid; while ((entry = readdir(dir_proc)) != NULL) { pid = atoi(entry->d_name); if (pid == 0) continue; if (*written == dst_size) return ENOMEM; dst[*written] = pid; ++(*written); } return 0; } int sa_get_process(pid_t pid, struct sa_process* dst) { if (pid == 0 || dst == NULL) return EINVAL; return read_stats(dst, pid); } int sa_get_process_activity(pid_t pid, struct sa_process_activity* dst) { if (pid == 0 || dst == NULL) return EINVAL; psinfo_t p_info; if (get_psinfo(&p_info, pid) != 0) return ESRCH; return read_stats_activity(dst, &p_info); } static int get_psinfo(psinfo_t* p_info, pid_t pid) { char line_buffer[32]; FILE* psinfo; sprintf(line_buffer, "/proc/%d/psinfo", (int) pid); psinfo = fopen(line_buffer, "r"); if (psinfo == NULL) return ESRCH; if (fread(p_info, sizeof(psinfo_t), 1, psinfo) == 0) { fclose(psinfo); return ENOSYS; } fclose(psinfo); return 0; } static int read_stats(struct sa_process* dst, pid_t pid) { psinfo_t p_info; // psinfo_t is defined at procfs.h int ret; ret = get_psinfo(&p_info, pid); if (ret != 0) return ret; dst->pid = pid; dst->uid = p_info.pr_uid; dst->gid = p_info.pr_gid; strncpy(dst->filename, p_info.pr_fname, PRFNSZ); strncpy(dst->cmdline, p_info.pr_psargs, PRARGSZ); dst->parent_pid = p_info.pr_ppid; dst->pgrp = p_info.pr_pgid; dst->sid = p_info.pr_sid; dst->tty = p_info.pr_ttydev; dst->nice = p_info.pr_lwp.pr_nice - 20; dst->start_time = (uint64_t) (p_info.pr_start.tv_sec - boot_time) * 100; return read_stats_activity(&dst->activity, &p_info); } static int read_stats_activity(struct sa_process_activity* dst, psinfo_t* p_info) { dst->pid = p_info->pr_pid; sprintf(&usage_path[6], "%d/usage", (int) p_info->pr_pid); FILE* file_usage = fopen(usage_path, "r"); if (file_usage == NULL) return ESRCH; prusage_t prusage; if (fread(&prusage, sizeof prusage, 1, file_usage) != 1) { fclose(file_usage); return ESRCH; } fclose(file_usage); dst->threads = prusage.pr_count; dst->user_time = prusage.pr_utime.tv_sec * 1000 + prusage.pr_utime.tv_nsec / 1000000; dst->sys_time = prusage.pr_stime.tv_sec * 1000 + prusage.pr_stime.tv_nsec / 1000000; switch (p_info->pr_lwp.pr_state) { case SZOMB: dst->state = SA_ZOMBIE; break; case SSTOP: dst->state = SA_STOPPED; break; case SIDL: case SONPROC: dst->state = SA_RUNNING; break; default: dst->state = SA_SLEEPING; break; } dst->vm_size = p_info->pr_size * 1024; dst->rss = p_info->pr_rssize * 1024; return 0; } libsysactivity-0.6.5/src/SunOS/network.c0000644000175000017500000001031612220245547017233 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include static kstat_t* get_next_ksp(kstat_t* local_ksp); static int assign_dst(struct sa_net_interface* dst, kstat_t* local_ksp) SA_NONNULL; static void assign_field(kstat_t* local_ksp, uint64_t* field, char* tag64, char* tag32) SA_NONNULL SA_HOT; __thread kstat_ctl_t* network_kc; __thread kstat_t* ksp; int sa_open_net() { network_kc = kstat_open(); if (network_kc == NULL) return ENOSYS; return 0; } int sa_close_net() { if (network_kc != NULL) kstat_close(network_kc); return 0; } int sa_count_net_interfaces(uint16_t* number) { if (number == NULL) return EINVAL; kstat_t* local_ksp = NULL; *number = 0; while ((local_ksp = get_next_ksp(local_ksp)) != NULL) ++(*number); return 0; } int sa_reset_net_interfaces() { ksp = NULL; return 0; } int sa_get_net_interfaces_ids(char* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; int i; *written = 0; for (i = 0; (ksp = get_next_ksp(ksp)) != NULL; ++i) { if (i == dst_size) return ENOMEM; if (kstat_read(network_kc, ksp, NULL) == -1) return 0; strncpy(&dst[i * SA_NET_INTERFACE_NAME], ksp->ks_name, SA_NET_INTERFACE_NAME); ++(*written); } return 0; } int sa_get_net_interface(char* name, struct sa_net_interface* dst) { if (name == NULL || dst == NULL) return EINVAL; kstat_t* local_ksp = NULL; while ((local_ksp = get_next_ksp(local_ksp)) != NULL) { if (strncmp(local_ksp->ks_name, name, sizeof local_ksp->ks_name) != 0) continue; if (!assign_dst(dst, local_ksp)) return ENOSYS; return 0; } return ENODEV; } int sa_get_net_interfaces(struct sa_net_interface* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; int i; *written = 0; for (i = 0; (ksp = get_next_ksp(ksp)) != NULL; ++i) { if (i == dst_size) return ENOMEM; if (!assign_dst(&dst[i], ksp)) return ENOSYS; ++(*written); } return 0; } static kstat_t* get_next_ksp(kstat_t* local_ksp) { do { local_ksp = (local_ksp == NULL) ? network_kc->kc_chain : local_ksp->ks_next; if (local_ksp == NULL) return local_ksp; } while (strcmp(local_ksp->ks_module, "link") != 0 && strcmp(local_ksp->ks_module, "lo") != 0); return local_ksp; } static int assign_dst(struct sa_net_interface* dst, kstat_t* local_ksp) { if (kstat_read(network_kc, local_ksp, NULL) == -1) return 0; strncpy(dst->name, local_ksp->ks_name, sizeof dst->name); dst->received_bytes = 0; assign_field(local_ksp, &dst->received_bytes, "rbytes64", "rbytes"); assign_field(local_ksp, &dst->received_packets, "ipackets64", "ipackets"); kstat_named_t* knp = kstat_data_lookup(local_ksp, "ierrors"); dst->received_errors = (knp != NULL) ? knp->value.ui32 : 0; assign_field(local_ksp, &dst->sent_bytes, "obytes64", "obytes"); assign_field(local_ksp, &dst->sent_packets, "opackets64", "opackets"); knp = kstat_data_lookup(local_ksp, "oerrors"); dst->sent_errors = (knp != NULL) ? knp->value.ui32 : 0; return 1; } static void assign_field(kstat_t* local_ksp, uint64_t* field, char* tag64, char* tag32) { kstat_named_t* knp = kstat_data_lookup(local_ksp, tag64); if (knp != NULL) { *field = knp->value.ui64; return; } knp = kstat_data_lookup(local_ksp, tag32); *field = (knp != NULL) ? knp->value.ui32 : 0; } libsysactivity-0.6.5/src/SunOS/memory.c0000644000175000017500000000407212220245547017054 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include "utils.h" __thread kstat_ctl_t* memory_kc; __thread int pagesize = 0; int sa_open_memory() { memory_kc = kstat_open(); if (memory_kc == NULL) return ENOSYS; pagesize = sysconf(_SC_PAGESIZE); return 0; } int sa_close_memory() { if (memory_kc != NULL) kstat_close(memory_kc); return 0; } int sa_get_memory(struct sa_memory* dst) { if (dst == NULL) return EINVAL; kstat_t* ks; if (get_ks(memory_kc, &ks, "unix", "system_pages") != 0) return ENOSYS; kstat_named_t* kn = kstat_data_lookup(ks, "pagestotal"); if (kn == NULL) return ENOSYS; dst->total = (uint64_t) kn->value.ui64 * pagesize; kn = kstat_data_lookup(ks, "pagesfree"); if (kn == NULL) return ENOSYS; dst->free = (uint64_t) kn->value.ui64 * pagesize; kn = kstat_data_lookup(ks, "pageslocked"); if (kn == NULL) return ENOSYS; dst->locked = (uint64_t) kn->value.ui64 * pagesize; struct anoninfo swap_info; if (swapctl(SC_AINFO, &swap_info) == -1) return ENOSYS; dst->swap_total = swap_info.ani_max; dst->swap_free = swap_info.ani_free; return 0; } libsysactivity-0.6.5/src/SunOS/libsysactivity.h0000644000175000017500000000653512220245547020641 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef LIBSYSACTIVITY_H_ #define LIBSYSACTIVITY_H_ #include #include #include #ifdef __cplusplus extern "C" { #endif #define SA_OPEN_CPU #define SA_CLOSE_CPU #undef SA_SMP_CAPABLE #define SA_CPU_ID #define SA_CPU_USER #undef SA_CPU_NICE #define SA_CPU_SYSTEM #define SA_CPU_IDLE #define SA_CPU_WAITING_FOR_IO #undef SA_CPU_HARDWARE_IRQ #undef SA_CPU_SOFTWARE_IRQ #undef SA_CPU_STOLEN #undef SA_CPU_INTR #define SA_OPEN_DISK #define SA_CLOSE_DISK #define SA_DISK_NAME KSTAT_STRLEN #define SA_DISK_READS #undef SA_DISK_READS_MERGED #undef SA_DISK_SECTORS_READ #undef SA_DISK_TIME_SPENT_READING #define SA_DISK_WRITES #undef SA_DISK_SECTORS_WRITTEN #undef SA_DISK_TIME_SPENT_WRITING #define SA_DISK_BYTES_READ #define SA_DISK_BYTES_WRITTEN #define SA_OPEN_MEMORY #define SA_CLOSE_MEMORY #define SA_MEMORY_TOTAL #define SA_MEMORY_FREE #undef SA_MEMORY_ACTIVE #undef SA_MEMORY_INACTIVE #undef SA_MEMORY_BUFFERS #define SA_MEMORY_SWAP_TOTAL #define SA_MEMORY_SWAP_FREE #undef SA_MEMORY_SWAP_CACHED #undef SA_MEMORY_WIRED #undef SA_MEMORY_CACHED #undef SA_MEMORY_DIRTY #undef SA_MEMORY_EXECUTABLE #undef SA_MEMORY_FILES #define SA_MEMORY_LOCKED #define SA_OPEN_NET #define SA_CLOSE_NET #define SA_NET_INTERFACE_NAME KSTAT_STRLEN #define SA_NET_INTERFACE_RECEIVED_BYTES #define SA_NET_INTERFACE_RECEIVED_PACKETS #define SA_NET_INTERFACE_RECEIVED_ERRORS #undef SA_NET_INTERFACE_RECEIVED_DROP #undef SA_NET_INTERFACE_RECEIVED_FIFO #undef SA_NET_INTERFACE_RECEIVED_COMPRESSED #undef SA_NET_INTERFACE_RECEIVED_MULTICAST #define SA_NET_INTERFACE_SENT_BYTES #define SA_NET_INTERFACE_SENT_PACKETS #define SA_NET_INTERFACE_SENT_ERRORS #undef SA_NET_INTERFACE_SENT_DROP #undef SA_NET_INTERFACE_SENT_FIFO #undef SA_NET_INTERFACE_SENT_COMPRESSED #undef SA_NET_INTERFACE_SENT_MULTICAST #define SA_OPEN_PROCESS #define SA_CLOSE_PROCESS #define SA_PROCESS_PID #define SA_PROCESS_UID #define SA_PROCESS_GID #define SA_PROCESS_FILENAME PRFNSZ #define SA_PROCESS_CMDLINE PRARGSZ #define SA_PROCESS_PARENT_PID #define SA_PROCESS_PGRP #define SA_PROCESS_SID #define SA_PROCESS_TTY #define SA_PROCESS_NICE #define SA_PROCESS_START_TIME #define SA_PROCESS_STATE #define SA_PROCESS_USER_TIME #define SA_PROCESS_SYS_TIME #define SA_PROCESS_THREADS #define SA_PROCESS_VM_SIZE #define SA_PROCESS_RSS #define SA_OPEN_SWAP #define SA_CLOSE_SWAP #define SA_SWAP_NAME 256 #define SA_SWAP_TOTAL #define SA_SWAP_FREE #undef SA_SWAP_TYPE #include "global.h" #ifdef __cplusplus } #endif #endif /* LIBSYSACTIVITY_H_ */ libsysactivity-0.6.5/src/SunOS/disk.c0000644000175000017500000000630212220245547016474 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include static kstat_t* get_next_ksp(kstat_t* ksp); static int assign_dst(struct sa_disk* dst, kstat_t* ksp) SA_NONNULL; __thread kstat_ctl_t* disk_kc; int sa_open_disk() { disk_kc = kstat_open(); if (disk_kc == NULL) return ENOSYS; return 0; } int sa_close_disk() { if (disk_kc != NULL) kstat_close(disk_kc); return 0; } int sa_count_disks(uint16_t* number) { if (number == NULL) return EINVAL; if (kstat_chain_update(disk_kc) == -1) return errno; kstat_t* ksp = NULL; *number = 0; while ((ksp = get_next_ksp(ksp)) != NULL) ++(*number); return 0; } int sa_reset_disks() { if(kstat_chain_update(disk_kc) == -1) return errno; return 0; } int sa_get_disks_ids(char* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; uint16_t i; kstat_t* ksp = NULL; *written = 0; for (i = 0; (ksp = get_next_ksp(ksp)) != NULL; ++i) { if (i == dst_size) return ENOMEM; strncpy(&dst[i * SA_DISK_NAME], ksp->ks_name, SA_DISK_NAME); ++(*written); } return 0; } int sa_get_disk(char* name, struct sa_disk* dst) { if (name == NULL || dst == NULL) return EINVAL; kstat_t* ksp = NULL; while ((ksp = get_next_ksp(ksp)) != NULL) { if (strncmp(ksp->ks_name, name, sizeof ksp->ks_name) != 0) continue; if (assign_dst(dst, ksp) != 0) return ENOSYS; return 0; } return ENODEV; } int sa_get_disks(struct sa_disk* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; uint16_t i; kstat_t* ksp = NULL; *written = 0; for (i = 0; (ksp = get_next_ksp(ksp)) != NULL; ++i) { if (i == dst_size) return ENOMEM; if (assign_dst(&dst[i], ksp) != 0) return ENOSYS; ++(*written); } return 0; } static kstat_t* get_next_ksp(kstat_t* ksp) { do { if (ksp == NULL) ksp = disk_kc->kc_chain; else ksp = ksp->ks_next; if (ksp == NULL) return ksp; } while (ksp->ks_type != KSTAT_TYPE_IO); return ksp; } static int assign_dst(struct sa_disk* dst, kstat_t* ksp) { kstat_io_t kio; if (kstat_read(disk_kc, ksp, &kio) == -1) return errno; strncpy(dst->name, ksp->ks_name, sizeof dst->name); dst->reads = kio.reads; dst->writes = kio.writes; dst->bytes_read = kio.nread; dst->bytes_written = kio.nwritten; return 0; } libsysactivity-0.6.5/src/SunOS/cpu.c0000644000175000017500000000636212220245547016337 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include "utils.h" typedef struct { uint32_t user, system, idle, waiting_for_io; } CPU_TIMES_t; static void calculate_cpu_times(struct sa_cpu* dst, CPU_TIMES_t* cpu_old_times, CPU_TIMES_t* cpu_new_times) SA_NONNULL; #define NUMBER_CPUS 1 __thread kstat_ctl_t* cpu_kc; __thread CPU_TIMES_t cpus; __thread CPU_TIMES_t diffs; __thread cpu_stat_t* cpu_stat; int sa_open_cpu() { cpu_kc = kstat_open(); if (cpu_kc == NULL) return ENOSYS; bzero(&cpus, sizeof cpus); return 0; } int sa_close_cpu() { if (cpu_kc != NULL) kstat_close(cpu_kc); return 0; } int sa_reset_cpus() { kstat_t* ks; if (get_ks(cpu_kc, &ks, "cpu_stat", "cpu_stat0") != 0) return ENOSYS; if (ks->ks_data_size != sizeof(cpu_stat_t)) return ENOSYS; cpu_stat = (cpu_stat_t*) ks->ks_data; return 0; } int sa_get_cpu(uint16_t index, struct sa_cpu* dst) { if (index > 0 || dst == NULL) return EINVAL; CPU_TIMES_t cpu_new_times; cpu_new_times.user = cpu_stat->cpu_sysinfo.cpu[CPU_USER]; cpu_new_times.system = cpu_stat->cpu_sysinfo.cpu[CPU_KERNEL]; cpu_new_times.idle = cpu_stat->cpu_sysinfo.cpu[CPU_IDLE]; cpu_new_times.waiting_for_io = cpu_stat->cpu_syswait.iowait; dst->id = 0; //TODO smp.. calculate_cpu_times(dst, &cpus, &cpu_new_times); return 0; } int sa_count_cpus(uint16_t* number) { if (number == NULL) return EINVAL; *number = NUMBER_CPUS; return 0; } int sa_get_cpus(struct sa_cpu* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; sa_get_cpu(0, dst); *written = NUMBER_CPUS; return 0; } static void calculate_cpu_times(struct sa_cpu* dst, CPU_TIMES_t* cpu_old_times, CPU_TIMES_t* cpu_new_times) { diffs.user = cpu_new_times->user - cpu_old_times->user; diffs.system = cpu_new_times->system - cpu_old_times->system; diffs.idle = cpu_new_times->idle - cpu_old_times->idle; diffs.waiting_for_io = cpu_new_times->waiting_for_io - cpu_old_times->waiting_for_io; uint64_t total = diffs.user + diffs.system + diffs.idle + diffs.waiting_for_io; float scale; if (total == 0) scale = 1; else scale = (float) total / 100.0; dst->user = diffs.user / scale; dst->system = diffs.system / scale; dst->idle = diffs.idle / scale; dst->waiting_for_io = diffs.waiting_for_io / scale; *cpu_old_times = *cpu_new_times; } libsysactivity-0.6.5/src/SunOS/CMakeLists.txt0000644000175000017500000000065212220245547020140 0ustar hazelhazel list(APPEND SPECIFIC_HDRS libsysactivity.h) INSTALL(FILES ${SPECIFIC_HDRS} DESTINATION ${HEADERS_INSTALLATION_DIR}) FILE(GLOB LIBSA_SPECIFIC_SRCS *.c) ADD_LIBRARY(sysactivity SHARED ${LIBSA_SPECIFIC_SRCS}) set_target_properties(sysactivity PROPERTIES VERSION ${LIBSA_VERSION} SOVERSION ${LIBSA_ABI_VERSION}) TARGET_LINK_LIBRARIES(sysactivity kstat) INSTALL(TARGETS sysactivity LIBRARY DESTINATION ${LIB_INSTALLATION_DIR}) libsysactivity-0.6.5/src/OpenBSD/0000755000175000017500000000000012220245547015620 5ustar hazelhazellibsysactivity-0.6.5/src/OpenBSD/utils.h0000644000175000017500000000205212220245547017130 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef UTILS_H_ #define UTILS_H_ #include void free_keys(void * resource); int safe_realloc(void** ptr, size_t* size) SA_NONNULL; #endif /* UTILS_H_ */ libsysactivity-0.6.5/src/OpenBSD/utils.c0000644000175000017500000000226012220245547017124 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include "utils.h" void free_keys(void * resource) { free(resource); } int safe_realloc(void** ptr, size_t* size) { void* tmp = realloc(*ptr, *size); if (tmp == NULL) { free(*ptr); *ptr = NULL; *size = 0; return ENOMEM; } *ptr = tmp; return 0; } libsysactivity-0.6.5/src/OpenBSD/swap.c0000644000175000017500000000722112220245547016740 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include "utils.h" pthread_key_t buffer_key; pthread_key_t buffer_size_key; pthread_key_t number_swaps_key; static void create_keys(); int sa_open_swap() { pthread_once_t key_once = PTHREAD_ONCE_INIT; if (pthread_once(&key_once, create_keys)) return ENOSYS; return 0; } int sa_count_swaps(uint16_t* number) { if (number == NULL) return EINVAL; *number = (uint16_t) swapctl(SWAP_NSWAP, NULL, 0); return 0; } int sa_reset_swaps() { int number_swaps; struct swapent* buffer = (struct swapent*) pthread_getspecific(buffer_key); size_t buffer_size = (size_t) pthread_getspecific(buffer_size_key); do { number_swaps = swapctl(SWAP_NSWAP, NULL, 0); if (pthread_setspecific(number_swaps_key, (void *) number_swaps)) return ENOSYS; size_t size = number_swaps * sizeof(struct swapent); if (buffer_size < size) { safe_realloc((void*) &buffer, &size); if (pthread_setspecific(buffer_key, buffer)) return ENOSYS; buffer_size = size; if (pthread_setspecific(buffer_size_key, (void *) buffer_size)) return ENOSYS; if (buffer == NULL) return ENOMEM; } errno = 0; if (swapctl(SWAP_STATS, buffer, number_swaps) == -1 && errno != ENOMEM) return ENOSYS; } while (errno == ENOMEM); return 0; } int sa_get_swap(uint16_t index, struct sa_swap* dst) { if (dst == NULL) return EINVAL; int number_swaps = (int) pthread_getspecific(number_swaps_key); if (index >= number_swaps) return ENODEV; struct swapent* buffer = (struct swapent*) pthread_getspecific(buffer_key); strlcpy(dst->name, buffer[index].se_path, sizeof dst->name); dst->total = (uint64_t) buffer[index].se_nblks * DEV_BSIZE; dst->free = (uint64_t) (buffer[index].se_nblks - buffer[index].se_inuse) * DEV_BSIZE; return 0; } int sa_get_swaps(struct sa_swap* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; struct swapent* buffer = (struct swapent*) pthread_getspecific(buffer_key); int number_swaps = (int) pthread_getspecific(number_swaps_key); *written = 0; uint16_t i; for (i = 0; i < number_swaps; ++i) { if (i == dst_size) return ENOMEM; strlcpy(dst[i].name, buffer[i].se_path, sizeof dst->name); dst[i].total = (uint64_t) buffer[i].se_nblks * DEV_BSIZE; dst[i].free = (uint64_t) (buffer[i].se_nblks - buffer[i].se_inuse) * DEV_BSIZE; ++(*written); } return 0; } static void create_keys() { static short keys_created = 0; if (keys_created) { return; } pthread_key_create(&buffer_key, free_keys); pthread_key_create(&buffer_size_key, NULL); pthread_key_create(&number_swaps_key, NULL); keys_created = 1; } libsysactivity-0.6.5/src/OpenBSD/process.c0000644000175000017500000001273112220245547017446 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2012 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include #include "utils.h" static void create_keys(); static void assign(struct sa_process* dst, struct kinfo_proc* proc) SA_HOT SA_NONNULL; static void assign_activity(struct sa_process_activity* dst, struct kinfo_proc* proc) SA_HOT SA_NONNULL; static int refresh_processes(struct kinfo_proc** processes, uint32_t* amount) SA_NONNULL; long pagesize; pthread_key_t processes_key; pthread_key_t processes_size_key; int sa_open_process() { pthread_once_t key_once = PTHREAD_ONCE_INIT; if (pthread_once(&key_once, create_keys)) return ENOSYS; return 0; } int sa_count_processes(uint32_t* number) { if (number == NULL) return EINVAL; int mib[6]; size_t len; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_ALL; mib[3] = 0; mib[4] = sizeof(struct kinfo_proc); mib[5] = 0; if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1) return ENOSYS; // TODO sysctl says that there are more processes than actually are. I guess the second sysctl call is right. *number = len / sizeof(struct kinfo_proc); return 0; } int sa_get_processes_ids(pid_t* dst, uint32_t dst_size, uint32_t* written) { if (dst == NULL || dst_size <= 0 || written == NULL) return EINVAL; struct kinfo_proc* processes; uint32_t amount; int ret = refresh_processes(&processes, &amount); if (ret != 0) return ret; uint32_t i; *written = 0; for (i = 0; i < amount; ++i) { if (i == dst_size) return ENOMEM; dst[i] = processes[i].p_pid; ++(*written); } return 0; } int sa_get_process(pid_t pid, struct sa_process* dst) { if (pid == 0 || dst == NULL) return EINVAL; int mib[6]; struct kinfo_proc proc; size_t len = sizeof proc; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PID; mib[3] = pid; mib[4] = len; mib[5] = 1; proc.p_paddr = 0; if (sysctl(mib, 6, &proc, &len, NULL, 0) == -1) return ENOSYS; // TODO Return something more specific in case the process does not exist if (proc.p_paddr == 0) return ESRCH; assign(dst, &proc); return 0; } int sa_get_process_activity(pid_t pid, struct sa_process_activity* dst) { if (pid == 0 || dst == NULL) return EINVAL; int mib[6]; struct kinfo_proc proc; size_t len = sizeof proc; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_PID; mib[3] = pid; mib[4] = len; mib[5] = 1; proc.p_paddr = 0; if (sysctl(mib, 6, &proc, &len, NULL, 0) == -1) return ENOSYS; // TODO Return something more specific in case the process does not exist if (proc.p_paddr == 0) return ESRCH; assign_activity(dst, &proc); return 0; } static void create_keys() { static short keys_created = 0; if (keys_created) { return; } pagesize = sysconf(_SC_PAGESIZE); pthread_key_create(&processes_key, free_keys); pthread_key_create(&processes_size_key, NULL); keys_created = 1; } static void assign(struct sa_process* dst, struct kinfo_proc* proc) { dst->pid = proc->p_pid; dst->uid = proc->p_uid; dst->gid = proc->p_gid; strlcpy(dst->filename, proc->p_comm, KI_MAXCOMLEN); dst->parent_pid = proc->p_ppid; dst->pgrp = proc->p__pgid; dst->sid = proc->p_sid; dst->tty = proc->p_tdev; dst->nice = proc->p_nice - 20; dst->start_time = proc->p_ustart_sec * 100 + proc->p_ustart_usec / 10000; assign_activity(&dst->activity, proc); } static void assign_activity(struct sa_process_activity* dst, struct kinfo_proc* proc) { dst->pid = proc->p_pid; dst->user_time = proc->p_uticks; dst->sys_time = proc->p_sticks; dst->vm_size = proc->p_vm_map_size; dst->rss = proc->p_vm_rssize * pagesize; } static int refresh_processes(struct kinfo_proc** processes, uint32_t* amount) { int mib[6]; size_t len; mib[0] = CTL_KERN; mib[1] = KERN_PROC; mib[2] = KERN_PROC_ALL; mib[3] = 0; mib[4] = sizeof(struct kinfo_proc); mib[5] = 0; do { if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1) return ENOSYS; size_t processes_size = (size_t) pthread_getspecific(processes_size_key); *processes = pthread_getspecific(processes_key); if (processes_size < len) { safe_realloc((void*) processes, &len); if (pthread_setspecific(processes_key, *processes)) return ENOSYS; processes_size = len; if (pthread_setspecific(processes_size_key, (void*) processes_size)) return ENOSYS; if (*processes == NULL) return ENOMEM; } mib[5] = len / sizeof(struct kinfo_proc); errno = 0; if (sysctl(mib, 6, *processes, &len, NULL, 0) == -1 && errno != ENOMEM) return ENOSYS; } while (errno == ENOMEM); *amount = len / sizeof(struct kinfo_proc); return 0; } libsysactivity-0.6.5/src/OpenBSD/network.c0000644000175000017500000001400612220245547017456 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include "utils.h" pthread_key_t buffer_key; pthread_key_t buffer_size_key; pthread_key_t size_key; static void create_keys(); static struct if_msghdr* get_next_if_hdr(size_t* offset, const void* buffer, const size_t size) SA_NONNULL; static void assign(struct sa_net_interface* __restrict__ dst, struct if_msghdr* if_hdr) SA_NONNULL; int sa_open_net() { pthread_once_t key_once = PTHREAD_ONCE_INIT; if (pthread_once(&key_once, create_keys)) return ENOSYS; return 0; } int sa_count_net_interfaces(uint16_t* number) { if (number == NULL) return EINVAL; if (sa_reset_net_interfaces()) return ENOSYS; size_t offset = 0; void* buffer = pthread_getspecific(buffer_key); size_t size = (size_t) pthread_getspecific(size_key); *number = 0; while (get_next_if_hdr(&offset, buffer, size) != NULL) ++(*number); return 0; } int sa_reset_net_interfaces() { int mib[6] = { CTL_NET, AF_ROUTE, 0, 0, NET_RT_IFLIST, 0 }; size_t size = (size_t) pthread_getspecific(size_key); do { if (sysctl(mib, 6, NULL, &size, NULL, 0) == -1) return ENOSYS; size_t buffer_size = (size_t) pthread_getspecific(buffer_size_key); void* buffer = pthread_getspecific(buffer_key); if (buffer_size < size) { safe_realloc(&buffer, &size); if (pthread_setspecific(buffer_key, buffer)) return ENOSYS; buffer_size = size; if (pthread_setspecific(buffer_size_key, (void *) buffer_size)) return ENOSYS; if (buffer == NULL) return ENOMEM; } errno = 0; if (sysctl(mib, 6, buffer, &size, NULL, 0) == -1 && errno != ENOMEM) return ENOSYS; } while (errno == ENOMEM); if (pthread_setspecific(size_key, (void *) size)) return ENOSYS; return 0; } int sa_get_net_interfaces_ids(char* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; size_t offset = 0; void* buffer = pthread_getspecific(buffer_key); size_t size = (size_t) pthread_getspecific(size_key); *written = 0; struct if_msghdr* if_hdr; struct sockaddr_dl* sdl; uint16_t i = 0; for (i = 0; (if_hdr = get_next_if_hdr(&offset, buffer, size)) != NULL; ++i) { if (i == dst_size) return ENOMEM; sdl = (struct sockaddr_dl*) (if_hdr + 1); strlcpy(&dst[i * SA_NET_INTERFACE_NAME], sdl->sdl_data, SA_NET_INTERFACE_NAME); ++(*written); } return 0; } int sa_get_net_interface(char* name, struct sa_net_interface* dst) { if (name == NULL || dst == NULL) return EINVAL; size_t offset = 0; void* buffer = pthread_getspecific(buffer_key); size_t size = (size_t) pthread_getspecific(size_key); struct if_msghdr* if_hdr; struct sockaddr_dl* sdl; while ((if_hdr = get_next_if_hdr(&offset, buffer, size)) != NULL) { sdl = (struct sockaddr_dl*) (if_hdr + 1); if (strncmp(sdl->sdl_data, name, sizeof sdl->sdl_nlen) != 0) continue; assign(dst, if_hdr); return 0; } return ENODEV; } int sa_get_net_interfaces(struct sa_net_interface* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; size_t offset = 0; void* buffer = pthread_getspecific(buffer_key); size_t size = (size_t) pthread_getspecific(size_key); *written = 0; struct if_msghdr* if_hdr; uint16_t i = 0; for (i = 0; (if_hdr = get_next_if_hdr(&offset, buffer, size)) != NULL; ++i) { if (i == dst_size) return ENOMEM; assign(&dst[i], if_hdr); ++(*written); } return 0; } static void create_keys() { static short keys_created = 0; if (keys_created) { return; } pthread_key_create(&buffer_key, free_keys); pthread_key_create(&buffer_size_key, NULL); pthread_key_create(&size_key, NULL); keys_created = 1; } static struct if_msghdr* get_next_if_hdr(size_t* offset, const void* buffer, const size_t size) { struct if_msghdr* if_hdr; struct rt_msghdr* rt_hdr; struct sockaddr_dl* sdl; while (*offset < size) { rt_hdr = (struct rt_msghdr*) (buffer + *offset); if (rt_hdr->rtm_version != RTM_VERSION || rt_hdr->rtm_type != RTM_IFINFO) { *offset += rt_hdr->rtm_msglen; continue; } if_hdr = (struct if_msghdr*) (buffer + *offset); if (!(if_hdr->ifm_addrs & (1 << RTAX_IFP))) { *offset += rt_hdr->rtm_msglen; continue; } sdl = (struct sockaddr_dl*) (if_hdr + 1); if (sdl == NULL || sdl->sdl_family != AF_LINK) { *offset += rt_hdr->rtm_msglen; continue; } *offset += rt_hdr->rtm_msglen; return if_hdr; } return NULL; } static void assign(struct sa_net_interface* __restrict__ dst, struct if_msghdr* if_hdr) { struct sockaddr_dl* sdl = (struct sockaddr_dl*) (if_hdr + 1); struct if_data* if_data = &if_hdr->ifm_data; strlcpy(dst->name, sdl->sdl_data, sizeof dst->name); dst->received_bytes = if_data->ifi_ibytes; dst->received_packets = if_data->ifi_ipackets; dst->received_errors = if_data->ifi_ierrors; dst->received_drop = if_data->ifi_iqdrops; dst->received_multicast = if_data->ifi_imcasts; dst->sent_bytes = if_data->ifi_obytes; dst->sent_packets = if_data->ifi_opackets; dst->sent_errors = if_data->ifi_oerrors; dst->sent_multicast = if_data->ifi_omcasts; } libsysactivity-0.6.5/src/OpenBSD/memory.c0000644000175000017500000000417012220245547017276 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include "utils.h" int pagesize; int sa_open_memory() { int mib[] = { CTL_HW, HW_PAGESIZE }; size_t len = sizeof (pagesize); if (sysctl(mib, 2, &pagesize, &len, NULL, 0) == -1) return ENOSYS; return 0; } int sa_get_memory(struct sa_memory* dst) { if (dst == NULL) return EINVAL; size_t memory_total; int mib[] = { CTL_HW, HW_PHYSMEM }; size_t len = sizeof memory_total; if (sysctl(mib, 2, &memory_total, &len, NULL, 0) == -1) return ENOSYS; dst->total = (uint64_t) memory_total; mib[0] = CTL_VM; mib[1] = VM_METER; struct vmtotal vmtotal; len = sizeof vmtotal; if (sysctl(mib, sizeof(mib) / sizeof(int), &vmtotal, &len, NULL, 0) == -1) return ENOSYS; dst->free = (uint64_t) vmtotal.t_free * pagesize; dst->active = (uint64_t) vmtotal.t_arm * pagesize; dst->inactive = (uint64_t) vmtotal.t_rm * pagesize; struct swapent swapent; if (swapctl(SWAP_STATS, &swapent, 1) == -1) return ENOSYS; dst->swap_total = (uint64_t) swapent.se_nblks * DEV_BSIZE; dst->swap_free = (uint64_t) (swapent.se_nblks - swapent.se_inuse) * DEV_BSIZE; return 0; } libsysactivity-0.6.5/src/OpenBSD/libsysactivity.h0000644000175000017500000000660012220245547021055 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef LIBSYSACTIVITY_H_ #define LIBSYSACTIVITY_H_ #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif #define SA_OPEN_CPU #undef SA_CLOSE_CPU #undef SA_SMP_CAPABLE #define SA_CPU_ID #define SA_CPU_USER #define SA_CPU_NICE #define SA_CPU_SYSTEM #define SA_CPU_IDLE #undef SA_CPU_WAITING_FOR_IO #undef SA_CPU_HARDWARE_IRQ #undef SA_CPU_SOFTWARE_IRQ #undef SA_CPU_STOLEN #define SA_CPU_INTR #define SA_OPEN_DISK #undef SA_CLOSE_DISK #define SA_DISK_NAME DS_DISKNAMELEN #define SA_DISK_READS #undef SA_DISK_READS_MERGED #undef SA_DISK_SECTORS_READ #undef SA_DISK_TIME_SPENT_READING #define SA_DISK_WRITES #undef SA_DISK_SECTORS_WRITTEN #undef SA_DISK_TIME_SPENT_WRITING #define SA_DISK_BYTES_READ #define SA_DISK_BYTES_WRITTEN #define SA_OPEN_MEMORY #undef SA_CLOSE_MEMORY #define SA_MEMORY_TOTAL #define SA_MEMORY_FREE #define SA_MEMORY_ACTIVE #define SA_MEMORY_INACTIVE #undef SA_MEMORY_BUFFERS #define SA_MEMORY_SWAP_TOTAL #define SA_MEMORY_SWAP_FREE #undef SA_MEMORY_SWAP_CACHED #undef SA_MEMORY_WIRED #undef SA_MEMORY_CACHED #undef SA_MEMORY_DIRTY #undef SA_MEMORY_EXECUTABLE #undef SA_MEMORY_FILES #undef SA_MEMORY_LOCKED #define SA_OPEN_NET #undef SA_CLOSE_NET #define SA_NET_INTERFACE_NAME 12 // if_dl.h:67 #define SA_NET_INTERFACE_RECEIVED_BYTES #define SA_NET_INTERFACE_RECEIVED_PACKETS #define SA_NET_INTERFACE_RECEIVED_ERRORS #define SA_NET_INTERFACE_RECEIVED_DROP #undef SA_NET_INTERFACE_RECEIVED_FIFO #define SA_NET_INTERFACE_RECEIVED_MULTICAST #define SA_NET_INTERFACE_SENT_BYTES #define SA_NET_INTERFACE_SENT_PACKETS #define SA_NET_INTERFACE_SENT_ERRORS #undef SA_NET_INTERFACE_SENT_DROP #undef SA_NET_INTERFACE_SENT_FIFO #undef SA_NET_INTERFACE_SENT_COMPRESSED #define SA_NET_INTERFACE_SENT_MULTICAST #define SA_OPEN_PROCESS #undef SA_CLOSE_PROCESS #define SA_PROCESS_PID #define SA_PROCESS_UID #define SA_PROCESS_GID #define SA_PROCESS_FILENAME KI_MAXCOMLEN #undef SA_PROCESS_CMDLINE #define SA_PROCESS_PARENT_PID #define SA_PROCESS_PGRP #define SA_PROCESS_SID #define SA_PROCESS_TTY #define SA_PROCESS_NICE #define SA_PROCESS_START_TIME #undef SA_PROCESS_STATE #define SA_PROCESS_USER_TIME #define SA_PROCESS_SYS_TIME #undef SA_PROCESS_THREADS #define SA_PROCESS_VM_SIZE #define SA_PROCESS_RSS #define SA_OPEN_SWAP #undef SA_CLOSE_SWAP #define SA_SWAP_NAME MAXPATHLEN #define SA_SWAP_TOTAL #define SA_SWAP_FREE #undef SA_SWAP_TYPE #include "global.h" #ifdef __cplusplus } #endif #endif /* LIBSYSACTIVITY_H_ */ libsysactivity-0.6.5/src/OpenBSD/disk.c0000644000175000017500000001047412220245547016724 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include "utils.h" pthread_key_t buffer_key; pthread_key_t buffer_size_key; pthread_key_t number_disks_key; static void create_keys(); void assign(struct sa_disk* __restrict__ dst, const struct diskstats* __restrict__ src) SA_NONNULL; int sa_open_disk() { pthread_once_t key_once = PTHREAD_ONCE_INIT; if (pthread_once(&key_once, create_keys)) return ENOSYS; return 0; } int sa_count_disks(uint16_t* number) { if (number == NULL) return EINVAL; int mib[] = { CTL_HW, HW_DISKCOUNT }; int n_disks; size_t size = sizeof number; if (sysctl(mib, 2, &n_disks, &size, NULL, 0) < 0) return ENOSYS; *number = n_disks; return 0; } int sa_reset_disks() { int ret; uint16_t number; size_t size; struct diskstats* buffer = pthread_getspecific(buffer_key); size_t buffer_size = (size_t) pthread_getspecific(buffer_size_key); int mib[] = { CTL_HW, HW_DISKSTATS }; do { ret = sa_count_disks(&number); if (ret != 0) return ret; size = number * sizeof(struct diskstats); if (buffer_size < size) { safe_realloc((void*) &buffer, &size); if (pthread_setspecific(buffer_key, buffer)) return ENOSYS; buffer_size = size; if (pthread_setspecific(buffer_size_key, (void *) buffer_size)) return ENOSYS; if (buffer == NULL) return ENOMEM; } errno = 0; if (sysctl(mib, 2, buffer, &buffer_size, NULL, 0) < 0 && errno != ENOMEM) return ENOSYS; } while (errno == ENOMEM); if (pthread_setspecific(number_disks_key, (void *) (int) number)) return ENOSYS; return 0; } int sa_get_disks_ids(char* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; struct diskstats* buffer = pthread_getspecific(buffer_key); size_t number_disks = (size_t) pthread_getspecific(number_disks_key); *written = 0; size_t i; for (i = 0; i < number_disks; ++i) { if (i == dst_size) return ENOMEM; strlcpy(&dst[i * SA_DISK_NAME], buffer[i].ds_name, DS_DISKNAMELEN); ++(*written); } return 0; } int sa_get_disk(char* name, struct sa_disk* dst) { if (name == NULL || dst == NULL) return EINVAL; struct diskstats* buffer = pthread_getspecific(buffer_key); size_t number_disks = (size_t) pthread_getspecific(number_disks_key); size_t i; for (i = 0; i < number_disks; ++i) { if (strncmp(buffer[i].ds_name, name, DS_DISKNAMELEN) != 0) continue; assign(dst, &buffer[i]); return 0; } return ENODEV; } int sa_get_disks(struct sa_disk* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; struct diskstats* buffer = pthread_getspecific(buffer_key); size_t number_disks = (size_t) pthread_getspecific(number_disks_key); *written = 0; size_t i; for (i = 0; i < number_disks; ++i) { if (i == dst_size) return ENOMEM; assign(&dst[i], &buffer[i]); ++(*written); } return 0; } static void create_keys() { static short keys_created = 0; if (keys_created) { return; } pthread_key_create(&buffer_key, free_keys); pthread_key_create(&buffer_size_key, NULL); pthread_key_create(&number_disks_key, NULL); keys_created = 1; } void assign(struct sa_disk* __restrict__ dst, const struct diskstats* __restrict__ src) { strlcpy(dst->name, src->ds_name, DS_DISKNAMELEN); dst->reads = src->ds_rxfer; dst->writes = src->ds_wxfer; dst->bytes_read = src->ds_rbytes; dst->bytes_written = src->ds_wbytes; } libsysactivity-0.6.5/src/OpenBSD/cpu.c0000644000175000017500000001257712220245547016567 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include "utils.h" static void create_keys(); static void calculate_cpu(struct sa_cpu* dst) SA_NONNULL; static inline void percentages(long* new, long* old) SA_NONNULL; pthread_key_t cp_time_key; pthread_key_t cp_old_key; int sa_open_cpu() { pthread_once_t key_once = PTHREAD_ONCE_INIT; if (pthread_once(&key_once, create_keys)) return ENOSYS; long* cp_time = malloc(CPUSTATES * sizeof (long)); if (cp_time == NULL) return ENOMEM; if (pthread_setspecific(cp_time_key, cp_time)) return ENOSYS; long* cp_old = malloc(CPUSTATES * sizeof (long)); if (cp_old == NULL) return ENOMEM; if (pthread_setspecific(cp_old_key, cp_old)) return ENOSYS; return 0; } int sa_reset_cpus() { long* cp_time = pthread_getspecific(cp_time_key); int cp_time_mib[] = { CTL_KERN, KERN_CPTIME }; size_t len = CPUSTATES * sizeof (long); if (sysctl(cp_time_mib, 2, cp_time, &len, NULL, 0) == -1) return ENOSYS; return 0; } int sa_get_cpu(uint16_t index, struct sa_cpu* dst) { if (index > 0 || dst == NULL) return EINVAL; calculate_cpu(dst); return 0; } int sa_count_cpus(uint16_t* number) { if (number == NULL) return EINVAL; *number = 1; return 0; } int sa_get_cpus(struct sa_cpu* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 1; calculate_cpu(dst); return 0; } static void create_keys() { static short keys_created = 0; if (keys_created) { return; } pthread_key_create(&cp_time_key, free_keys); pthread_key_create(&cp_old_key, free_keys); keys_created = 1; } static void calculate_cpu(struct sa_cpu* dst) { long* cp_time = pthread_getspecific(cp_time_key); long* cp_old = pthread_getspecific(cp_old_key); percentages(cp_time, cp_old); dst->id = 0; dst->user = cp_time[CP_USER] / 10; dst->nice = cp_time[CP_NICE] / 10; dst->system = cp_time[CP_SYS] / 10; dst->idle = cp_time[CP_IDLE] / 10; dst->intr = cp_time[CP_INTR] / 10; } /* * This function is taken from unixtop 3.8beta1 at http://www.unixtop.org/download/ * * Copyright (c) 1984 through 2008, William LeFebvre * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * * Neither the name of William LeFebvre nor the names of other * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ static inline void percentages(long* new, long* old) { register int i; long change; long total_change; long half_total; long cp_diff[CPUSTATES]; total_change = 0; /* calculate changes for each state and the overall change */ for (i = 0; i < CPUSTATES; ++i) { if ((change = new[i] - old[i]) < 0) { /* this only happens when the counter wraps */ change = (int) ((unsigned long) new[i] - (unsigned long) old[i]); } total_change += (cp_diff[i] = change); old[i] = new[i]; } /* avoid divide by zero potential */ if (total_change == 0) total_change = 1; /* calculate percentages based on overall change, rounding up */ half_total = total_change / 2l; for (i = 0; i < CPUSTATES; ++i) new[i] = (cp_diff[i] * 1000 + half_total) / total_change; } libsysactivity-0.6.5/src/OpenBSD/CMakeLists.txt0000644000175000017500000000064412220245547020364 0ustar hazelhazel list(APPEND SPECIFIC_HDRS libsysactivity.h) INSTALL(FILES ${SPECIFIC_HDRS} DESTINATION ${HEADERS_INSTALLATION_DIR}) FILE(GLOB LIBSA_SPECIFIC_SRCS *.c) ADD_LIBRARY(sysactivity SHARED ${LIBSA_SPECIFIC_SRCS}) set_target_properties(sysactivity PROPERTIES VERSION ${LIBSA_VERSION} SOVERSION ${LIBSA_ABI_VERSION}) TARGET_LINK_LIBRARIES(sysactivity) INSTALL(TARGETS sysactivity LIBRARY DESTINATION ${LIB_INSTALLATION_DIR}) libsysactivity-0.6.5/src/NetBSD/0000755000175000017500000000000012220245547015445 5ustar hazelhazellibsysactivity-0.6.5/src/NetBSD/process.c0000644000175000017500000001074712220245547017300 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include #include #include "../OpenBSD/utils.h" static void create_keys(); static void assign(struct sa_process* dst, struct kinfo_proc2* proc) SA_HOT SA_NONNULL; static void assign_activity(struct sa_process_activity* dst, struct kinfo_proc2* proc) SA_HOT SA_NONNULL; static void close_keys(void* resource); long pagesize; pthread_key_t dir_proc_key; int sa_open_process() { pthread_once_t key_once = PTHREAD_ONCE_INIT; if (pthread_once(&key_once, create_keys)) return ENOSYS; DIR* dir_proc = opendir("/proc/"); if (pthread_setspecific(dir_proc_key, dir_proc)) return ENOSYS; if (dir_proc == NULL) return EIO; return 0; } int sa_count_processes(uint32_t* number) { if (number == NULL) return EINVAL; DIR* dir_proc = pthread_getspecific(dir_proc_key); rewinddir(dir_proc); *number = 0; struct dirent* entry; while ((entry = readdir(dir_proc)) != NULL) { if (!isdigit((int) entry->d_name[0])) continue; ++(*number); } return 0; } int sa_get_processes_ids(pid_t* dst, uint32_t dst_size, uint32_t* written) { if (dst == NULL || dst_size <= 0 || written == NULL) return EINVAL; DIR* dir_proc = pthread_getspecific(dir_proc_key); rewinddir(dir_proc); *written = 0; struct dirent* entry; while ((entry = readdir(dir_proc)) != NULL) { if (!isdigit((int) entry->d_name[0])) continue; if (*written == dst_size) return ENOMEM; dst[*written] = atoi(entry->d_name); ++(*written); } return 0; } int sa_get_process(pid_t pid, struct sa_process* dst) { if (dst == NULL) return EINVAL; int mib[6]; struct kinfo_proc2 proc; size_t len = sizeof proc; mib[0] = CTL_KERN; mib[1] = KERN_PROC2; mib[2] = KERN_PROC_PID; mib[3] = pid; mib[4] = len; mib[5] = 1; proc.p_paddr = 0; if (sysctl(mib, 6, &proc, &len, NULL, 0) == -1) return ENOSYS; // TODO Return something more specific in case the process does not exist if (proc.p_paddr == 0) return ESRCH; assign(dst, &proc); return 0; } int sa_get_process_activity(pid_t pid, struct sa_process_activity* dst) { if (dst == NULL) return EINVAL; int mib[6]; struct kinfo_proc2 proc; size_t len = sizeof proc; mib[0] = CTL_KERN; mib[1] = KERN_PROC2; mib[2] = KERN_PROC_PID; mib[3] = pid; mib[4] = len; mib[5] = 1; proc.p_paddr = 0; if (sysctl(mib, 6, &proc, &len, NULL, 0) == -1) return ENOSYS; // TODO Return something more specific in case the process does not exist if (proc.p_paddr == 0) return ESRCH; assign_activity(dst, &proc); return 0; } static void create_keys() { static short keys_created = 0; if (keys_created) { return; } pagesize = sysconf(_SC_PAGESIZE); pthread_key_create(&dir_proc_key, close_keys); keys_created = 1; } static void assign(struct sa_process* dst, struct kinfo_proc2* proc) { dst->pid = proc->p_pid; dst->uid = proc->p_uid; dst->gid = proc->p_gid; strlcpy(dst->filename, proc->p_comm, KI_MAXCOMLEN); dst->parent_pid = proc->p_ppid; dst->pgrp = proc->p__pgid; dst->sid = proc->p_sid; dst->tty = proc->p_tdev; dst->nice = proc->p_nice - 20; dst->start_time = proc->p_ustart_sec * 100 + proc->p_ustart_usec / 10000; assign_activity(&dst->activity, proc); } static void assign_activity(struct sa_process_activity* dst, struct kinfo_proc2* proc) { dst->pid = proc->p_pid; dst->user_time = proc->p_uticks; dst->sys_time = proc->p_sticks; dst->vm_size = proc->p_vm_vsize; dst->rss = proc->p_vm_rssize * pagesize; } static void close_keys(void* resource) { closedir(resource); } libsysactivity-0.6.5/src/NetBSD/memory.c0000644000175000017500000000404212220245547017121 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include "../OpenBSD/utils.h" int sa_get_memory(struct sa_memory* dst) { if (dst == NULL) return EINVAL; size_t val; int mib[] = { CTL_HW, HW_PHYSMEM }; size_t len = sizeof val; if (sysctl(mib, sizeof(mib) / sizeof(int), &val, &len, NULL, 0) == -1) return ENOSYS; dst->total = (uint64_t) val; mib[0] = CTL_VM; mib[1] = VM_UVMEXP2; struct uvmexp_sysctl uvmexp; len = sizeof uvmexp; if (sysctl(mib, sizeof(mib) / sizeof(int), &uvmexp, &len, NULL, 0) == -1) return ENOSYS; dst->free = (uint64_t) uvmexp.free * uvmexp.pagesize; dst->active = (uint64_t) uvmexp.active * uvmexp.pagesize; dst->inactive = (uint64_t) uvmexp.inactive * uvmexp.pagesize; dst->swap_total = (uint64_t) uvmexp.swpages * uvmexp.pagesize; dst->swap_free = (uint64_t) (uvmexp.swpages - uvmexp.swpginuse) * uvmexp.pagesize; dst->wired = (uint64_t) uvmexp.wired * uvmexp.pagesize; dst->executable = (uint64_t) uvmexp.execpages * uvmexp.pagesize; dst->files = (uint64_t) uvmexp.filepages * uvmexp.pagesize; return 0; } libsysactivity-0.6.5/src/NetBSD/libsysactivity.h0000644000175000017500000000653412220245547020710 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef LIBSYSACTIVITY_H_ #define LIBSYSACTIVITY_H_ #include #include #include #include #ifdef __cplusplus extern "C" { #endif #define SA_OPEN_CPU #undef SA_CLOSE_CPU #undef SA_SMP_CAPABLE #define SA_CPU_ID #define SA_CPU_USER #define SA_CPU_NICE #define SA_CPU_SYSTEM #define SA_CPU_IDLE #undef SA_CPU_WAITING_FOR_IO #undef SA_CPU_HARDWARE_IRQ #undef SA_CPU_SOFTWARE_IRQ #undef SA_CPU_STOLEN #define SA_CPU_INTR #define SA_OPEN_DISK #undef SA_CLOSE_DISK #define SA_DISK_NAME IOSTATNAMELEN #define SA_DISK_READS #undef SA_DISK_READS_MERGED #undef SA_DISK_SECTORS_READ #undef SA_DISK_TIME_SPENT_READING #define SA_DISK_WRITES #undef SA_DISK_SECTORS_WRITTEN #undef SA_DISK_TIME_SPENT_WRITING #define SA_DISK_BYTES_READ #define SA_DISK_BYTES_WRITTEN #undef SA_OPEN_MEMORY #undef SA_CLOSE_MEMORY #define SA_MEMORY_TOTAL #define SA_MEMORY_FREE #define SA_MEMORY_ACTIVE #define SA_MEMORY_INACTIVE #undef SA_MEMORY_BUFFERS #define SA_MEMORY_SWAP_TOTAL #define SA_MEMORY_SWAP_FREE #undef SA_MEMORY_SWAP_CACHED #define SA_MEMORY_WIRED #undef SA_MEMORY_CACHED #undef SA_MEMORY_DIRTY #define SA_MEMORY_EXECUTABLE #define SA_MEMORY_FILES #undef SA_MEMORY_LOCKED #define SA_OPEN_NET #undef SA_CLOSE_NET #define SA_NET_INTERFACE_NAME 12 // net/if_dl.h:76 #define SA_NET_INTERFACE_RECEIVED_BYTES #define SA_NET_INTERFACE_RECEIVED_PACKETS #define SA_NET_INTERFACE_RECEIVED_ERRORS #define SA_NET_INTERFACE_RECEIVED_DROP #undef SA_NET_INTERFACE_RECEIVED_FIFO #define SA_NET_INTERFACE_RECEIVED_MULTICAST #define SA_NET_INTERFACE_SENT_BYTES #define SA_NET_INTERFACE_SENT_PACKETS #define SA_NET_INTERFACE_SENT_ERRORS #undef SA_NET_INTERFACE_SENT_DROP #undef SA_NET_INTERFACE_SENT_FIFO #undef SA_NET_INTERFACE_SENT_COMPRESSED #define SA_NET_INTERFACE_SENT_MULTICAST #define SA_OPEN_PROCESS #undef SA_CLOSE_PROCESS #define SA_PROCESS_PID #define SA_PROCESS_UID #define SA_PROCESS_GID #define SA_PROCESS_FILENAME KI_MAXCOMLEN #undef SA_PROCESS_CMDLINE #define SA_PROCESS_PARENT_PID #define SA_PROCESS_PGRP #define SA_PROCESS_SID #define SA_PROCESS_TTY #define SA_PROCESS_NICE #define SA_PROCESS_START_TIME #undef SA_PROCESS_STATE #define SA_PROCESS_USER_TIME #define SA_PROCESS_SYS_TIME #undef SA_PROCESS_THREADS #define SA_PROCESS_VM_SIZE #define SA_PROCESS_RSS #define SA_OPEN_SWAP #undef SA_CLOSE_SWAP #define SA_SWAP_NAME PATH_MAX+1 #define SA_SWAP_TOTAL #define SA_SWAP_FREE #undef SA_SWAP_TYPE #include "global.h" #ifdef __cplusplus } #endif #endif /* LIBSYSACTIVITY_H_ */ libsysactivity-0.6.5/src/NetBSD/disk.c0000644000175000017500000001032212220245547016541 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include "../OpenBSD/utils.h" pthread_key_t buffer_key; pthread_key_t buffer_size_key; pthread_key_t number_disks_key; int mib[] = { CTL_HW, HW_IOSTATS, sizeof(struct io_sysctl) }; static void create_keys(); int sa_open_disk() { pthread_once_t key_once = PTHREAD_ONCE_INIT; if (pthread_once(&key_once, create_keys)) return ENOSYS; return 0; } int sa_count_disks(uint16_t* number) { if (number == NULL) return EINVAL; size_t size; if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) return ENOSYS; *number = size / sizeof(struct io_sysctl); return 0; } int sa_reset_disks() { size_t size; struct io_sysctl* buffer = pthread_getspecific(buffer_key); size_t buffer_size = (size_t) pthread_getspecific(buffer_size_key); do { if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) return ENOSYS; if (buffer_size < size) { safe_realloc((void*) &buffer, &size); if (pthread_setspecific(buffer_key, buffer)) return ENOSYS; buffer_size = size; if (pthread_setspecific(buffer_size_key, (void *) buffer_size)) return ENOSYS; if (buffer == NULL) return ENOMEM; } errno = 0; if (sysctl(mib, 3, buffer, &size, NULL, 0) < 0 && errno != ENOMEM) return ENOSYS; } while (errno == ENOMEM); if (pthread_setspecific(number_disks_key, (void *) (size / sizeof(struct io_sysctl)))) return ENOSYS; return 0; } int sa_get_disks_ids(char* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; struct io_sysctl* buffer = pthread_getspecific(buffer_key); size_t number_disks = (size_t) pthread_getspecific(number_disks_key); *written = 0; size_t i; for (i = 0; i < dst_size; ++i) { if (i == number_disks) return ENOMEM; strlcpy(&dst[i * SA_DISK_NAME], buffer[i].name, IOSTATNAMELEN); ++(*written); } return 0; } int sa_get_disk(char* name, struct sa_disk* dst) { if (name == NULL || dst == NULL) return EINVAL; struct io_sysctl* buffer = pthread_getspecific(buffer_key); size_t number_disks = (size_t) pthread_getspecific(number_disks_key); size_t i; for (i = 0; i < number_disks; ++i) { if (strncmp(buffer[i].name, name, IOSTATNAMELEN) != 0) continue; strlcpy(dst->name, buffer[i].name, IOSTATNAMELEN); dst->reads = buffer[i].rxfer; dst->writes = buffer[i].wxfer; dst->bytes_read = buffer[i].rbytes; dst->bytes_written = buffer[i].wbytes; return 0; } return ENODEV; } int sa_get_disks(struct sa_disk* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; struct io_sysctl* buffer = pthread_getspecific(buffer_key); size_t number_disks = (size_t) pthread_getspecific(number_disks_key); *written = 0; size_t i; for (i = 0; i < dst_size; ++i) { if (i == number_disks) return ENOMEM; strlcpy(dst[i].name, buffer[i].name, IOSTATNAMELEN); dst[i].reads = buffer[i].rxfer; dst[i].writes = buffer[i].wxfer; dst[i].bytes_read = buffer[i].rbytes; dst[i].bytes_written = buffer[i].wbytes; ++(*written); } return 0; } static void create_keys() { static short keys_created = 0; if (keys_created) { return; } pthread_key_create(&buffer_key, free_keys); pthread_key_create(&buffer_size_key, NULL); pthread_key_create(&number_disks_key, NULL); keys_created = 1; } libsysactivity-0.6.5/src/NetBSD/cpu.c0000644000175000017500000001235312220245547016404 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include /* CPUSTATES */ #include #include #include #include "../OpenBSD/utils.h" static void create_keys(); static void calculate_cpu(struct sa_cpu* dst) SA_NONNULL; static inline void percentages(u_int64_t *new, u_int64_t *old) SA_NONNULL; pthread_key_t cp_time_key; pthread_key_t cp_old_key; int sa_open_cpu() { pthread_once_t key_once = PTHREAD_ONCE_INIT; if (pthread_once(&key_once, create_keys)) return ENOSYS; u_int64_t * cp_time = malloc(CPUSTATES * sizeof (u_int64_t)); if (cp_time == NULL) return ENOMEM; if (pthread_setspecific(cp_time_key, cp_time)) return ENOSYS; u_int64_t * cp_old = malloc(CPUSTATES * sizeof (u_int64_t)); if (cp_old == NULL) return ENOMEM; if (pthread_setspecific(cp_old_key, cp_old)) return ENOSYS; return 0; } int sa_reset_cpus() { u_int64_t* cp_time = pthread_getspecific(cp_time_key); int cp_time_mib[] = { CTL_KERN, KERN_CP_TIME }; size_t size = CPUSTATES * sizeof (u_int64_t); if (sysctl(cp_time_mib, 2, cp_time, &size, NULL, 0) == -1) return ENOSYS; return 0; } int sa_get_cpu(uint16_t index, struct sa_cpu* dst) { if (index > 0 || dst == NULL) return EINVAL; calculate_cpu(dst); return 0; } int sa_count_cpus(uint16_t* number) { if (number == NULL) return EINVAL; *number = 1; return 0; } int sa_get_cpus(struct sa_cpu* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 1; calculate_cpu(dst); return 0; } static void create_keys() { static short keys_created = 0; if (keys_created) { return; } pthread_key_create(&cp_time_key, free_keys); pthread_key_create(&cp_old_key, free_keys); keys_created = 1; } static void calculate_cpu(struct sa_cpu* dst) { u_int64_t* cp_time = pthread_getspecific(cp_time_key); u_int64_t* cp_old = pthread_getspecific(cp_old_key); percentages(cp_time, cp_old); dst->id = 0; dst->user = cp_time[CP_USER] / 10; dst->nice = cp_time[CP_NICE] / 10; dst->system = cp_time[CP_SYS] / 10; dst->idle = cp_time[CP_IDLE] / 10; dst->intr = cp_time[CP_INTR] / 10; } /* * This function is taken from unixtop 3.8beta1 at http://www.unixtop.org/download/ * * Copyright (c) 1984 through 2008, William LeFebvre * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * * Neither the name of William LeFebvre nor the names of other * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ static inline void percentages(u_int64_t *new, u_int64_t *old) { register int i; u_int64_t total_change; u_int64_t half_total; u_int64_t cp_diff[CPUSTATES]; total_change = 0; /* calculate changes for each state and the overall change */ for (i = 0; i < CPUSTATES; ++i) { total_change += (cp_diff[i] = new[i] - old[i]); old[i] = new[i]; } /* avoid divide by zero potential */ if (total_change == 0) total_change = 1; /* calculate percentages based on overall change, rounding up */ half_total = total_change / 2l; for (i = 0; i < CPUSTATES; ++i) new[i] = (cp_diff[i] * 1000 + half_total) / total_change; } libsysactivity-0.6.5/src/NetBSD/CMakeLists.txt0000644000175000017500000000122512220245547020205 0ustar hazelhazel list(APPEND SPECIFIC_HDRS libsysactivity.h) INSTALL(FILES ${SPECIFIC_HDRS} DESTINATION ${HEADERS_INSTALLATION_DIR}) FILE(GLOB LIBSA_SPECIFIC_SRCS *.c) list(APPEND LIBSA_SPECIFIC_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../OpenBSD/network.c) list(APPEND LIBSA_SPECIFIC_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../OpenBSD/swap.c) list(APPEND LIBSA_SPECIFIC_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../OpenBSD/utils.c) ADD_LIBRARY(sysactivity SHARED ${LIBSA_SPECIFIC_SRCS}) set_target_properties(sysactivity PROPERTIES VERSION ${LIBSA_VERSION} SOVERSION ${LIBSA_ABI_VERSION}) TARGET_LINK_LIBRARIES(sysactivity) INSTALL(TARGETS sysactivity LIBRARY DESTINATION ${LIB_INSTALLATION_DIR}) libsysactivity-0.6.5/src/Linux/0000755000175000017500000000000012220245547015465 5ustar hazelhazellibsysactivity-0.6.5/src/Linux/utils.h0000644000175000017500000000223712220245547017002 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2010-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef UTILS_H_ #define UTILS_H_ int kernel_version; char* skip_values(char* pos, int number) SA_NONNULL; char* skip_value(char* pos) SA_NONNULL SA_HOT; SA_INLINE void strlcpy(char* __restrict__ dest, const char* __restrict__ src, const size_t n) SA_NONNULL; #endif /* UTILS_H_ */ libsysactivity-0.6.5/src/Linux/utils.c0000644000175000017500000000340712220245547016775 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2010-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include "utils.h" static void __attribute__ ((constructor)) set_kernel_version(void) { struct utsname uts; if (uname(&uts) != 0) { kernel_version = -1; return; } if (strncmp(uts.release, "3.", sizeof "3." - 1) == 0) kernel_version = atoi(uts.release + sizeof "3." - 1) + 40; else if (strncmp(uts.release, "2.6.", sizeof "2.6." - 1) == 0) kernel_version = atoi(uts.release + sizeof "2.6." - 1); else kernel_version = -1; } char* skip_values(char* pos, int number) { while (number--) pos = skip_value(pos); return pos; } char* skip_value(char* pos) { while (isgraph(*pos)) ++pos; while (isblank(*pos)) ++pos; return pos; } SA_INLINE void strlcpy(char* __restrict__ dest, const char* __restrict__ src, const size_t n) { strncpy(dest, src, n); if (strlen(src) >= n) dest[n] = '\0'; } libsysactivity-0.6.5/src/Linux/swap.c0000644000175000017500000000633612220245547016613 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include "utils.h" static void parse_swap(struct sa_swap* __restrict__ dst, char* pos) SA_NONNULL; extern int kernel_version; __thread FILE* file_swaps; __thread long swap_useful_pos; __thread char s_line_buffer[512]; int sa_open_swap() { file_swaps = NULL; if (kernel_version < 11) return ENOTSUP; file_swaps = fopen("/proc/swaps", "r"); if (file_swaps == NULL) return EIO; if (fgets(s_line_buffer, sizeof(s_line_buffer), file_swaps) == NULL) return ENOTSUP; swap_useful_pos = ftell(file_swaps); if (swap_useful_pos == -1) return ENOTSUP; return 0; } int sa_close_swap() { if (file_swaps != NULL) fclose(file_swaps); return 0; } int sa_count_swaps(uint16_t* number) { if (number == NULL) return EINVAL; if (sa_reset_swaps() != 0) return EIO; *number = 0; while (fgets(s_line_buffer, sizeof(s_line_buffer), file_swaps) != NULL) ++(*number); return 0; } int sa_reset_swaps() { fclose(file_swaps); file_swaps = fopen("/proc/swaps", "r"); if (file_swaps == NULL) return EIO; fseek(file_swaps, swap_useful_pos, SEEK_SET); return 0; } int sa_get_swap(uint16_t index, struct sa_swap* dst) { if (dst == NULL) return EINVAL; int i; for (i = 0; fgets(s_line_buffer, sizeof(s_line_buffer), file_swaps) != NULL; ++i) { if (i != index) continue; errno = 0; parse_swap(dst, s_line_buffer); if (errno != 0) return ENOSYS; return 0; } return ENODEV; } int sa_get_swaps(struct sa_swap* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 0; int i; for (i = 0; fgets(s_line_buffer, sizeof s_line_buffer, file_swaps) != NULL; ++i) { if (i >= dst_size) return ENOMEM; errno = 0; parse_swap(&dst[i], s_line_buffer); if (errno != 0) return ENOSYS; ++(*written); } return 0; } static void parse_swap(struct sa_swap* __restrict__ dst, char* pos) { size_t end = strchr(pos, ' ') - pos; if (sizeof(dst->name) - 1 < end) end = sizeof(dst->name) - 1; strlcpy(dst->name, pos, end); pos = skip_value(pos); dst->type = strncmp(pos, "file", 4) == 0 ? 2 : 1; pos = skip_value(pos); dst->total = strtoull(pos, NULL, 10) * 1024; pos = skip_value(pos); dst->free = dst->total - strtoull(pos, NULL, 10) * 1024; } libsysactivity-0.6.5/src/Linux/process.c0000644000175000017500000001363712220245547017321 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include "utils.h" static inline int parse_stats(struct sa_process* dst, const pid_t pid) SA_HOT SA_NONNULL; static int parse_activity(struct sa_process_activity* dst, const pid_t pid) SA_HOT SA_NONNULL; extern int kernel_version; __thread DIR* dir_proc; __thread char path[32]; int sa_open_process() { dir_proc = NULL; if (kernel_version < 25) return ENOTSUP; dir_proc = opendir("/proc/"); if (dir_proc == NULL) return EIO; strcpy(path, "/proc/"); return 0; } int sa_close_process() { if (dir_proc != NULL) closedir(dir_proc); return 0; } int sa_count_processes(uint32_t* number) { if (number == NULL) return EINVAL; struct sysinfo info; if (sysinfo(&info) == -1) return errno; *number = (pid_t) info.procs; return 0; } int sa_get_processes_ids(pid_t* dst, uint32_t dst_size, uint32_t* written) { if (dst == NULL || dst_size <= 0 || written == NULL) return EINVAL; rewinddir(dir_proc); *written = 0; struct dirent* entry; pid_t pid; while ((entry = readdir(dir_proc)) != NULL) { if (entry->d_type != DT_DIR || (pid = atoi(entry->d_name)) == 0) continue; if (*written == dst_size) return ENOMEM; dst[*written] = pid; ++(*written); } return 0; } int sa_get_process(pid_t pid, struct sa_process* dst) { if (pid == 0 || dst == NULL) return EINVAL; sprintf(&path[6], "%d", pid); return parse_stats(dst, pid); } int sa_get_process_activity(pid_t pid, struct sa_process_activity* dst) { if (pid == 0 || dst == NULL) return EINVAL; sprintf(&path[6], "%d", pid); return parse_activity(dst, pid); } static inline int parse_stats(struct sa_process* dst, const pid_t pid) { char line_buffer[256]; int aux = strlen(path); strcpy(&path[aux], "/stat"); FILE* file = fopen(path, "r"); if (file == NULL) return ESRCH; if (fgets(line_buffer, sizeof line_buffer, file) == NULL) { fclose(file); return EIO; } dst->activity.pid = dst->pid = pid; char* pos = skip_values(line_buffer, 2); switch (*pos) { case 'S': dst->activity.state = SA_SLEEPING; break; case 'D': dst->activity.state = SA_SLEEPING_UNINTERRUPTIBLE; break; case 'Z': dst->activity.state = SA_ZOMBIE; break; case 'T': dst->activity.state = SA_STOPPED; break; default: dst->activity.state = SA_RUNNING; } pos = skip_value(pos); dst->parent_pid = atoi(pos); pos = skip_value(pos); dst->pgrp = atoi(pos); pos = skip_value(pos); dst->sid = atoi(pos); pos = skip_value(pos); dst->tty = atoi(pos); pos = skip_values(pos, 7); dst->activity.user_time = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->activity.sys_time = strtoull(pos, NULL, 10); pos = skip_values(pos, 4); dst->nice = atoi(pos); pos = skip_value(pos); dst->activity.threads = atoi(pos); pos = skip_values(pos, 2); dst->start_time = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->activity.vm_size = strtoul(pos, NULL, 10); pos = skip_value(pos); dst->activity.rss = strtoul(pos, NULL, 10); fclose(file); strcpy(&path[aux], "/cmdline"); file = fopen(path, "r"); if (file == NULL) return ESRCH; if (fgets(dst->cmdline, sizeof dst->cmdline, file) == NULL) // sometimes this file is empty dst->cmdline[0] = '\0'; fclose(file); strcpy(&path[aux], "/status"); file = fopen(path, "r"); if (file == NULL) return ESRCH; dst->uid = dst->gid = 0; dst->filename[0] = '\0'; aux = 0; // for better performance while (fgets(line_buffer, sizeof line_buffer, file) != NULL) { if (aux < 1 && !strncmp(line_buffer, "Name:", sizeof("Name:") - 1)) { pos = skip_value(line_buffer); strlcpy(dst->filename, pos, sizeof(dst->filename) - 1); dst->filename[strlen(dst->filename) - 1] = '\0'; ++aux; continue; } if (aux < 2 && !strncmp(line_buffer, "Uid:", sizeof("Uid:") - 1)) { pos = skip_value(line_buffer); dst->uid = atoi(pos); ++aux; continue; } if (aux < 3 && !strncmp(line_buffer, "Gid:", sizeof("Gid:") - 1)) { pos = skip_value(line_buffer); dst->gid = atoi(pos); break; } } fclose(file); return 0; } static int parse_activity(struct sa_process_activity* dst, const pid_t pid) { char line_buffer[256]; int aux = strlen(path); strcpy(&path[aux], "/stat"); FILE* file = fopen(path, "r"); if (file == NULL) return ESRCH; if (fgets(line_buffer, sizeof line_buffer, file) == NULL) { fclose(file); return EIO; } dst->pid = pid; char* pos = skip_values(line_buffer, 2); switch (*pos) { case 'S': dst->state = SA_SLEEPING; break; case 'D': dst->state = SA_SLEEPING_UNINTERRUPTIBLE; break; case 'Z': dst->state = SA_ZOMBIE; break; case 'T': dst->state = SA_STOPPED; break; default: dst->state = SA_RUNNING; } pos = skip_values(pos, 11); dst->user_time = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->sys_time = strtoull(pos, NULL, 10); pos = skip_values(pos, 5); dst->threads = atoi(pos); pos = skip_values(pos, 3); dst->vm_size = strtoul(pos, NULL, 10); pos = skip_value(pos); dst->rss = strtoul(pos, NULL, 10); fclose(file); return 0; } libsysactivity-0.6.5/src/Linux/network.c0000644000175000017500000001136312220245547017326 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include "utils.h" static int parse_interface(struct sa_net_interface* __restrict__ dst, const char* __restrict__ name); extern int kernel_version; __thread FILE* file_net_dev; __thread char line_buffer[256]; __thread long pos_useful_data; int sa_open_net() { file_net_dev = NULL; if (kernel_version < 11) return ENOTSUP; file_net_dev = fopen("/proc/net/dev", "r"); if (file_net_dev == NULL) return EIO; int i; for (i = 0; i < 2; ++i) { if (fgets(line_buffer, sizeof line_buffer, file_net_dev) == NULL) return ENOTSUP; } pos_useful_data = ftell(file_net_dev); if (pos_useful_data == -1) return ENOTSUP; return 0; } int sa_close_net() { if (file_net_dev != NULL) fclose(file_net_dev); return 0; } int sa_count_net_interfaces(uint16_t* number) { if (number == NULL) return EINVAL; if (sa_reset_net_interfaces()) return EIO; *number = 0; while (fgets(line_buffer, sizeof line_buffer, file_net_dev)) ++(*number); return 0; } int sa_reset_net_interfaces() { fclose(file_net_dev); file_net_dev = fopen("/proc/net/dev", "r"); if (file_net_dev == NULL) return EIO; if (fseek(file_net_dev, pos_useful_data, SEEK_SET) != 0) return ENOSYS; return 0; } int sa_get_net_interfaces_ids(char* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 0; int i; char* pos; for (i = 0; fgets(line_buffer, sizeof line_buffer, file_net_dev); ++i) { if (i == dst_size) return ENOMEM; pos = line_buffer; while (*pos == ' ') pos++; *strrchr(line_buffer, ':') = '\0'; strcpy(&dst[i * SA_NET_INTERFACE_NAME], pos); ++(*written); } return 0; } int sa_get_net_interface(char* name, struct sa_net_interface* dst) { if (name == NULL || dst == NULL) return EINVAL; fseek(file_net_dev, pos_useful_data, SEEK_SET); while (fgets(line_buffer, sizeof line_buffer, file_net_dev)) { errno = 0; if (!parse_interface(dst, name)) continue; if (errno != 0) return ENOSYS; return 0; } return ENODEV; } int sa_get_net_interfaces(struct sa_net_interface* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 0; int i; for (i = 0; fgets(line_buffer, sizeof line_buffer, file_net_dev); ++i) { if (i == dst_size) return ENOMEM; errno = 0; parse_interface(&dst[i], NULL); if (errno != 0) return ENOSYS; ++(*written); } return 0; } static int parse_interface(struct sa_net_interface* __restrict__ dst, const char* __restrict__ name) { char* pos; char* end; end = strrchr(line_buffer, ':'); *end = ' '; pos = line_buffer; while (*pos == ' ') ++pos; if (name != NULL) if (strncmp(pos, name, (int) sizeof(dst->name) < end - pos ? (int) sizeof(dst->name) : end - pos) != 0) return 0; size_t length = strchr(pos, ' ') - pos; if (sizeof(dst->name) - 1 < length) length = sizeof(dst->name) - 1; strlcpy(dst->name, pos, length); pos = skip_value(pos); dst->received_bytes = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->received_packets = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->received_errors = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->received_drop = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->received_fifo = strtoull(pos, NULL, 10); pos = skip_values(pos, 2); dst->received_compressed = strtoull(pos, NULL, 10); pos = skip_values(pos, 2); dst->sent_bytes = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->sent_packets = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->sent_errors = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->sent_drop = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->sent_fifo = strtoull(pos, NULL, 10); pos = skip_values(pos, 3); dst->sent_compressed = strtoull(pos, NULL, 10); return 1; } libsysactivity-0.6.5/src/Linux/memory.c0000644000175000017500000000674312220245547017153 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include "utils.h" static void get_value(char* __restrict__ pos, uint64_t* __restrict__ value) SA_NONNULL; extern int kernel_version; __thread FILE* file_meminfo; __thread char m_line_buffer[512]; int sa_open_memory() { file_meminfo = NULL; if (kernel_version < 11) return ENOTSUP; return 0; } int sa_close_memory() { if (file_meminfo != NULL) fclose(file_meminfo); return 0; } int sa_get_memory(struct sa_memory* dst) { if (dst == NULL) return EINVAL; if (file_meminfo != NULL) fclose(file_meminfo); file_meminfo = fopen("/proc/meminfo", "r"); if (file_meminfo == NULL) return EIO; int aux = 0; // for better performance while (fgets(m_line_buffer, sizeof(m_line_buffer), file_meminfo) != NULL) { if (aux < 1 && strncmp(m_line_buffer, "MemTotal:", sizeof("MemTotal:") - 1) == 0) get_value(&m_line_buffer[sizeof("MemTotal:") - 1], &dst->total); else if (aux < 2 && strncmp(m_line_buffer, "MemFree:", sizeof("MemFree:") - 1) == 0) get_value(&m_line_buffer[sizeof("MemFree:") - 1], &dst->free); else if (aux < 3 && strncmp(m_line_buffer, "Buffers:", sizeof("Buffers:") - 1) == 0) get_value(&m_line_buffer[sizeof("Buffers:") - 1], &dst->buffers); else if (aux < 4 && strncmp(m_line_buffer, "Cached:", sizeof("Cached:") - 1) == 0) get_value(&m_line_buffer[sizeof("Cached:") - 1], &dst->cached); else if (aux < 5 && strncmp(m_line_buffer, "SwapCached:", sizeof("SwapCached:") - 1) == 0) get_value(&m_line_buffer[sizeof("SwapCached:") - 1], &dst->swap_cached); else if (aux < 6 && strncmp(m_line_buffer, "Active:", sizeof("Active:") - 1) == 0) get_value(&m_line_buffer[sizeof("Active:") - 1], &dst->active); else if (aux < 7 && strncmp(m_line_buffer, "Inactive:", sizeof("Inactive:") - 1) == 0) get_value(&m_line_buffer[sizeof("Inactive:") - 1], &dst->inactive); else if (aux < 8 && strncmp(m_line_buffer, "SwapTotal:", sizeof("SwapTotal:") - 1) == 0) get_value(&m_line_buffer[sizeof("SwapTotal:") - 1], &dst->swap_total); else if (aux < 9 && strncmp(m_line_buffer, "SwapFree:", sizeof("SwapFree:") - 1) == 0) get_value(&m_line_buffer[sizeof("SwapFree:") - 1], &dst->swap_free); else if (aux < 10 && strncmp(m_line_buffer, "Dirty:", sizeof("Dirty:") - 1) == 0) { get_value(&m_line_buffer[sizeof("Dirty:") - 1], &dst->dirty); break; } else continue; ++aux; } return 0; } static void get_value(char* __restrict__ pos, uint64_t* __restrict__ value) { while (isblank(*pos)) ++pos; *value = strtoull(pos, NULL, 10); *value *= 1024; } libsysactivity-0.6.5/src/Linux/libsysactivity.h0000644000175000017500000000674612220245547020735 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef LIBSYSACTIVITY_H_ #define LIBSYSACTIVITY_H_ #include #include #include #ifdef __cplusplus extern "C" { #endif #define SA_OPEN_CPU #define SA_CLOSE_CPU #define SA_SMP_CAPABLE #define SA_CPU_ID #define SA_CPU_USER #define SA_CPU_NICE #define SA_CPU_SYSTEM #define SA_CPU_IDLE #define SA_CPU_WAITING_FOR_IO #define SA_CPU_HARDWARE_IRQ #define SA_CPU_SOFTWARE_IRQ #define SA_CPU_STOLEN #undef SA_CPU_INTR #define SA_OPEN_DISK #define SA_CLOSE_DISK #define SA_DISK_NAME DM_NAME_LEN #define SA_DISK_READS #define SA_DISK_READS_MERGED #define SA_DISK_SECTORS_READ #define SA_DISK_TIME_SPENT_READING #define SA_DISK_WRITES #define SA_DISK_SECTORS_WRITTEN #define SA_DISK_TIME_SPENT_WRITING #undef SA_DISK_BYTES_READ #undef SA_DISK_BYTES_WRITTEN #define SA_OPEN_MEMORY #define SA_CLOSE_MEMORY #define SA_MEMORY_TOTAL #define SA_MEMORY_FREE #define SA_MEMORY_ACTIVE #define SA_MEMORY_INACTIVE #define SA_MEMORY_BUFFERS #define SA_MEMORY_SWAP_TOTAL #define SA_MEMORY_SWAP_FREE #define SA_MEMORY_SWAP_CACHED #undef SA_MEMORY_WIRED #define SA_MEMORY_CACHED #define SA_MEMORY_DIRTY #undef SA_MEMORY_EXECUTABLE #undef SA_MEMORY_FILES #undef SA_MEMORY_LOCKED #define SA_OPEN_NET #define SA_CLOSE_NET #define SA_NET_INTERFACE_NAME 64 #define SA_NET_INTERFACE_RECEIVED_BYTES #define SA_NET_INTERFACE_RECEIVED_PACKETS #define SA_NET_INTERFACE_RECEIVED_ERRORS #define SA_NET_INTERFACE_RECEIVED_DROP #define SA_NET_INTERFACE_RECEIVED_FIFO #define SA_NET_INTERFACE_RECEIVED_COMPRESSED #undef SA_NET_INTERFACE_RECEIVED_MULTICAST #define SA_NET_INTERFACE_SENT_BYTES #define SA_NET_INTERFACE_SENT_PACKETS #define SA_NET_INTERFACE_SENT_ERRORS #define SA_NET_INTERFACE_SENT_DROP #define SA_NET_INTERFACE_SENT_FIFO #define SA_NET_INTERFACE_SENT_COMPRESSED #undef SA_NET_INTERFACE_SENT_MULTICAST #define SA_OPEN_PROCESS #define SA_CLOSE_PROCESS #define SA_PROCESS_PID #define SA_PROCESS_UID #define SA_PROCESS_GID #define SA_PROCESS_FILENAME 1024 // Don't use FILENAME_MAX as the size of an array in which to store a file name! You can't possibly make an array that big! #define SA_PROCESS_CMDLINE 384 #define SA_PROCESS_PARENT_PID #define SA_PROCESS_PGRP #define SA_PROCESS_SID #define SA_PROCESS_TTY #define SA_PROCESS_NICE #define SA_PROCESS_START_TIME #define SA_PROCESS_STATE #define SA_PROCESS_USER_TIME #define SA_PROCESS_SYS_TIME #define SA_PROCESS_THREADS #define SA_PROCESS_VM_SIZE #define SA_PROCESS_RSS #define SA_OPEN_SWAP #define SA_CLOSE_SWAP #define SA_SWAP_NAME 1024 #define SA_SWAP_TOTAL #define SA_SWAP_FREE #define SA_SWAP_TYPE #include "global.h" #ifdef __cplusplus } #endif #endif /* LIBSYSACTIVITY_H_ */ libsysactivity-0.6.5/src/Linux/disk.c0000644000175000017500000001203412220245547016563 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include "utils.h" static int iterate_devices(struct sa_disk* __restrict__ dst, const uint16_t dst_size, uint16_t* __restrict__ count); static int is_a_real_device(const char* dev_name, const size_t name_len) SA_NONNULL; static int read_stat_file(struct sa_disk* __restrict__ dst, const char* __restrict__ dev_name, const size_t name_len) SA_NONNULL; extern int kernel_version; __thread DIR* dir_sys_block; int sa_open_disk() { dir_sys_block = NULL; if (kernel_version < 0) return ENOTSUP; dir_sys_block = opendir("/sys/block/"); if (dir_sys_block == NULL) return EIO; return 0; } int sa_close_disk() { if (dir_sys_block != NULL) closedir(dir_sys_block); return 0; } int sa_count_disks(uint16_t* number) { if (number == NULL) return EINVAL; rewinddir(dir_sys_block); if (iterate_devices(NULL, 0, number) != 0) return EIO; return 0; } int sa_reset_disks() { rewinddir(dir_sys_block); return 0; } int sa_get_disks_ids(char* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 0; struct dirent* device_folder; size_t name_len; while ((device_folder = readdir(dir_sys_block)) != NULL) { name_len = strlen(device_folder->d_name); if (!is_a_real_device(device_folder->d_name, name_len)) continue; if (*written == dst_size) return ENOMEM; strncpy(&dst[*written * SA_DISK_NAME], device_folder->d_name, SA_DISK_NAME); ++(*written); } return 0; } int sa_get_disk(char* name, struct sa_disk* dst) { if (name == NULL || dst == NULL) return EINVAL; size_t name_len = strlen(name); if (!is_a_real_device(name, name_len)) return ENODEV; return read_stat_file(dst, name, name_len); } int sa_get_disks(struct sa_disk* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; return iterate_devices(dst, dst_size, written); } static int iterate_devices(struct sa_disk* __restrict__ dst, const uint16_t dst_size, uint16_t* __restrict__ count) { struct dirent* device_folder; size_t name_len; *count = 0; while ((device_folder = readdir(dir_sys_block)) != NULL) { name_len = strlen(device_folder->d_name); if (!is_a_real_device(device_folder->d_name, name_len)) continue; if (dst != NULL) { if (*count == dst_size) return ENOMEM; if (read_stat_file(&dst[*count], device_folder->d_name, name_len) != 0) return EIO; } ++(*count); } return 0; } static int is_a_real_device(const char* dev_name, const size_t name_len) { char line_buffer[64]; DIR* tmp_dir; if (name_len > sizeof line_buffer - sizeof("/sys/block//device/") - 1) return EIO; strcpy(line_buffer, "/sys/block/"); strcat(line_buffer, dev_name); strcat(line_buffer, "/device/"); tmp_dir = opendir(line_buffer); if (tmp_dir == NULL) return 0; closedir(tmp_dir); return 1; } static int read_stat_file(struct sa_disk* __restrict__ dst, const char* __restrict__ dev_name, const size_t name_len) { char line_buffer[192]; FILE* file_stat; if (name_len > sizeof line_buffer - sizeof("/sys/block//stat") - 1) return EIO; strcpy(line_buffer, "/sys/block/"); strcat(line_buffer, dev_name); strcat(line_buffer, "/stat"); file_stat = fopen(line_buffer, "r"); if (file_stat == NULL) return EIO; if (fgets(line_buffer, sizeof line_buffer, file_stat) == NULL) { fclose(file_stat); return EIO; } char* pos = line_buffer; errno = 0; while (isblank(*pos)) ++pos; dst->reads = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->reads_merged = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->sectors_read = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->time_spent_reading = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->writes = strtoull(pos, NULL, 10); pos = skip_values(pos, 2); dst->sectors_written = strtoull(pos, NULL, 10); pos = skip_value(pos); dst->time_spent_writing = strtoull(pos, NULL, 10); if (errno != 0) { fclose(file_stat); return EIO; } strlcpy(dst->name, dev_name, sizeof(dst->name) - 1); fclose(file_stat); return 0; } libsysactivity-0.6.5/src/Linux/cpu.c0000644000175000017500000001217712220245547016430 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * 2002 James C. Warner * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include "utils.h" typedef struct { uint64_t u, n, s, i, w, x, y, z; // as represented in /proc/stat } CPU_STATES_t; typedef struct CPU_t { CPU_STATES_t diff, saved; unsigned id; // the CPU ID number } CPU_t; static void parse_line(CPU_STATES_t* __restrict__ states, char* __restrict__ pos) SA_NONNULL; static void calculate_cpu(struct sa_cpu* __restrict__ dst, CPU_t* __restrict__ cpu, const CPU_STATES_t* __restrict__ new_states) SA_NONNULL; extern int kernel_version; __thread long int number_cpus; __thread FILE* fp; __thread CPU_t* cpus; __thread char buf[320]; int sa_open_cpu() { fp = NULL; cpus = NULL; if (kernel_version < 24) return ENOTSUP; number_cpus = sysconf(_SC_NPROCESSORS_ONLN); if (number_cpus < 0) return ENOSYS; fp = fopen("/proc/stat", "r"); if (fp == NULL) return EIO; return 0; } int sa_close_cpu() { if (fp != NULL) fclose(fp); if (cpus != NULL) free(cpus); return 0; } int sa_reset_cpus() { fclose(fp); fp = fopen("/proc/stat", "r"); if (fp == NULL) return EIO; if (fgets(buf, sizeof buf, fp) == NULL) return EIO; long int new_number_cpus = sysconf(_SC_NPROCESSORS_ONLN); if (new_number_cpus < 0) return ENOSYS; if (cpus == NULL || number_cpus != new_number_cpus) { number_cpus = new_number_cpus; CPU_t* temp_cpus; temp_cpus = realloc(cpus, number_cpus * sizeof(CPU_t)); if (temp_cpus == NULL) return ENOMEM; cpus = temp_cpus; } return 0; } int sa_count_cpus(uint16_t* number) { if (number == NULL) return EINVAL; *number = (uint16_t) number_cpus; return 0; } int sa_get_cpu(uint16_t index, struct sa_cpu* dst) { if (index >= number_cpus || dst == NULL) return EINVAL; uint16_t i; CPU_STATES_t new_states; for (i = 0; i < number_cpus; ++i) { if (fgets(buf, sizeof buf, fp) == NULL) return EIO; if (index != i) continue; cpus[i].id = i; errno = 0; parse_line(&new_states, buf); if (errno != 0) return ENODEV; calculate_cpu(dst, &cpus[i], &new_states); return 0; } return ENODEV; } int sa_get_cpus(struct sa_cpu* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 0; uint16_t i; CPU_STATES_t new_states; for (i = 0; i < number_cpus; ++i) { if (fgets(buf, sizeof buf, fp) == NULL) return EIO; if (i >= dst_size) return ENOMEM; cpus[i].id = i; errno = 0; parse_line(&new_states, buf); if (errno != 0) return ENODEV; calculate_cpu(&dst[i], &cpus[i], &new_states); ++(*written); } return 0; } static void parse_line(CPU_STATES_t* __restrict__ states, char* __restrict__ pos) { pos = skip_value(pos); states->u = strtoull(pos, NULL, 10); pos = skip_value(pos); states->n = strtoull(pos, NULL, 10); pos = skip_value(pos); states->s = strtoull(pos, NULL, 10); pos = skip_value(pos); states->i = strtoull(pos, NULL, 10); pos = skip_value(pos); states->w = strtoull(pos, NULL, 10); pos = skip_value(pos); states->x = strtoull(pos, NULL, 10); pos = skip_value(pos); states->y = strtoull(pos, NULL, 10); pos = skip_value(pos); states->z = strtoull(pos, NULL, 10); } static void calculate_cpu(struct sa_cpu* __restrict__ dst, CPU_t* __restrict__ cpu, const CPU_STATES_t* __restrict__ new_states) { cpu->diff.u = new_states->u - cpu->saved.u; cpu->diff.s = new_states->s - cpu->saved.s; cpu->diff.n = new_states->n - cpu->saved.n; cpu->diff.i = new_states->i - cpu->saved.i; cpu->diff.w = new_states->w - cpu->saved.w; cpu->diff.x = new_states->x - cpu->saved.x; cpu->diff.y = new_states->y - cpu->saved.y; cpu->diff.z = new_states->z - cpu->saved.z; uint64_t total = cpu->diff.u + cpu->diff.s + cpu->diff.n + cpu->diff.i + cpu->diff.w + cpu->diff.x + cpu->diff.y + cpu->diff.z; float scale; if (total == 0) scale = 1; else scale = (float) total / 100.0; dst->id = cpu->id; dst->user = cpu->diff.u / scale; dst->nice = cpu->diff.n / scale; dst->system = cpu->diff.s / scale; dst->idle = cpu->diff.i / scale; dst->waiting_for_io = cpu->diff.w / scale; dst->hardware_irq = cpu->diff.x / scale; dst->software_irq = cpu->diff.y / scale; dst->stolen = cpu->diff.z / scale; cpu->saved = *new_states; } libsysactivity-0.6.5/src/Linux/CMakeLists.txt0000644000175000017500000000064412220245547020231 0ustar hazelhazel list(APPEND SPECIFIC_HDRS libsysactivity.h) install(FILES ${SPECIFIC_HDRS} DESTINATION ${HEADERS_INSTALLATION_DIR}) file(GLOB LIBSA_SPECIFIC_SRCS *.c) ADD_LIBRARY(sysactivity SHARED ${LIBSA_SPECIFIC_SRCS}) set_target_properties(sysactivity PROPERTIES VERSION ${LIBSA_VERSION} SOVERSION ${LIBSA_ABI_VERSION}) TARGET_LINK_LIBRARIES(sysactivity) install(TARGETS sysactivity LIBRARY DESTINATION ${LIB_INSTALLATION_DIR}) libsysactivity-0.6.5/src/FreeBSD/0000755000175000017500000000000012220245547015600 5ustar hazelhazellibsysactivity-0.6.5/src/FreeBSD/utils.h0000644000175000017500000000215712220245547017116 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef UTILS_H_ #define UTILS_H_ long pagesize; int safe_realloc(void** ptr, size_t* size) SA_NONNULL; #if !defined(__FreeBSD__) SA_INLINE void strlcpy(char* dest, const char* src, const size_t n) SA_NONNULL; #endif #endif /* UTILS_H_ */ libsysactivity-0.6.5/src/FreeBSD/utils.c0000644000175000017500000000274512220245547017114 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2010-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include "utils.h" static void __attribute__ ((constructor)) get_pagesize(void) { pagesize = sysconf(_SC_PAGESIZE); } int safe_realloc(void** __restrict__ ptr, size_t* __restrict__ size) { void* tmp = realloc(*ptr, *size); if (tmp == NULL) { free(*ptr); *ptr = NULL; *size = 0; return ENOMEM; } *ptr = tmp; return 0; } #if !defined(__FreeBSD__) SA_INLINE void strlcpy(char* __restrict__ dest, const char* __restrict__ src, const size_t n) { strncpy(dest, src, n); if (strlen(src) >= n) dest[n] = '\0'; } #endif libsysactivity-0.6.5/src/FreeBSD/swap.c0000644000175000017500000000575412220245547016731 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include "utils.h" #define S_MIB_SIZE 3 static void assign(struct sa_swap* __restrict__ dst, struct xswdev* __restrict__ src) SA_NONNULL; extern long pagesize; __thread int s_mib[S_MIB_SIZE]; __thread struct xswdev* buffer_s; __thread size_t buffer_s_size; __thread uint16_t number_swaps; int sa_open_swap() { size_t m_mib_size = S_MIB_SIZE; if (sysctlnametomib("vm.swap_info", s_mib, &m_mib_size) == -1) return ENOSYS; return 0; } int sa_count_swaps(uint16_t* number) { if (number == NULL) return EINVAL; *number = 0; struct xswdev xsw; size_t size = sizeof xsw; for (s_mib[S_MIB_SIZE - 1] = 0; sysctl(s_mib, S_MIB_SIZE, &xsw, &size, NULL, 0) != -1; ++s_mib[S_MIB_SIZE - 1]) ++(*number); return 0; } int sa_reset_swaps() { size_t len = 0; size_t size = sizeof(struct xswdev); s_mib[S_MIB_SIZE - 1] = 0; number_swaps = 0; while (1) { len += sizeof(struct xswdev); if (len > buffer_s_size) { safe_realloc(&buffer_s, &len); buffer_s_size = len; if (buffer_s == NULL) return ENOMEM; } if (sysctl(s_mib, S_MIB_SIZE, &buffer_s[number_swaps], &size, NULL, 0) == -1) break; ++s_mib[S_MIB_SIZE - 1]; ++number_swaps; } return 0; } int sa_get_swap(uint16_t index, struct sa_swap* dst) { if (dst == NULL) return EINVAL; if (index >= number_swaps) return ENODEV; assign(dst, &buffer_s[index]); return 0; } int sa_get_swaps(struct sa_swap* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 0; uint16_t i; for (i = 0; i < number_swaps; ++i) { if (i == dst_size) return ENOMEM; assign(&dst[i], &buffer_s[i]); ++(*written); } return 0; } static void assign(struct sa_swap* __restrict__ dst, struct xswdev* __restrict__ src) { devname_r(src->xsw_dev, S_IFCHR, dst->name, SA_SWAP_NAME); dst->total = (uint64_t) src->xsw_nblks * pagesize; dst->free = (uint64_t) (src->xsw_nblks - src->xsw_used) * pagesize; } libsysactivity-0.6.5/src/FreeBSD/process.c0000644000175000017500000001130212220245547017417 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include "utils.h" static int refresh_processes(size_t* len) SA_HOT SA_NONNULL; static inline void assign(struct sa_process* __restrict__ dst, struct kinfo_proc* __restrict__ kinfo_proc) SA_NONNULL; static void assign_activity(struct sa_process_activity* __restrict__ dst, struct kinfo_proc* __restrict__ kinfo_proc) SA_NONNULL; extern long pagesize; int mib[3] = { CTL_KERN, KERN_PROC, KERN_PROC_PROC }; __thread int fscale; __thread struct kinfo_proc* processes = NULL; __thread size_t processes_size = 0; __thread int cmd_mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ARGS, 0 }; int sa_close_process() { if (processes != NULL) { free(processes); processes = NULL; processes_size = 0; } return 0; } int sa_count_processes(uint32_t* number) { size_t len; if (sysctl(mib, 3, NULL, &len, NULL, 0) == -1) return ENOSYS; *number = len / sizeof(struct kinfo_proc); return 0; } int sa_get_processes_ids(pid_t* dst, uint32_t dst_size, uint32_t* written) { if (dst == NULL || dst_size <= 0 || written == NULL) return EINVAL; size_t len; if (refresh_processes(&len) != 0) return ENOSYS; uint32_t i; *written = 0; len /= sizeof(struct kinfo_proc); for (i = 0; i < len; ++i) { if (i == dst_size) return ENOMEM; dst[i] = processes[i].ki_pid; ++(*written); } return 0; } int sa_get_process(pid_t pid, struct sa_process* dst) { if (dst == NULL) // A pid with value 0 is valid on FreeBSD return EINVAL; size_t len; if (refresh_processes(&len) != 0) return ENOSYS; uint16_t i; len /= sizeof(struct kinfo_proc); for (i = 0; i < len; ++i) { if (processes[i].ki_pid != pid) continue; assign(dst, &processes[i]); return 0; } return ESRCH; } int sa_get_process_activity(pid_t pid, struct sa_process_activity* dst) { if (dst == NULL) // A pid with value 0 is valid on FreeBSD return EINVAL; size_t len; if (refresh_processes(&len) != 0) return ENOSYS; uint16_t i; len /= sizeof(struct kinfo_proc); for (i = 0; i < len; ++i) { if (processes[i].ki_pid != pid) continue; assign_activity(dst, &processes[i]); return 0; } return ESRCH; } static int refresh_processes(size_t* len) { do { if (sysctl(mib, 3, NULL, len, NULL, 0) == -1) return ENOSYS; if (*len > processes_size) { safe_realloc((void*) &processes, len); processes_size = *len; if (processes == NULL) return ENOMEM; } errno = 0; if (sysctl(mib, 3, processes, len, NULL, 0) == -1 && errno != ENOMEM) return ENOSYS; } while (errno == ENOMEM); return 0; } static inline void assign(struct sa_process* __restrict__ dst, struct kinfo_proc* __restrict__ kinfo_proc) { dst->pid = kinfo_proc->ki_pid; dst->uid = kinfo_proc->ki_uid; dst->gid = kinfo_proc->ki_rgid; strlcpy(dst->filename, kinfo_proc->ki_comm, SA_PROCESS_FILENAME); cmd_mib[3] = kinfo_proc->ki_pid; size_t len = sizeof dst->cmdline; sysctl(cmd_mib, 4, dst->cmdline, &len, 0, 0); dst->parent_pid = kinfo_proc->ki_ppid; dst->pgrp = kinfo_proc->ki_pgid; dst->sid = kinfo_proc->ki_sid; dst->tty = kinfo_proc->ki_tpgid; dst->nice = kinfo_proc->ki_nice; assign_activity(&dst->activity, kinfo_proc); } static void assign_activity(struct sa_process_activity* __restrict__ dst, struct kinfo_proc* __restrict__ kinfo_proc) { dst->pid = kinfo_proc->ki_pid; switch (kinfo_proc->ki_stat) { case 3: // 3 = idle but, sleeping = idle? case 1: dst->state = SA_SLEEPING; break; case 2: dst->state = SA_RUNNING; break; case 4: dst->state = SA_STOPPED; break; case 5: dst->state = SA_ZOMBIE; break; default: dst->state = SA_UNKNOWN; } dst->sys_time = kinfo_proc->ki_runtime / 10000; dst->threads = kinfo_proc->ki_numthreads; dst->vm_size = kinfo_proc->ki_size; dst->rss = kinfo_proc->ki_rssize * pagesize; } libsysactivity-0.6.5/src/FreeBSD/network.c0000644000175000017500000001002612220245547017434 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include "utils.h" static void assign(struct sa_net_interface* __restrict__ dst, struct ifmibdata* __restrict__ if_data) SA_NONNULL; __thread int n_mib[6] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_IFDATA, 0, IFDATA_GENERAL }; __thread struct ifmibdata* buffer_n; __thread uint16_t buffer_size_n; __thread uint16_t number_interfaces; // the actual number of interfaces int sa_open_net(void) { buffer_n = NULL; buffer_size_n = 0; number_interfaces = 0; return 0; } int sa_close_net(void) { if (buffer_n != NULL) free(buffer_n); return 0; } int sa_count_net_interfaces(uint16_t* number) { if (number == NULL) return EINVAL; u_int count; size_t len = sizeof count; if (sysctlbyname("net.link.generic.system.ifcount", &count, &len, NULL, 0) == -1) return ENOSYS; *number = count; return 0; } int sa_reset_net_interfaces() { size_t len = sizeof(struct ifmibdata); n_mib[4] = 1; // i know, it's 1 number_interfaces = 0; while (1) { if (number_interfaces * len >= buffer_size_n) { size_t size = (number_interfaces + 1) * len; safe_realloc(&buffer_n, &size); buffer_size_n = size; if (buffer_n == NULL) return ENOMEM; } if (sysctl(n_mib, 6, &buffer_n[number_interfaces], &len, NULL, 0) == -1) break; ++n_mib[4]; ++number_interfaces; } return 0; } int sa_get_net_interfaces_ids(char* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 0; uint16_t i; for (i = 0; i < number_interfaces; ++i) { if (i == dst_size) return ENOMEM; strlcpy(&dst[i * SA_NET_INTERFACE_NAME], buffer_n[i].ifmd_name, SA_NET_INTERFACE_NAME); ++(*written); } return 0; } int sa_get_net_interface(char* name, struct sa_net_interface* dst) { if (name == NULL || dst == NULL) return EINVAL; uint16_t i; for (i = 0; i < number_interfaces; ++i) { if (strncmp(buffer_n[i].ifmd_name, name, sizeof buffer_n->ifmd_name) != 0) continue; assign(dst, &buffer_n[i]); return 0; } return ENODEV; } int sa_get_net_interfaces(struct sa_net_interface* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 0; uint16_t i; for (i = 0; i < number_interfaces; ++i) { if (i == dst_size) return ENOMEM; assign(&dst[i], &buffer_n[i]); ++(*written); } return 0; } static void assign(struct sa_net_interface* __restrict__ dst, struct ifmibdata* __restrict__ if_data) { strlcpy(dst->name, if_data->ifmd_name, sizeof dst->name); dst->received_bytes = if_data->ifmd_data.ifi_ibytes; dst->received_packets = if_data->ifmd_data.ifi_ipackets; dst->received_errors = if_data->ifmd_data.ifi_ierrors; dst->received_drop = if_data->ifmd_data.ifi_iqdrops; dst->received_multicast = if_data->ifmd_data.ifi_imcasts; dst->sent_bytes = if_data->ifmd_data.ifi_obytes; dst->sent_packets = if_data->ifmd_data.ifi_opackets; dst->sent_errors = if_data->ifmd_data.ifi_oerrors; dst->sent_multicast = if_data->ifmd_data.ifi_omcasts; } libsysactivity-0.6.5/src/FreeBSD/memory.c0000644000175000017500000000531112220245547017254 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include "utils.h" #define M_MIB_SIZE 3 extern long pagesize; __thread int m_mib[M_MIB_SIZE]; int sa_open_memory() { size_t m_mib_size = M_MIB_SIZE; if (sysctlnametomib("vm.swap_info", m_mib, &m_mib_size) == -1) return ENOSYS; return 0; } int sa_get_memory(struct sa_memory* dst) { if (dst == NULL) return EINVAL; uint64_t tmp64 = 0; size_t len = sizeof tmp64; if (sysctlbyname("hw.physmem", &tmp64, &len, NULL, 0) == -1) return ENOSYS; dst->total = tmp64; if (sysctlbyname("vfs.bufspace", &tmp64, &len, NULL, 0) == -1) return ENOSYS; dst->buffers = tmp64; uint32_t tmp32; len = sizeof tmp32; if (sysctlbyname("vm.stats.vm.v_free_count", &tmp32, &len, NULL, 0) == -1) return ENOSYS; dst->free = (uint64_t) tmp32 * pagesize; if (sysctlbyname("vm.stats.vm.v_cache_count", &tmp32, &len, NULL, 0) == -1) return ENOSYS; dst->cached = (uint64_t) tmp32 * pagesize; if (sysctlbyname("vm.stats.vm.v_active_count", &tmp32, &len, NULL, 0) == -1) return ENOSYS; dst->active = (uint64_t) tmp32 * pagesize; if (sysctlbyname("vm.stats.vm.v_inactive_count", &tmp32, &len, NULL, 0) == -1) return ENOSYS; dst->inactive = (uint64_t) tmp32 * pagesize; if (sysctlbyname("vm.stats.vm.v_wire_count", &tmp32, &len, NULL, 0) == -1) return ENOSYS; dst->wired = (uint64_t) tmp32 * pagesize; struct xswdev xsw; size_t size = sizeof xsw; dst->swap_total = 0; dst->swap_free = 0; for (m_mib[M_MIB_SIZE - 1] = 0; sysctl(m_mib, M_MIB_SIZE, &xsw, &size, NULL, 0) != -1; ++m_mib[M_MIB_SIZE - 1]) { dst->swap_total += (uint64_t) xsw.xsw_nblks * pagesize; dst->swap_free += (uint64_t)(xsw.xsw_nblks - xsw.xsw_used) * pagesize; } return 0; } libsysactivity-0.6.5/src/FreeBSD/libsysactivity.h0000644000175000017500000000714712220245547021044 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef LIBSYSACTIVITY_H_ #define LIBSYSACTIVITY_H_ #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif #undef SA_OPEN_CPU #undef SA_CLOSE_CPU #undef SA_SMP_CAPABLE #define SA_CPU_ID #define SA_CPU_USER #define SA_CPU_NICE #define SA_CPU_SYSTEM #define SA_CPU_IDLE #undef SA_CPU_WAITING_FOR_IO #undef SA_CPU_HARDWARE_IRQ #undef SA_CPU_SOFTWARE_IRQ #undef SA_CPU_STOLEN #define SA_CPU_INTR #define SA_OPEN_DISK #define SA_CLOSE_DISK #define SA_DISK_NAME DEVSTAT_NAME_LEN #define SA_DISK_READS #undef SA_DISK_READS_MERGED #undef SA_DISK_SECTORS_READ #if DEVSTAT_VERSION == 4 #undef SA_DISK_TIME_SPENT_READING #elif DEVSTAT_VERSION == 6 #define SA_DISK_TIME_SPENT_READING #endif #define SA_DISK_WRITES #undef SA_DISK_SECTORS_WRITTEN #if DEVSTAT_VERSION == 4 #undef SA_DISK_TIME_SPENT_WRITING #elif DEVSTAT_VERSION == 6 #define SA_DISK_TIME_SPENT_WRITING #endif #define SA_DISK_BYTES_READ #define SA_DISK_BYTES_WRITTEN #define SA_OPEN_MEMORY #undef SA_CLOSE_MEMORY #define SA_MEMORY_TOTAL #define SA_MEMORY_FREE #define SA_MEMORY_ACTIVE #define SA_MEMORY_INACTIVE #define SA_MEMORY_BUFFERS #define SA_MEMORY_SWAP_TOTAL #define SA_MEMORY_SWAP_FREE #undef SA_MEMORY_SWAP_CACHED #define SA_MEMORY_WIRED #define SA_MEMORY_CACHED #undef SA_MEMORY_DIRTY #undef SA_MEMORY_EXECUTABLE #undef SA_MEMORY_FILES #undef SA_MEMORY_LOCKED #define SA_OPEN_NET #define SA_CLOSE_NET #define SA_NET_INTERFACE_NAME IFNAMSIZ #define SA_NET_INTERFACE_RECEIVED_BYTES #define SA_NET_INTERFACE_RECEIVED_PACKETS #define SA_NET_INTERFACE_RECEIVED_ERRORS #define SA_NET_INTERFACE_RECEIVED_DROP #undef SA_NET_INTERFACE_RECEIVED_FIFO #undef SA_NET_INTERFACE_RECEIVED_COMPRESSED #define SA_NET_INTERFACE_RECEIVED_MULTICAST #define SA_NET_INTERFACE_SENT_BYTES #define SA_NET_INTERFACE_SENT_PACKETS #define SA_NET_INTERFACE_SENT_ERRORS #undef SA_NET_INTERFACE_SENT_DROP #undef SA_NET_INTERFACE_SENT_FIFO #undef SA_NET_INTERFACE_SENT_COMPRESSED #define SA_NET_INTERFACE_SENT_MULTICAST #undef SA_OPEN_PROCESS #define SA_CLOSE_PROCESS #define SA_PROCESS_PID #define SA_PROCESS_UID #define SA_PROCESS_GID #define SA_PROCESS_FILENAME COMMLEN+1 #define SA_PROCESS_CMDLINE 256 #define SA_PROCESS_PARENT_PID #define SA_PROCESS_PGRP #define SA_PROCESS_SID #define SA_PROCESS_TTY #define SA_PROCESS_NICE #undef SA_PROCESS_START_TIME #define SA_PROCESS_STATE #undef SA_PROCESS_USER_TIME #define SA_PROCESS_SYS_TIME #define SA_PROCESS_THREADS #define SA_PROCESS_VM_SIZE #define SA_PROCESS_RSS #define SA_OPEN_SWAP #undef SA_CLOSE_SWAP #define SA_SWAP_NAME 32 #define SA_SWAP_TOTAL #define SA_SWAP_FREE #undef SA_SWAP_TYPE #include "global.h" #ifdef __cplusplus } #endif #endif /* LIBSYSACTIVITY_H_ */ libsysactivity-0.6.5/src/FreeBSD/disk.c0000644000175000017500000001036512220245547016703 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009-2011 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include "utils.h" #define MIB_SIZE 3 static void assign(struct sa_disk* __restrict__ dst, struct devstat* __restrict__ src) SA_NONNULL; __thread void* buffer; __thread size_t buffer_size = 0; __thread int ds_mib[MIB_SIZE]; __thread int number_devs; __thread struct devstat* devs; int sa_open_disk() { buffer = NULL; buffer_size = 0; int version; size_t len = sizeof version; if (sysctlbyname("kern.devstat.version", &version, &len, NULL, 0) == -1) return ENOSYS; if (version != DEVSTAT_VERSION) return ENOSYS; len = MIB_SIZE; if (sysctlnametomib("kern.devstat.numdevs", ds_mib, &len) == -1) return ENOSYS; return 0; } int sa_close_disk() { if (buffer != NULL) free(buffer); return 0; } int sa_count_disks(uint16_t* number) { if (number == NULL) return EINVAL; int amount; size_t len = sizeof amount; if (sysctl(ds_mib, MIB_SIZE, &amount, &len, NULL, 0) == -1) return ENOSYS; *number = amount; return 0; } int sa_reset_disks() { size_t len; do { len = sizeof number_devs; if (sysctl(ds_mib, MIB_SIZE, &number_devs, &len, NULL, 0) == -1) return ENOSYS; len = (number_devs * sizeof(struct devstat)) + sizeof(long); if (len > buffer_size) { safe_realloc(&buffer, &len); buffer_size = len; if (buffer == NULL) return ENOMEM; } errno = 0; if (sysctlbyname("kern.devstat.all", buffer, &len, NULL, 0) == -1 && errno != ENOMEM) return ENOSYS; } while (errno == ENOMEM); devs = (struct devstat *) (buffer + sizeof(long)); return 0; } int sa_get_disks_ids(char* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 0; uint16_t i; for (i = 0; i < number_devs; ++i) { if (i == dst_size) return ENOMEM; snprintf(&dst[i * SA_DISK_NAME], SA_DISK_NAME, "%s%d", devs[i].device_name, devs[i].unit_number); ++(*written); } return 0; } int sa_get_disk(char* name, struct sa_disk* dst) { if (name == NULL || dst == NULL) return EINVAL; uint16_t i; char tmp_name[sizeof dst->name]; for (i = 0; i < number_devs; ++i) { snprintf(tmp_name, sizeof tmp_name, "%s%d", devs[i].device_name, devs[i].unit_number); if (strncmp(tmp_name, name, sizeof tmp_name) != 0) continue; assign(dst, &devs[i]); return 0; } return ENODEV; } int sa_get_disks(struct sa_disk* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 0; uint16_t i; for (i = 0; i < number_devs; ++i) { if (i == dst_size) return ENOMEM; assign(&dst[i], &devs[i]); ++(*written); } return 0; } static void assign(struct sa_disk* __restrict__ dst, struct devstat* __restrict__ src) { snprintf(dst->name, sizeof dst->name, "%s%d", src->device_name, src->unit_number); #if DEVSTAT_VERSION == 4 dst->reads = src->num_reads; dst->writes = src->num_writes; dst->bytes_read = src->bytes_read; dst->bytes_written = src->bytes_written; #elif DEVSTAT_VERSION == 6 dst->reads = src->operations[DEVSTAT_READ]; dst->time_spent_reading = src->duration[DEVSTAT_READ].sec; dst->writes = src->operations[DEVSTAT_WRITE]; dst->time_spent_writing = src->duration[DEVSTAT_WRITE].sec; dst->bytes_read = src->bytes[DEVSTAT_READ]; dst->bytes_written = src->bytes[DEVSTAT_WRITE]; #endif } libsysactivity-0.6.5/src/FreeBSD/cpu.c0000644000175000017500000001104412220245547016533 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2009, 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include static void percentages(long* new, long* old) SA_NONNULL; static void assign(struct sa_cpu* dst) SA_NONNULL; __thread long cp_time[CPUSTATES]; __thread long cp_old[CPUSTATES]; // its first value is zero int sa_reset_cpus() { size_t len = sizeof cp_time; if (sysctlbyname("kern.cp_time", &cp_time, &len, NULL, 0) == -1) return ENOSYS; return 0; } int sa_count_cpus(uint16_t* number) { if (number == NULL) return EINVAL; *number = 1; return 0; } int sa_get_cpu(uint16_t index, struct sa_cpu* dst) { if (index > 0 || dst == NULL) return EINVAL; percentages(cp_time, cp_old); assign(dst); return 0; } int sa_get_cpus(struct sa_cpu* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 1; percentages(cp_time, cp_old); assign(dst); return 0; } /* * This function is taken from unixtop 3.8beta1 at http://www.unixtop.org/download/ * * Copyright (c) 1984 through 2008, William LeFebvre * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * * Neither the name of William LeFebvre nor the names of other * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ static void percentages(long* new, long* old) { register int i; long change; long total_change; long half_total; long cp_diff[CPUSTATES]; total_change = 0; /* calculate changes for each state and the overall change */ for (i = 0; i < CPUSTATES; ++i) { if ((change = new[i] - old[i]) < 0) { /* this only happens when the counter wraps */ change = (int) ((unsigned long) new[i] - (unsigned long) old[i]); } total_change += (cp_diff[i] = change); old[i] = new[i]; } /* avoid divide by zero potential */ if (total_change == 0) total_change = 1; /* calculate percentages based on overall change, rounding up */ half_total = total_change / 2l; for (i = 0; i < CPUSTATES; ++i) new[i] = (cp_diff[i] * 1000 + half_total) / total_change; } static void assign(struct sa_cpu* dst) { dst->id = 0; dst->user = cp_time[CP_USER] / 10; dst->nice = cp_time[CP_NICE] / 10; dst->system = cp_time[CP_SYS] / 10; dst->idle = cp_time[CP_IDLE] / 10; dst->intr = cp_time[CP_INTR] / 10; } libsysactivity-0.6.5/src/FreeBSD/CMakeLists.txt0000644000175000017500000000064412220245547020344 0ustar hazelhazel list(APPEND SPECIFIC_HDRS libsysactivity.h) INSTALL(FILES ${SPECIFIC_HDRS} DESTINATION ${HEADERS_INSTALLATION_DIR}) FILE(GLOB LIBSA_SPECIFIC_SRCS *.c) ADD_LIBRARY(sysactivity SHARED ${LIBSA_SPECIFIC_SRCS}) set_target_properties(sysactivity PROPERTIES VERSION ${LIBSA_VERSION} SOVERSION ${LIBSA_ABI_VERSION}) target_link_libraries(sysactivity) INSTALL(TARGETS sysactivity LIBRARY DESTINATION ${LIB_INSTALLATION_DIR}) libsysactivity-0.6.5/src/DragonFly/0000755000175000017500000000000012220245547016253 5ustar hazelhazellibsysactivity-0.6.5/src/DragonFly/utils.h0000644000175000017500000000177612220245547017577 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef UTILS_H_ #define UTILS_H_ long pagesize; int safe_realloc(void** ptr, size_t* size) SA_NONNULL; #endif /* UTILS_H_ */ libsysactivity-0.6.5/src/DragonFly/utils.c0000644000175000017500000000235512220245547017564 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include "utils.h" static void __attribute__ ((constructor)) get_pagesize(void) { pagesize = sysconf(_SC_PAGESIZE); } int safe_realloc(void** ptr, size_t* size) { void* tmp = realloc(*ptr, *size); if (tmp == NULL) { free(*ptr); *ptr = NULL; *size = 0; return ENOMEM; } *ptr = tmp; return 0; } libsysactivity-0.6.5/src/DragonFly/swap.c0000644000175000017500000000641412220245547017376 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include "utils.h" #define MIB_SIZE 3 __thread struct xswdev* xswbuf = NULL; __thread size_t xswbuf_len = 0; __thread uint16_t number_swaps; extern long pagesize; int sa_close_swap() { if (xswbuf != NULL) { free(xswbuf); xswbuf = NULL; xswbuf_len = 0; } return 0; } int sa_count_swaps(uint16_t* number) { if (number == NULL) return EINVAL; int ret = sa_reset_swaps(); if (ret != 0) return ret; *number = number_swaps; return 0; } int sa_reset_swaps() { size_t len; do { // See http://gitweb.dragonflybsd.org/dragonfly.git/blobdiff/79634a6643a5f76dd3cf8995a5c054ba6ad27192..a8a3cea3c7ac1ff2cbb8bb7aeee54a784e044128:/lib/libkvm/kvm_getswapinfo.c if (sysctlbyname("vm.swap_info_array", NULL, &len, NULL, 0) == -1 || len == 0) return ENOSYS; if (len > xswbuf_len) { safe_realloc((void*) &xswbuf, &len); xswbuf_len = len; if (xswbuf == NULL) return ENOMEM; } errno = 0; if ((sysctlbyname("vm.swap_info_array", xswbuf, &len, NULL, 0) == -1 || len == 0) && errno != ENOMEM) return ENOSYS; } while (errno == ENOMEM); number_swaps = (uint16_t) (len / xswbuf->xsw_size); return 0; } int sa_get_swap(uint16_t index, struct sa_swap* dst) { if (dst == NULL) return EINVAL; int i, j; i = j = 0; while (i < number_swaps) { if (xswbuf->xsw_dev != NODEV && (xswbuf->xsw_flags & SW_FREED) != 0) { if (index == j) { strlcpy(dst->name, devname(xswbuf->xsw_dev, S_IFCHR), SA_SWAP_NAME); dst->total = xswbuf->xsw_nblks * pagesize; dst->free = (xswbuf->xsw_nblks - xswbuf->xsw_used) * pagesize; return 0; } ++j; } ++i; xswbuf += xswbuf->xsw_size; } return ENODEV; } int sa_get_swaps(struct sa_swap* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; int i, j; *written = i = j = 0; while (i < number_swaps) { if (xswbuf->xsw_dev != NODEV && (xswbuf->xsw_flags & SW_FREED) != 0) { if (j == dst_size) return ENOMEM; strlcpy(dst[j].name, devname(xswbuf->xsw_dev, S_IFCHR), SA_SWAP_NAME); dst[j].total = xswbuf->xsw_nblks * pagesize; dst[j].free = (xswbuf->xsw_nblks - xswbuf->xsw_used) * pagesize; ++j; ++(*written); } ++i; xswbuf += xswbuf->xsw_size; } return 0; } libsysactivity-0.6.5/src/DragonFly/process.c0000644000175000017500000001106612220245547020101 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include "utils.h" static int refresh_processes(size_t* len) SA_HOT SA_NONNULL; static void assign(struct sa_process* dst, struct kinfo_proc* kinfo_proc) SA_NONNULL; static void assign_activity(struct sa_process_activity* dst, struct kinfo_proc* kinfo_proc) SA_NONNULL; int mib[3] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL }; extern long pagesize; __thread struct kinfo_proc* processes = NULL; __thread size_t processes_size = 0; __thread int cmd_mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ARGS, 0 }; int sa_close_process() { if (processes != NULL) { free(processes); processes = NULL; processes_size = 0; } return 0; } int sa_count_processes(uint32_t* number) { size_t len; if (sysctl(mib, 3, NULL, &len, NULL, 0) == -1) return ENOSYS; *number = len / sizeof(struct kinfo_proc); return 0; } int sa_get_processes_ids(pid_t* dst, uint32_t dst_size, uint32_t* written) { if (dst == NULL || dst_size <= 0 || written == NULL) return EINVAL; size_t len; if (refresh_processes(&len) != 0) return ENOSYS; uint32_t i; *written = 0; len /= sizeof(struct kinfo_proc); for (i = 0; i < len; ++i) { if (i == dst_size) return ENOMEM; dst[i] = processes[i].kp_pid; ++(*written); } return 0; } int sa_get_process(pid_t pid, struct sa_process* dst) { if (dst == NULL) // A pid with value 0 is valid here return EINVAL; struct kinfo_proc proc; size_t len = sizeof proc; int mib_pid[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID }; mib_pid[3] = pid; if (sysctl(mib_pid, 4, &proc, &len, NULL, 0) == -1) return ENOSYS; assign(dst, &proc); return 0; } int sa_get_process_activity(pid_t pid, struct sa_process_activity* dst) { if (dst == NULL) // A pid with value 0 is valid here return EINVAL; struct kinfo_proc proc; size_t len = sizeof proc; int mib_pid[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID }; mib_pid[3] = pid; if (sysctl(mib_pid, 4, &proc, &len, NULL, 0) == -1) return ENOSYS; assign_activity(dst, &proc); return 0; } static int refresh_processes(size_t* len) { do { if (sysctl(mib, 3, NULL, len, NULL, 0) == -1) return ENOSYS; if (*len > processes_size) { safe_realloc((void*) &processes, len); processes_size = *len; if (processes == NULL) return ENOMEM; } errno = 0; if (sysctl(mib, 3, processes, len, NULL, 0) == -1 && errno != ENOMEM) return ENOSYS; } while (errno == ENOMEM); return 0; } static void assign(struct sa_process* dst, struct kinfo_proc* kinfo_proc) { dst->pid = kinfo_proc->kp_pid; dst->uid = kinfo_proc->kp_uid; dst->gid = kinfo_proc->kp_rgid; strlcpy(dst->filename, kinfo_proc->kp_comm, SA_PROCESS_FILENAME); cmd_mib[3] = kinfo_proc->kp_pid; size_t len = sizeof dst->cmdline; sysctl(cmd_mib, 4, dst->cmdline, &len, 0, 0); dst->parent_pid = kinfo_proc->kp_ppid; dst->pgrp = kinfo_proc->kp_pgid; dst->sid = kinfo_proc->kp_sid; dst->tty = kinfo_proc->kp_tpgid; dst->nice = kinfo_proc->kp_nice; assign_activity(&dst->activity, kinfo_proc); } static void assign_activity(struct sa_process_activity* dst, struct kinfo_proc* kinfo_proc) { dst->pid = kinfo_proc->kp_pid; switch (kinfo_proc->kp_stat) { case 3: // 3 = idle but, sleeping = idle? case 1: dst->state = SA_SLEEPING; break; case 2: dst->state = SA_RUNNING; break; case 4: dst->state = SA_STOPPED; break; case 5: dst->state = SA_ZOMBIE; break; default: dst->state = SA_UNKNOWN; } dst->user_time = kinfo_proc->kp_lwp.kl_uticks; dst->sys_time = kinfo_proc->kp_lwp.kl_sticks; dst->threads = kinfo_proc->kp_nthreads; dst->vm_size = kinfo_proc->kp_vm_map_size; dst->rss = kinfo_proc->kp_vm_rssize * pagesize; } libsysactivity-0.6.5/src/DragonFly/memory.c0000644000175000017500000000563512220245547017740 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include #include #include "utils.h" #define MIB_SIZE 3 __thread int m_mib[MIB_SIZE]; extern long pagesize; int sa_get_memory(struct sa_memory* dst) { if (dst == NULL) return EINVAL; uint64_t tmp64 = 0; size_t len = sizeof tmp64; if (sysctlbyname("hw.physmem", &tmp64, &len, NULL, 0) == -1) return ENOSYS; dst->total = tmp64; if (sysctlbyname("vfs.bufspace", &tmp64, &len, NULL, 0) == -1) return ENOSYS; dst->buffers = tmp64; uint32_t tmp32; len = sizeof tmp32; if (sysctlbyname("vm.stats.vm.v_free_count", &tmp32, &len, NULL, 0) == -1) return ENOSYS; dst->free = (uint64_t) tmp32 * pagesize; if (sysctlbyname("vm.stats.vm.v_cache_count", &tmp32, &len, NULL, 0) == -1) return ENOSYS; dst->cached = (uint64_t) tmp32 * pagesize; if (sysctlbyname("vm.stats.vm.v_active_count", &tmp32, &len, NULL, 0) == -1) return ENOSYS; dst->active = (uint64_t) tmp32 * pagesize; if (sysctlbyname("vm.stats.vm.v_inactive_count", &tmp32, &len, NULL, 0) == -1) return ENOSYS; dst->inactive = (uint64_t) tmp32 * pagesize; if (sysctlbyname("vm.stats.vm.v_wire_count", &tmp32, &len, NULL, 0) == -1) return ENOSYS; dst->wired = (uint64_t) tmp32 * pagesize; // See http://bugs.dragonflybsd.org/issue1805 and // http://gitweb.dragonflybsd.org/dragonfly.git/blobdiff/878e32ca6306f6d48a6232ff29a6611adc74bd01..97a3ace7a60a869c957f6c0bb6d9f69bce477f80:/sys/vm/swap_pager.c if (sysctlbyname("vm.swap_size", &tmp32, &len, NULL, 0) == -1) return ENOSYS; dst->swap_total = (uint64_t) tmp32 * pagesize; size_t swap_anon_use; len = sizeof swap_anon_use; if (sysctlbyname("vm.swap_anon_use", &swap_anon_use, &len, NULL, 0) == -1) return ENOSYS; size_t swap_cache_use; len = sizeof swap_cache_use; if (sysctlbyname("vm.swap_cache_use", &swap_cache_use, &len, NULL, 0) == -1) return ENOSYS; dst->swap_free = (tmp32 - swap_anon_use - swap_cache_use) * pagesize; return 0; } libsysactivity-0.6.5/src/DragonFly/libsysactivity.h0000644000175000017500000000704412220245547021513 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef LIBSYSACTIVITY_H_ #define LIBSYSACTIVITY_H_ #include #include #include #ifdef __cplusplus extern "C" { #endif #define SA_OPEN_CPU #define SA_CLOSE_CPU #define SA_SMP_CAPABLE #define SA_CPU_ID #define SA_CPU_USER #define SA_CPU_NICE #define SA_CPU_SYSTEM #define SA_CPU_IDLE #undef SA_CPU_WAITING_FOR_IO #undef SA_CPU_HARDWARE_IRQ #undef SA_CPU_SOFTWARE_IRQ #undef SA_CPU_STOLEN #define SA_CPU_INTR #define SA_OPEN_DISK #define SA_CLOSE_DISK #define SA_DISK_NAME DEVSTAT_NAME_LEN #define SA_DISK_READS #undef SA_DISK_READS_MERGED #undef SA_DISK_SECTORS_READ #if DEVSTAT_VERSION == 4 #undef SA_DISK_TIME_SPENT_READING #elif DEVSTAT_VERSION == 6 #define SA_DISK_TIME_SPENT_READING #endif #define SA_DISK_WRITES #undef SA_DISK_SECTORS_WRITTEN #if DEVSTAT_VERSION == 4 #undef SA_DISK_TIME_SPENT_WRITING #elif DEVSTAT_VERSION == 6 #define SA_DISK_TIME_SPENT_WRITING #endif #define SA_DISK_BYTES_READ #define SA_DISK_BYTES_WRITTEN #undef SA_OPEN_MEMORY #undef SA_CLOSE_MEMORY #define SA_MEMORY_TOTAL #define SA_MEMORY_FREE #define SA_MEMORY_ACTIVE #define SA_MEMORY_INACTIVE #define SA_MEMORY_BUFFERS #define SA_MEMORY_SWAP_TOTAL #define SA_MEMORY_SWAP_FREE #undef SA_MEMORY_SWAP_CACHED #define SA_MEMORY_WIRED #define SA_MEMORY_CACHED #undef SA_MEMORY_DIRTY #undef SA_MEMORY_EXECUTABLE #undef SA_MEMORY_FILES #undef SA_MEMORY_LOCKED #undef SA_OPEN_NET #undef SA_CLOSE_NET #define SA_NET_INTERFACE_NAME IFNAMSIZ #define SA_NET_INTERFACE_RECEIVED_BYTES #define SA_NET_INTERFACE_RECEIVED_PACKETS #define SA_NET_INTERFACE_RECEIVED_ERRORS #define SA_NET_INTERFACE_RECEIVED_DROP #undef SA_NET_INTERFACE_RECEIVED_FIFO #undef SA_NET_INTERFACE_RECEIVED_COMPRESSED #define SA_NET_INTERFACE_RECEIVED_MULTICAST #define SA_NET_INTERFACE_SENT_BYTES #define SA_NET_INTERFACE_SENT_PACKETS #define SA_NET_INTERFACE_SENT_ERRORS #undef SA_NET_INTERFACE_SENT_DROP #undef SA_NET_INTERFACE_SENT_FIFO #undef SA_NET_INTERFACE_SENT_COMPRESSED #define SA_NET_INTERFACE_SENT_MULTICAST #undef SA_OPEN_PROCESS #define SA_CLOSE_PROCESS #define SA_PROCESS_PID #define SA_PROCESS_UID #define SA_PROCESS_GID #define SA_PROCESS_FILENAME MAXCOMLEN+1 #define SA_PROCESS_CMDLINE 256 #define SA_PROCESS_PARENT_PID #define SA_PROCESS_PGRP #define SA_PROCESS_SID #define SA_PROCESS_TTY #define SA_PROCESS_NICE #undef SA_PROCESS_START_TIME #define SA_PROCESS_STATE #define SA_PROCESS_USER_TIME #define SA_PROCESS_SYS_TIME #define SA_PROCESS_THREADS #define SA_PROCESS_VM_SIZE #define SA_PROCESS_RSS #undef SA_OPEN_SWAP #define SA_CLOSE_SWAP #define SA_SWAP_NAME 32 #define SA_SWAP_TOTAL #define SA_SWAP_FREE #undef SA_SWAP_TYPE #include "global.h" #ifdef __cplusplus } #endif #endif /* LIBSYSACTIVITY_H_ */ libsysactivity-0.6.5/src/DragonFly/cpu.c0000644000175000017500000000653212220245547017214 0ustar hazelhazel/* * libsysactivity * http://sourceforge.net/projects/libsysactivity/ * Copyright (c) 2010 Carlos Olmedo Escobar * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include "utils.h" static void percentages(struct sa_cpu* dst, struct kinfo_cputime *new, struct kinfo_cputime *old) SA_NONNULL; __thread uint16_t number_cpus; __thread struct kinfo_cputime* cpu_times; __thread size_t cpu_times_len; __thread struct kinfo_cputime* cpu_old; int sa_open_cpu() { cpu_old = NULL; cpu_times = NULL; cpu_times_len = 0; int num; if (kinfo_get_cpus(&num)) return ENOSYS; number_cpus = num; cpu_old = calloc(num, sizeof(struct kinfo_cputime)); if (cpu_old == NULL) return ENOMEM; return 0; } int sa_close_cpu() { if (cpu_old != NULL) free(cpu_old); if (cpu_times != NULL) free(cpu_times); return 0; } int sa_reset_cpus() { size_t len = sizeof(struct kinfo_cputime) * number_cpus; if (cpu_times_len < len) { safe_realloc(&cpu_times, &len); cpu_times_len = len; if (cpu_times == NULL) return ENOMEM; } if (sysctlbyname("kern.cputime", cpu_times, &cpu_times_len, NULL, 0) != 0) return ENOSYS; return 0; } int sa_get_cpu(uint16_t index, struct sa_cpu* dst) { if (index >= number_cpus || dst == NULL) return EINVAL; percentages(dst, &cpu_times[index], &cpu_old[index]); return 0; } int sa_count_cpus(uint16_t* number) { if (number == NULL) return EINVAL; *number = number_cpus; return 0; } int sa_get_cpus(struct sa_cpu* dst, uint16_t dst_size, uint16_t* written) { if (dst == NULL || dst_size == 0 || written == NULL) return EINVAL; *written = 0; uint16_t i; for (i = 0; i < number_cpus; ++i) { if (i >= dst_size) return ENOMEM; percentages(&dst[i], &cpu_times[i], &cpu_old[i]); ++(*written); } return 0; } static void percentages(struct sa_cpu* dst, struct kinfo_cputime *new, struct kinfo_cputime *old) { struct kinfo_cputime delta; delta.cp_user = new->cp_user - old->cp_user; delta.cp_nice = new->cp_nice - old->cp_nice; delta.cp_sys = new->cp_sys - old->cp_sys; delta.cp_intr = new->cp_intr - old->cp_intr; delta.cp_idle = new->cp_idle - old->cp_idle; uint64_t total = delta.cp_user + delta.cp_nice + delta.cp_sys + delta.cp_intr + delta.cp_idle; if (total == 0) total = 1; dst->user = (double) delta.cp_user * 100.0 / (double) total; dst->nice = (double) delta.cp_nice * 100.0 / (double) total; dst->system = (double) delta.cp_sys * 100.0 / (double) total; dst->idle = (double) delta.cp_idle * 100.0 / (double) total; dst->intr = (double) delta.cp_intr * 100.0 / (double) total; *old = *new; } libsysactivity-0.6.5/src/DragonFly/CMakeLists.txt0000644000175000017500000000111312220245547021007 0ustar hazelhazel list(APPEND SPECIFIC_HDRS libsysactivity.h) install(FILES ${SPECIFIC_HDRS} DESTINATION ${HEADERS_INSTALLATION_DIR}) file(GLOB LIBSA_SPECIFIC_SRCS *.c) list(APPEND LIBSA_SPECIFIC_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../FreeBSD/disk.c) list(APPEND LIBSA_SPECIFIC_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../FreeBSD/network.c) add_library(sysactivity SHARED ${LIBSA_SPECIFIC_SRCS}) set_target_properties(sysactivity PROPERTIES VERSION ${LIBSA_VERSION} SOVERSION ${LIBSA_ABI_VERSION}) target_link_libraries(sysactivity kinfo) install(TARGETS sysactivity LIBRARY DESTINATION ${LIB_INSTALLATION_DIR}) libsysactivity-0.6.5/src/CMakeLists.txt0000644000175000017500000000240012220245547017122 0ustar hazelhazel # Checking the OS if (${CMAKE_SYSTEM_NAME} MATCHES "^Linux$|^FreeBSD$|^SunOS$|^NetBSD$|^OpenBSD$|^kFreeBSD$|^DragonFly$") message(STATUS "OS detected: ${CMAKE_SYSTEM_NAME}") else () message(FATAL_ERROR "OS: ${CMAKE_SYSTEM_NAME} is not supported") endif () set(LIBSA_ABI_VERSION 1) # Increase this number everytime the ABI is broken if (NOT DEFINED HEADERS_INSTALLATION_DIR) set(HEADERS_INSTALLATION_DIR "${CMAKE_INSTALL_PREFIX}/include/libsysactivity/") endif (NOT DEFINED HEADERS_INSTALLATION_DIR) if (NOT DEFINED LIB_INSTALLATION_DIR) set(LIB_INSTALLATION_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}") endif (NOT DEFINED LIB_INSTALLATION_DIR) # Common headers add_subdirectory(common) # Forcing to include the right libsysactivity.h through command line so it can compile whatever file # from another operating system without any include conflict if (${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD") add_definitions(-include ${CMAKE_CURRENT_SOURCE_DIR}/FreeBSD/libsysactivity.h) else () add_definitions(-include ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_SYSTEM_NAME}/libsysactivity.h) endif () # Specific code include_directories(common/) if (${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD") add_subdirectory("FreeBSD") else () add_subdirectory(${CMAKE_SYSTEM_NAME}) endif () libsysactivity-0.6.5/release.sh0000755000175000017500000000523712220245547015565 0ustar hazelhazel#!/bin/bash if [ $# -ne 1 ] then echo "Usage: `basename $0` {version}" exit 1 fi DOTTED_VERSION=$1 SLASHED_VERSION=$(echo $DOTTED_VERSION|sed 's/\./_/g') OLD_WORKING_DIR=`pwd` WORKING_DIR=/tmp/libsysactivity-$RANDOM clean () { rm -rf $WORKING_DIR } mkdir -p $WORKING_DIR cd $WORKING_DIR git clone git://libsysactivity.git.sourceforge.net/gitroot/libsysactivity/libsysactivity -b v${DOTTED_VERSION%.*} libsysactivity-$DOTTED_VERSION cd libsysactivity-$DOTTED_VERSION git checkout v$DOTTED_VERSION cd .. grep -r --color " printf" $WORKING_DIR/libsysactivity-$DOTTED_VERSION/src/* if [ $? == 0 ]; then echo "There are printf() calls in the code" clean exit 2 fi grep LIBSA_VERSION $WORKING_DIR/libsysactivity-$DOTTED_VERSION/CMakeLists.txt read -p "Have you updated the CMakeList.txt version? (y/n) " yn if [ $yn != "y" ]; then clean exit 2 fi grep SA_VERSION_ $WORKING_DIR/libsysactivity-$DOTTED_VERSION/src/common/global.h read -p "Have you updated the version in global.h? (y/n) " yn if [ $yn != "y" ]; then clean exit 2 fi grep PROJECT_NUMBER $WORKING_DIR/libsysactivity-$DOTTED_VERSION/Doxyfile read -p "Have you updated the Doxyfile version? (y/n) " yn if [ $yn != "y" ]; then clean exit 2 fi cat $WORKING_DIR/libsysactivity-$DOTTED_VERSION/cmake/libsysactivityConfigVersion.cmake read -p "Have you updated the libsysactivityConfigVersion.cmake? (always needed) (y/n) " yn if [ $yn != "y" ]; then clean exit 2 fi head $WORKING_DIR/libsysactivity-$DOTTED_VERSION/CHANGELOG read -p "Have you updated the changelog? (y/n) " yn if [ $yn != "y" ]; then clean exit 2 fi grep LIBSA_ABI_VERSION $WORKING_DIR/libsysactivity-$DOTTED_VERSION/src/CMakeLists.txt read -p "Did you break the ABI? (y/n) " yn for dir in DragonFly FreeBSD Linux NetBSD OpenBSD SunOS do cppcheck --error-exitcode=1 -I $WORKING_DIR/libsysactivity-$DOTTED_VERSION/src/common/ -I $WORKING_DIR/libsysactivity-$DOTTED_VERSION/src/$dir/ $WORKING_DIR/libsysactivity-$DOTTED_VERSION/src/$dir/*.c if [ $? != 0 ]; then echo "ERROR: cppcheck found an error on $dir code." clean exit 3 fi done mkdir $WORKING_DIR/libsysactivity-$DOTTED_VERSION/build/ cd $WORKING_DIR/libsysactivity-$DOTTED_VERSION/build/ cmake .. -DCMAKE_BUILD_TYPE=debug && make if [ $? != 0 ]; then echo "ERROR: Can't build the CVS code." clean exit 4 fi make -f test/Makefile && make test if [ $? != 0 ]; then echo "ERROR: Unit tests not passed." clean exit 5 fi rm -rf $WORKING_DIR/libsysactivity-$DOTTED_VERSION/build/* rm -rf $WORKING_DIR/libsysactivity-$DOTTED_VERSION/.git* cd $WORKING_DIR tar -zcvf libsysactivity-$DOTTED_VERSION.tar.gz libsysactivity-$DOTTED_VERSION mv libsysactivity-$DOTTED_VERSION.tar.gz ~ cd $OLD_WORKING_DIR clean libsysactivity-0.6.5/doc/0000755000175000017500000000000012220245547014344 5ustar hazelhazellibsysactivity-0.6.5/doc/additional0000644000175000017500000003114112220245547016377 0ustar hazelhazel/** \mainpage * * \section intro_sec Technical overview * - Lightweight: It's a small and fast library that obtains the statistics directly from the system, nothing else is under it. * - Secure: it works with no privileges so no SUID bit is needed. * - Multi-architecture: it exposes a common API: common functions and common structures, most of the fields of these structures are common too. The OS-specific stuff has been reduced to the minimum. * - Thread-safe: you can use it during simultaneous execution by multiple threads. * - SMP: It supports per-processor statistics when possible (the underlying OS has to be capable to do so). * - Unit and stress tests: automated tests are used to guarantee the quality of the code. * * libsysactivity is made up of these feature sets: * - \ref cpu "cpu" * - \ref disk "disk" * - \ref memory "memory" * - \ref network "network" * - \ref process "process" * * \page matrix_page Matrix of available stats per OS * \section matrix_cpu_sec CPU matrix \latexonly \begin{center} \begin{tabular}{ | l | l | l | l | l | l | l | } \hline & DragonFly & FreeBSD & Linux & NetBSD & OpenBSD & SunOS \\ \hline SMP support * & \cellcolor{green} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline id & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline user & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline nice & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} \\ \hline system & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline idle & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline waiting for io & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} \\ \hline hardware irq & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline software irq & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline stolen & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline intr & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} \\ \hline \end{tabular} \end{center} The \emph{id} field is the identifier of the cpu struct so it is always present.\\ (*) Per-processor stats are only available on the platforms that offers such stats.\\ \endlatexonly * \section matrix_disk_sec Disk matrix \latexonly \begin{center} \begin{tabular}{ | l | l | l | l | l | l | l | } \hline & DragonFly & FreeBSD & Linux & NetBSD & OpenBSD & SunOS \\ \hline name & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline reads & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline reads merged & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline sectors read & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline time spent reading & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline writes & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline sectors written & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline time spent writing & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline bytes read & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline bytes written & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline \end{tabular} \end{center} The \emph{name} field is the identifier of the disk struct so it is always present.\\ \endlatexonly * \section matrix_memory_sec Memory matrix \latexonly \begin{center} \begin{tabular}{ | l | l | l | l | l | l | l | } \hline & DragonFly & FreeBSD & Linux & NetBSD & OpenBSD & SunOS \\ \hline total & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline free & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline active & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} \\ \hline inactive & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} \\ \hline buffers & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline swap total & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline swap free & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline swap cached & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline wired & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} \\ \hline cached & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline dirty & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline executable & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} \\ \hline files & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} \\ \hline locked & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} \\ \hline \end{tabular} \end{center} \endlatexonly * \section matrix_swap_sec Swap matrix \latexonly \begin{center} \begin{tabular}{ | l | l | l | l | l | l | l | } \hline & DragonFly & FreeBSD & Linux & NetBSD & OpenBSD & SunOS \\ \hline name & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline total & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline free & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline type & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline \end{tabular} \end{center} The \emph{name} field is the identifier of the swap struct so it is always present.\\ \endlatexonly * \section matrix_network_sec Network matrix \latexonly \begin{center} \begin{tabular}{ | l | l | l | l | l | l | l | } \hline & DragonFly & FreeBSD & Linux & NetBSD & OpenBSD & SunOS \\ \hline name & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline received bytes & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline received packets & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline received errors & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline received drop & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} \\ \hline received fifo & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline received compressed & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} \\ \hline received multicast & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} \\ \hline sent bytes & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline sent packets & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline sent errors & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline sent drop & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline sent fifo & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline sent compressed & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{red} \\ \hline sent multicast & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} \\ \hline \end{tabular} \end{center} The \emph{name} field is the identifier of the network struct so it is always present.\\ \endlatexonly * \section matrix_process_sec Process matrix \latexonly \begin{center} \begin{tabular}{ | l | l | l | l | l | l | l | } \hline & DragonFly & FreeBSD & Linux & NetBSD & OpenBSD & SunOS \\ \hline pid & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline uid & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline gid & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline filename & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline cmdline & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} \\ \hline state & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} \\ \hline parent pid & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline pgrp & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline sid & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline tty & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline user time & \cellcolor{green} & \cellcolor{red} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline sys time & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline nice & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline threads & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} \\ \hline start time & \cellcolor{red} & \cellcolor{red} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline vm size & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline rss & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} & \cellcolor{green} \\ \hline \end{tabular} \end{center} The \emph{pid} field is the identifier of the network struct so it is always present.\\ \endlatexonly * */ libsysactivity-0.6.5/cmake/0000755000175000017500000000000012220245547014657 5ustar hazelhazellibsysactivity-0.6.5/cmake/libsysactivityConfigVersion.cmake0000644000175000017500000000137212220245547023442 0ustar hazelhazel#See http://www.cmake.org/Wiki/CMake_2.6_Notes#Package_Version_Files for more information set(PACKAGE_VERSION 0.6.5) # UPDATE ME! if ("${PACKAGE_FIND_VERSION_MAJOR}" GREATER 0) # > 0.y.z set(PACKAGE_VERSION_COMPATIBLE true) endif ("${PACKAGE_FIND_VERSION_MAJOR}" GREATER 0) if ("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 0) # == 0.y.z if ("${PACKAGE_FIND_VERSION_MINOR}" GREATER 5) # > 0.5.z set(PACKAGE_VERSION_COMPATIBLE true) if ("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 6 AND "${PACKAGE_FIND_VERSION_PATCH}" EQUAL 5) # == 0.6.5 set(PACKAGE_VERSION_EXACT true) endif ("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 6 AND "${PACKAGE_FIND_VERSION_PATCH}" EQUAL 5) endif ("${PACKAGE_FIND_VERSION_MINOR}" GREATER 5) endif ("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 0) libsysactivity-0.6.5/cmake/libsysactivityConfig.cmake0000644000175000017500000000061012220245547022066 0ustar hazelhazel#See http://www.cmake.org/Wiki/CMake_2.6_Notes#Package_Configuration_Files for more information set(LIBSYSACTIVITY_INCLUDE_DIR {CMAKE_INSTALL_PREFIX}/include/libsysactivity/) set(LIBSYSACTIVITY_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/libsysactivity.so) message(STATUS "Found libsysactivity: ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/cmake/libsysactivity/libsysactivityConfig.cmake") libsysactivity-0.6.5/cmake/CMakeLists.txt0000644000175000017500000000030512220245547017415 0ustar hazelhazelset(FIND_PACKAGE_FILES libsysactivityConfig.cmake libsysactivityConfigVersion.cmake) install(FILES ${FIND_PACKAGE_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/cmake/libsysactivity/) libsysactivity-0.6.5/TEST0000644000175000017500000000175512220245547014311 0ustar hazelhazel ======= Compile and execute unit tests ======= In order to build and execute the unit tests type the commands: cd build cmake .. # You can specify the following parameters: # -DCMAKE_BUILD_TYPE=release or -DCMAKE_BUILD_TYPE=debug # -DCMAKE_INSTALL_PREFIX=/some/absolute/path make make -f test/Makefile all # There is no need to install the library in order to compile or execute the tests make test # This is the command that actually executes the tests If you get any error please file a bug to https://sourceforge.net/tracker/?group_id=260799&atid=1137117 attaching the file build/Testing/Temporary/LastTest.log ======= Omitting tests ======= If you want one or more tests to be ignored just place a file called CTestCustom.cmake in the build/ directory with the following line (use as many lines as you need): set(CTEST_CUSTOM_TESTS_IGNORE name_of_the_test_to_ignore) where name_of_the_test_to_ignore is one of the following: cpu, disk, memory, network, process. libsysactivity-0.6.5/INSTALL0000644000175000017500000000070112220245547014626 0ustar hazelhazel Currently libsysactivity supports the following operating systems: * Linux 2.6 * FreeBSD * NetBSD * OpenBSD * Solaris/OpenSolaris. ======= Compile ======= To build it use the following commands: cd build cmake .. # You can specify the following parameters: # -DCMAKE_BUILD_TYPE=release or -DCMAKE_BUILD_TYPE=debug # -DCMAKE_INSTALL_PREFIX=/some/absolute/path make make install # You will need root privileges for this step libsysactivity-0.6.5/Doxyfile0000644000175000017500000017362312220245547015321 0ustar hazelhazel# Doxyfile 1.6.1 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project # # All text after a hash (#) is considered a comment and will be ignored # The format is: # TAG = value [value, ...] # For lists items can also be appended using: # TAG += value [value, ...] # Values that contain spaces should be placed between quotes (" ") #--------------------------------------------------------------------------- # Project related configuration options #--------------------------------------------------------------------------- # This tag specifies the encoding used for all characters in the config file # that follow. The default is UTF-8 which is also the encoding used for all # text before the first occurrence of this tag. Doxygen uses libiconv (or the # iconv built into libc) for the transcoding. See # http://www.gnu.org/software/libiconv for the list of possible encodings. DOXYFILE_ENCODING = UTF-8 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded # by quotes) that should identify the project. PROJECT_NAME = libsysactivity # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or # if some version control system is used. PROJECT_NUMBER = 0.6.5 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. # If a relative path is entered, it will be relative to the location # where doxygen was started. If left blank the current directory will be used. OUTPUT_DIRECTORY = doc # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create # 4096 sub-directories (in 2 levels) under the output directory of each output # format and will distribute the generated files over these directories. # Enabling this option can be useful when feeding doxygen a huge amount of # source files, where putting all generated files in the same directory would # otherwise cause performance problems for the file system. CREATE_SUBDIRS = NO # The OUTPUT_LANGUAGE tag is used to specify the language in which all # documentation generated by doxygen is written. Doxygen will use this # information to generate all constant output in the proper language. # The default language is English, other supported languages are: # Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, # Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, # Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English # messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, # Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, # Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. OUTPUT_LANGUAGE = English # If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will # include brief member descriptions after the members that are listed in # the file and class documentation (similar to JavaDoc). # Set to NO to disable this. BRIEF_MEMBER_DESC = YES # If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend # the brief description of a member or function before the detailed description. # Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the # brief descriptions will be completely suppressed. REPEAT_BRIEF = YES # This tag implements a quasi-intelligent brief description abbreviator # that is used to form the text in various listings. Each string # in this list, if found as the leading text of the brief description, will be # stripped from the text and the result after processing the whole list, is # used as the annotated text. Otherwise, the brief description is used as-is. # If left blank, the following values are used ("$name" is automatically # replaced with the name of the entity): "The $name class" "The $name widget" # "The $name file" "is" "provides" "specifies" "contains" # "represents" "a" "an" "the" ABBREVIATE_BRIEF = # If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then # Doxygen will generate a detailed section even if there is only a brief # description. ALWAYS_DETAILED_SEC = NO # If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all # inherited members of a class in the documentation of that class as if those # members were ordinary class members. Constructors, destructors and assignment # operators of the base classes will not be shown. INLINE_INHERITED_MEMB = NO # If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full # path before files name in the file list and in the header files. If set # to NO the shortest path that makes the file name unique will be used. FULL_PATH_NAMES = YES # If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag # can be used to strip a user-defined part of the path. Stripping is # only done if one of the specified strings matches the left-hand part of # the path. The tag can be used to show relative paths in the file list. # If left blank the directory from which doxygen is run is used as the # path to strip. STRIP_FROM_PATH = # The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of # the path mentioned in the documentation of a class, which tells # the reader which header file to include in order to use a class. # If left blank only the name of the header file containing the class # definition is used. Otherwise one should specify the include paths that # are normally passed to the compiler using the -I flag. STRIP_FROM_INC_PATH = # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter # (but less readable) file names. This can be useful is your file systems # doesn't support long names like on DOS, Mac, or CD-ROM. SHORT_NAMES = NO # If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen # will interpret the first line (until the first dot) of a JavaDoc-style # comment as the brief description. If set to NO, the JavaDoc # comments will behave just like regular Qt-style comments # (thus requiring an explicit @brief command for a brief description.) JAVADOC_AUTOBRIEF = NO # If the QT_AUTOBRIEF tag is set to YES then Doxygen will # interpret the first line (until the first dot) of a Qt-style # comment as the brief description. If set to NO, the comments # will behave just like regular Qt-style comments (thus requiring # an explicit \brief command for a brief description.) QT_AUTOBRIEF = NO # The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen # treat a multi-line C++ special comment block (i.e. a block of //! or /// # comments) as a brief description. This used to be the default behaviour. # The new default is to treat a multi-line C++ comment block as a detailed # description. Set this tag to YES if you prefer the old behaviour instead. MULTILINE_CPP_IS_BRIEF = NO # If the INHERIT_DOCS tag is set to YES (the default) then an undocumented # member inherits the documentation from any documented member that it # re-implements. INHERIT_DOCS = YES # If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce # a new page for each member. If set to NO, the documentation of a member will # be part of the file/class/namespace that contains it. SEPARATE_MEMBER_PAGES = NO # The TAB_SIZE tag can be used to set the number of spaces in a tab. # Doxygen uses this value to replace tabs by spaces in code fragments. TAB_SIZE = 8 # This tag can be used to specify a number of aliases that acts # as commands in the documentation. An alias has the form "name=value". # For example adding "sideeffect=\par Side Effects:\n" will allow you to # put the command \sideeffect (or @sideeffect) in the documentation, which # will result in a user-defined paragraph with heading "Side Effects:". # You can put \n's in the value part of an alias to insert newlines. ALIASES = # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C # sources only. Doxygen will then generate output that is more tailored for C. # For instance, some of the names that are used will be different. The list # of all members will be omitted, etc. OPTIMIZE_OUTPUT_FOR_C = YES # Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java # sources only. Doxygen will then generate output that is more tailored for # Java. For instance, namespaces will be presented as packages, qualified # scopes will look different, etc. OPTIMIZE_OUTPUT_JAVA = NO # Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran # sources only. Doxygen will then generate output that is more tailored for # Fortran. OPTIMIZE_FOR_FORTRAN = NO # Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL # sources. Doxygen will then generate output that is tailored for # VHDL. OPTIMIZE_OUTPUT_VHDL = NO # Doxygen selects the parser to use depending on the extension of the files it parses. # With this tag you can assign which parser to use for a given extension. # Doxygen has a built-in mapping, but you can override or extend it using this tag. # The format is ext=language, where ext is a file extension, and language is one of # the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP, # Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat # .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran), # use: inc=Fortran f=C. Note that for custom extensions you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. EXTENSION_MAPPING = # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want # to include (a tag file for) the STL sources as input, then you should # set this tag to YES in order to let doxygen match functions declarations and # definitions whose arguments contain STL classes (e.g. func(std::string); v.s. # func(std::string) {}). This also make the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. BUILTIN_STL_SUPPORT = NO # If you use Microsoft's C++/CLI language, you should set this option to YES to # enable parsing support. CPP_CLI_SUPPORT = NO # Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. # Doxygen will parse them like normal C++ but will assume all classes use public # instead of private inheritance when no explicit protection keyword is present. SIP_SUPPORT = NO # For Microsoft's IDL there are propget and propput attributes to indicate getter # and setter methods for a property. Setting this option to YES (the default) # will make doxygen to replace the get and set methods by a property in the # documentation. This will only work if the methods are indeed getting or # setting a simple type. If this is not the case, or you want to show the # methods anyway, you should set this option to NO. IDL_PROPERTY_SUPPORT = NO # If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC # tag is set to YES, then doxygen will reuse the documentation of the first # member in the group (if any) for the other members of the group. By default # all members of a group must be documented explicitly. DISTRIBUTE_GROUP_DOC = NO # Set the SUBGROUPING tag to YES (the default) to allow class member groups of # the same type (for instance a group of public functions) to be put as a # subgroup of that type (e.g. under the Public Functions section). Set it to # NO to prevent subgrouping. Alternatively, this can be done per class using # the \nosubgrouping command. SUBGROUPING = YES # When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum # is documented as struct, union, or enum with the name of the typedef. So # typedef struct TypeS {} TypeT, will appear in the documentation as a struct # with name TypeT. When disabled the typedef will appear as a member of a file, # namespace, or class. And the struct will be named TypeS. This can typically # be useful for C code in case the coding convention dictates that all compound # types are typedef'ed and only the typedef is referenced, never the tag name. TYPEDEF_HIDES_STRUCT = NO # The SYMBOL_CACHE_SIZE determines the size of the internal cache use to # determine which symbols to keep in memory and which to flush to disk. # When the cache is full, less often used symbols will be written to disk. # For small to medium size projects (<1000 input files) the default value is # probably good enough. For larger projects a too small cache size can cause # doxygen to be busy swapping symbols to and from disk most of the time # causing a significant performance penality. # If the system has enough physical memory increasing the cache will improve the # performance by keeping more symbols in memory. Note that the value works on # a logarithmic scale so increasing the size by one will rougly double the # memory usage. The cache size is given by this formula: # 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, # corresponding to a cache size of 2^16 = 65536 symbols SYMBOL_CACHE_SIZE = 0 #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- # If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in # documentation are documented, even if no documentation was available. # Private class members and static file members will be hidden unless # the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES EXTRACT_ALL = NO # If the EXTRACT_PRIVATE tag is set to YES all private members of a class # will be included in the documentation. EXTRACT_PRIVATE = NO # If the EXTRACT_STATIC tag is set to YES all static members of a file # will be included in the documentation. EXTRACT_STATIC = NO # If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) # defined locally in source files will be included in the documentation. # If set to NO only classes defined in header files are included. EXTRACT_LOCAL_CLASSES = NO # This flag is only useful for Objective-C code. When set to YES local # methods, which are defined in the implementation section but not in # the interface are included in the documentation. # If set to NO (the default) only methods in the interface are included. EXTRACT_LOCAL_METHODS = NO # If this flag is set to YES, the members of anonymous namespaces will be # extracted and appear in the documentation as a namespace called # 'anonymous_namespace{file}', where file will be replaced with the base # name of the file that contains the anonymous namespace. By default # anonymous namespace are hidden. EXTRACT_ANON_NSPACES = NO # If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all # undocumented members of documented classes, files or namespaces. # If set to NO (the default) these members will be included in the # various overviews, but no documentation section is generated. # This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_MEMBERS = YES # If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all # undocumented classes that are normally visible in the class hierarchy. # If set to NO (the default) these classes will be included in the various # overviews. This option has no effect if EXTRACT_ALL is enabled. HIDE_UNDOC_CLASSES = YES # If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all # friend (class|struct|union) declarations. # If set to NO (the default) these declarations will be included in the # documentation. HIDE_FRIEND_COMPOUNDS = NO # If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any # documentation blocks found inside the body of a function. # If set to NO (the default) these blocks will be appended to the # function's detailed documentation block. HIDE_IN_BODY_DOCS = NO # The INTERNAL_DOCS tag determines if documentation # that is typed after a \internal command is included. If the tag is set # to NO (the default) then the documentation will be excluded. # Set it to YES to include the internal documentation. INTERNAL_DOCS = NO # If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate # file names in lower-case letters. If set to YES upper-case letters are also # allowed. This is useful if you have classes or files whose names only differ # in case and if your file system supports case sensitive file names. Windows # and Mac users are advised to set this option to NO. CASE_SENSE_NAMES = YES # If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen # will show members with their full class and namespace scopes in the # documentation. If set to YES the scope will be hidden. HIDE_SCOPE_NAMES = YES # If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen # will put a list of the files that are included by a file in the documentation # of that file. SHOW_INCLUDE_FILES = NO # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] # is inserted in the documentation for inline members. INLINE_INFO = YES # If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen # will sort the (detailed) documentation of file and class members # alphabetically by member name. If set to NO the members will appear in # declaration order. SORT_MEMBER_DOCS = NO # If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the # brief documentation of file, namespace and class members alphabetically # by member name. If set to NO (the default) the members will appear in # declaration order. SORT_BRIEF_DOCS = NO # If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the (brief and detailed) documentation of class members so that constructors and destructors are listed first. If set to NO (the default) the constructors will appear in the respective orders defined by SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. SORT_MEMBERS_CTORS_1ST = NO # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the # hierarchy of group names into alphabetical order. If set to NO (the default) # the group names will appear in their defined order. SORT_GROUP_NAMES = NO # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be # sorted by fully-qualified names, including namespaces. If set to # NO (the default), the class list will be sorted only by class name, # not including the namespace part. # Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. # Note: This option applies only to the class list, not to the # alphabetical list. SORT_BY_SCOPE_NAME = NO # The GENERATE_TODOLIST tag can be used to enable (YES) or # disable (NO) the todo list. This list is created by putting \todo # commands in the documentation. GENERATE_TODOLIST = YES # The GENERATE_TESTLIST tag can be used to enable (YES) or # disable (NO) the test list. This list is created by putting \test # commands in the documentation. GENERATE_TESTLIST = YES # The GENERATE_BUGLIST tag can be used to enable (YES) or # disable (NO) the bug list. This list is created by putting \bug # commands in the documentation. GENERATE_BUGLIST = YES # The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or # disable (NO) the deprecated list. This list is created by putting # \deprecated commands in the documentation. GENERATE_DEPRECATEDLIST= YES # The ENABLED_SECTIONS tag can be used to enable conditional # documentation sections, marked by \if sectionname ... \endif. ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines # the initial value of a variable or define consists of for it to appear in # the documentation. If the initializer consists of more lines than specified # here it will be hidden. Use a value of 0 to hide initializers completely. # The appearance of the initializer of individual variables and defines in the # documentation can be controlled using \showinitializer or \hideinitializer # command in the documentation regardless of this setting. MAX_INITIALIZER_LINES = 30 # Set the SHOW_USED_FILES tag to NO to disable the list of files generated # at the bottom of the documentation of classes and structs. If set to YES the # list will mention the files that were used to generate the documentation. SHOW_USED_FILES = YES # If the sources in your project are distributed over multiple directories # then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy # in the documentation. The default is NO. SHOW_DIRECTORIES = NO # Set the SHOW_FILES tag to NO to disable the generation of the Files page. # This will remove the Files entry from the Quick Index and from the # Folder Tree View (if specified). The default is YES. SHOW_FILES = NO # Set the SHOW_NAMESPACES tag to NO to disable the generation of the # Namespaces page. # This will remove the Namespaces entry from the Quick Index # and from the Folder Tree View (if specified). The default is YES. SHOW_NAMESPACES = NO # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from # the version control system). Doxygen will invoke the program by executing (via # popen()) the command , where is the value of # the FILE_VERSION_FILTER tag, and is the name of an input file # provided by doxygen. Whatever the program writes to standard output # is used as the file version. See the manual for examples. FILE_VERSION_FILTER = # The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by # doxygen. The layout file controls the global structure of the generated output files # in an output format independent way. The create the layout file that represents # doxygen's defaults, run doxygen with the -l option. You can optionally specify a # file name after the option, if omitted DoxygenLayout.xml will be used as the name # of the layout file. LAYOUT_FILE = #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- # The QUIET tag can be used to turn on/off the messages that are generated # by doxygen. Possible values are YES and NO. If left blank NO is used. QUIET = NO # The WARNINGS tag can be used to turn on/off the warning messages that are # generated by doxygen. Possible values are YES and NO. If left blank # NO is used. WARNINGS = YES # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings # for undocumented members. If EXTRACT_ALL is set to YES then this flag will # automatically be disabled. WARN_IF_UNDOCUMENTED = YES # If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for # potential errors in the documentation, such as not documenting some # parameters in a documented function, or documenting parameters that # don't exist or using markup commands wrongly. WARN_IF_DOC_ERROR = YES # This WARN_NO_PARAMDOC option can be abled to get warnings for # functions that are documented, but have no documentation for their parameters # or return value. If set to NO (the default) doxygen will only warn about # wrong or incomplete parameter documentation, but not about the absence of # documentation. WARN_NO_PARAMDOC = YES # The WARN_FORMAT tag determines the format of the warning messages that # doxygen can produce. The string should contain the $file, $line, and $text # tags, which will be replaced by the file and line number from which the # warning originated and the warning text. Optionally the format may contain # $version, which will be replaced by the version of the file (if it could # be obtained via FILE_VERSION_FILTER) WARN_FORMAT = "$file:$line: $text" # The WARN_LOGFILE tag can be used to specify a file to which warning # and error messages should be written. If left blank the output is written # to stderr. WARN_LOGFILE = #--------------------------------------------------------------------------- # configuration options related to the input files #--------------------------------------------------------------------------- # The INPUT tag can be used to specify the files and/or directories that contain # documented source files. You may enter file names like "myfile.cpp" or # directories like "/usr/src/myproject". Separate the files or directories # with spaces. INPUT = doc/additional src/common/ # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is # also the default input encoding. Doxygen uses libiconv (or the iconv built # into libc) for the transcoding. See http://www.gnu.org/software/libiconv for # the list of possible encodings. INPUT_ENCODING = UTF-8 # If the value of the INPUT tag contains directories, you can use the # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank the following patterns are tested: # *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx # *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 FILE_PATTERNS = *.h # The RECURSIVE tag can be used to turn specify whether or not subdirectories # should be searched for input files as well. Possible values are YES and NO. # If left blank NO is used. RECURSIVE = NO # The EXCLUDE tag can be used to specify files and/or directories that should # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. EXCLUDE = # The EXCLUDE_SYMLINKS tag can be used select whether or not files or # directories that are symbolic links (a Unix filesystem feature) are excluded # from the input. EXCLUDE_SYMLINKS = NO # If the value of the INPUT tag contains directories, you can use the # EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude # certain files from those directories. Note that the wildcards are matched # against the file with absolute path, so to exclude all test directories # for example use the pattern */test/* EXCLUDE_PATTERNS = # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the # output. The symbol name can be a fully qualified name, a word, or if the # wildcard * is used, a substring. Examples: ANamespace, AClass, # AClass::ANamespace, ANamespace::*Test EXCLUDE_SYMBOLS = # The EXAMPLE_PATH tag can be used to specify one or more files or # directories that contain example code fragments that are included (see # the \include command). EXAMPLE_PATH = # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank all files are included. EXAMPLE_PATTERNS = # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be # searched for input files to be used with the \include or \dontinclude # commands irrespective of the value of the RECURSIVE tag. # Possible values are YES and NO. If left blank NO is used. EXAMPLE_RECURSIVE = NO # The IMAGE_PATH tag can be used to specify one or more files or # directories that contain image that are included in the documentation (see # the \image command). IMAGE_PATH = # The INPUT_FILTER tag can be used to specify a program that doxygen should # invoke to filter for each input file. Doxygen will invoke the filter program # by executing (via popen()) the command , where # is the value of the INPUT_FILTER tag, and is the name of an # input file. Doxygen will then use the output that the filter program writes # to standard output. # If FILTER_PATTERNS is specified, this tag will be # ignored. INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern # basis. # Doxygen will compare the file name with each pattern and apply the # filter if there is a match. # The filters are a list of the form: # pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further # info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER # is applied to all files. FILTER_PATTERNS = # If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using # INPUT_FILTER) will be used to filter the input files when producing source # files to browse (i.e. when SOURCE_BROWSER is set to YES). FILTER_SOURCE_FILES = NO #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- # If the SOURCE_BROWSER tag is set to YES then a list of source files will # be generated. Documented entities will be cross-referenced with these sources. # Note: To get rid of all source code in the generated output, make sure also # VERBATIM_HEADERS is set to NO. SOURCE_BROWSER = NO # Setting the INLINE_SOURCES tag to YES will include the body # of functions and classes directly in the documentation. INLINE_SOURCES = NO # Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct # doxygen to hide any special comment blocks from generated source code # fragments. Normal C and C++ comments will always remain visible. STRIP_CODE_COMMENTS = YES # If the REFERENCED_BY_RELATION tag is set to YES # then for each documented function all documented # functions referencing it will be listed. REFERENCED_BY_RELATION = NO # If the REFERENCES_RELATION tag is set to YES # then for each documented function all documented entities # called/used by that function will be listed. REFERENCES_RELATION = NO # If the REFERENCES_LINK_SOURCE tag is set to YES (the default) # and SOURCE_BROWSER tag is set to YES, then the hyperlinks from # functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will # link to the source code. # Otherwise they will link to the documentation. REFERENCES_LINK_SOURCE = YES # If the USE_HTAGS tag is set to YES then the references to source code # will point to the HTML generated by the htags(1) tool instead of doxygen # built-in source browser. The htags tool is part of GNU's global source # tagging system (see http://www.gnu.org/software/global/global.html). You # will need version 4.8.6 or higher. USE_HTAGS = NO # If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen # will generate a verbatim copy of the header file for each class for # which an include is specified. Set to NO to disable this. VERBATIM_HEADERS = YES #--------------------------------------------------------------------------- # configuration options related to the alphabetical class index #--------------------------------------------------------------------------- # If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index # of all compounds will be generated. Enable this if the project # contains a lot of classes, structs, unions or interfaces. ALPHABETICAL_INDEX = NO # If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then # the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns # in which this list will be split (can be a number in the range [1..20]) COLS_IN_ALPHA_INDEX = 5 # In case all classes in a project start with a common prefix, all # classes will be put under the same header in the alphabetical index. # The IGNORE_PREFIX tag can be used to specify one or more prefixes that # should be ignored while generating the index headers. IGNORE_PREFIX = #--------------------------------------------------------------------------- # configuration options related to the HTML output #--------------------------------------------------------------------------- # If the GENERATE_HTML tag is set to YES (the default) Doxygen will # generate HTML output. GENERATE_HTML = NO # The HTML_OUTPUT tag is used to specify where the HTML docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `html' will be used as the default path. HTML_OUTPUT = html # The HTML_FILE_EXTENSION tag can be used to specify the file extension for # each generated HTML page (for example: .htm,.php,.asp). If it is left blank # doxygen will generate files with .html extension. HTML_FILE_EXTENSION = .html # The HTML_HEADER tag can be used to specify a personal HTML header for # each generated HTML page. If it is left blank doxygen will generate a # standard header. HTML_HEADER = # The HTML_FOOTER tag can be used to specify a personal HTML footer for # each generated HTML page. If it is left blank doxygen will generate a # standard footer. HTML_FOOTER = # The HTML_STYLESHEET tag can be used to specify a user-defined cascading # style sheet that is used by each HTML page. It can be used to # fine-tune the look of the HTML output. If the tag is left blank doxygen # will generate a default style sheet. Note that doxygen will try to copy # the style sheet file to the HTML output directory, so don't put your own # stylesheet in the HTML output directory as well, or it will be erased! HTML_STYLESHEET = # If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, # files or namespaces will be aligned in HTML using tables. If set to # NO a bullet list will be used. HTML_ALIGN_MEMBERS = YES # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the # page has loaded. For this to work a browser that supports # JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox # Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). HTML_DYNAMIC_SECTIONS = NO # If the GENERATE_DOCSET tag is set to YES, additional index files # will be generated that can be used as input for Apple's Xcode 3 # integrated development environment, introduced with OSX 10.5 (Leopard). # To create a documentation set, doxygen will generate a Makefile in the # HTML output directory. Running make will produce the docset in that # directory and running "make install" will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find # it at startup. # See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information. GENERATE_DOCSET = NO # When GENERATE_DOCSET tag is set to YES, this tag determines the name of the # feed. A documentation feed provides an umbrella under which multiple # documentation sets from a single provider (such as a company or product suite) # can be grouped. DOCSET_FEEDNAME = "Doxygen generated docs" # When GENERATE_DOCSET tag is set to YES, this tag specifies a string that # should uniquely identify the documentation set bundle. This should be a # reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen # will append .docset to the name. DOCSET_BUNDLE_ID = org.doxygen.Project # If the GENERATE_HTMLHELP tag is set to YES, additional index files # will be generated that can be used as input for tools like the # Microsoft HTML help workshop to generate a compiled HTML help file (.chm) # of the generated HTML documentation. GENERATE_HTMLHELP = NO # If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can # be used to specify the file name of the resulting .chm file. You # can add a path in front of the file if the result should not be # written to the html output directory. CHM_FILE = # If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can # be used to specify the location (absolute path including file name) of # the HTML help compiler (hhc.exe). If non-empty doxygen will try to run # the HTML help compiler on the generated index.hhp. HHC_LOCATION = # If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag # controls if a separate .chi index file is generated (YES) or that # it should be included in the master .chm file (NO). GENERATE_CHI = NO # If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING # is used to encode HtmlHelp index (hhk), content (hhc) and project file # content. CHM_INDEX_ENCODING = # If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag # controls whether a binary table of contents is generated (YES) or a # normal table of contents (NO) in the .chm file. BINARY_TOC = NO # The TOC_EXPAND flag can be set to YES to add extra items for group members # to the contents of the HTML help documentation and to the tree view. TOC_EXPAND = NO # If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER # are set, an additional index file will be generated that can be used as input for # Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated # HTML documentation. GENERATE_QHP = NO # If the QHG_LOCATION tag is specified, the QCH_FILE tag can # be used to specify the file name of the resulting .qch file. # The path specified is relative to the HTML output folder. QCH_FILE = # The QHP_NAMESPACE tag specifies the namespace to use when generating # Qt Help Project output. For more information please see # http://doc.trolltech.com/qthelpproject.html#namespace QHP_NAMESPACE = # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating # Qt Help Project output. For more information please see # http://doc.trolltech.com/qthelpproject.html#virtual-folders QHP_VIRTUAL_FOLDER = doc # If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add. # For more information please see # http://doc.trolltech.com/qthelpproject.html#custom-filters QHP_CUST_FILTER_NAME = # The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see # Qt Help Project / Custom Filters. QHP_CUST_FILTER_ATTRS = # The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's # filter section matches. # Qt Help Project / Filter Attributes. QHP_SECT_FILTER_ATTRS = # If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can # be used to specify the location of Qt's qhelpgenerator. # If non-empty doxygen will try to run qhelpgenerator on the generated # .qhp file. QHG_LOCATION = # The DISABLE_INDEX tag can be used to turn on/off the condensed index at # top of each HTML page. The value NO (the default) enables the index and # the value YES disables it. DISABLE_INDEX = NO # This tag can be used to set the number of enum values (range [1..20]) # that doxygen will group on one line in the generated HTML documentation. ENUM_VALUES_PER_LINE = 4 # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index # structure should be generated to display hierarchical information. # If the tag value is set to YES, a side panel will be generated # containing a tree-like index structure (just like the one that # is generated for HTML Help). For this to work a browser that supports # JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). # Windows users are probably better off using the HTML help feature. GENERATE_TREEVIEW = NO # By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, # and Class Hierarchy pages using a tree view instead of an ordered list. USE_INLINE_TREES = NO # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be # used to set the initial width (in pixels) of the frame in which the tree # is shown. TREEVIEW_WIDTH = 250 # Use this tag to change the font size of Latex formulas included # as images in the HTML documentation. The default is 10. Note that # when you change the font size after a successful doxygen run you need # to manually remove any form_*.png images from the HTML output directory # to force them to be regenerated. FORMULA_FONTSIZE = 10 # When the SEARCHENGINE tag is enable doxygen will generate a search box for the HTML output. The underlying search engine uses javascript # and DHTML and should work on any modern browser. Note that when using HTML help (GENERATE_HTMLHELP) or Qt help (GENERATE_QHP) # there is already a search function so this one should typically # be disabled. SEARCHENGINE = YES #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- # If the GENERATE_LATEX tag is set to YES (the default) Doxygen will # generate Latex output. GENERATE_LATEX = YES # The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `latex' will be used as the default path. LATEX_OUTPUT = latex # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be # invoked. If left blank `latex' will be used as the default command name. LATEX_CMD_NAME = latex # The MAKEINDEX_CMD_NAME tag can be used to specify the command name to # generate index for LaTeX. If left blank `makeindex' will be used as the # default command name. MAKEINDEX_CMD_NAME = makeindex # If the COMPACT_LATEX tag is set to YES Doxygen generates more compact # LaTeX documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_LATEX = YES # The PAPER_TYPE tag can be used to set the paper type that is used # by the printer. Possible values are: a4, a4wide, letter, legal and # executive. If left blank a4wide will be used. PAPER_TYPE = a4wide # The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX # packages that should be included in the LaTeX output. EXTRA_PACKAGES = colortbl # for \cellcolor command # The LATEX_HEADER tag can be used to specify a personal LaTeX header for # the generated latex document. The header should contain everything until # the first chapter. If it is left blank doxygen will generate a # standard header. Notice: only use this tag if you know what you are doing! LATEX_HEADER = # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated # is prepared for conversion to pdf (using ps2pdf). The pdf file will # contain links (just like the HTML output) instead of page references # This makes the output suitable for online browsing using a pdf viewer. PDF_HYPERLINKS = YES # If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of # plain latex in the generated Makefile. Set this option to YES to get a # higher quality PDF documentation. USE_PDFLATEX = YES # If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. # command to the generated LaTeX files. This will instruct LaTeX to keep # running if errors occur, instead of asking the user for help. # This option is also used when generating formulas in HTML. LATEX_BATCHMODE = NO # If LATEX_HIDE_INDICES is set to YES then doxygen will not # include the index chapters (such as File Index, Compound Index, etc.) # in the output. LATEX_HIDE_INDICES = YES # If LATEX_SOURCE_CODE is set to YES then doxygen will include source code with syntax highlighting in the LaTeX output. Note that which sources are shown also depends on other settings such as SOURCE_BROWSER. LATEX_SOURCE_CODE = NO #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- # If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output # The RTF output is optimized for Word 97 and may not look very pretty with # other RTF readers or editors. GENERATE_RTF = NO # The RTF_OUTPUT tag is used to specify where the RTF docs will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `rtf' will be used as the default path. RTF_OUTPUT = rtf # If the COMPACT_RTF tag is set to YES Doxygen generates more compact # RTF documents. This may be useful for small projects and may help to # save some trees in general. COMPACT_RTF = NO # If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated # will contain hyperlink fields. The RTF file will # contain links (just like the HTML output) instead of page references. # This makes the output suitable for online browsing using WORD or other # programs which support those fields. # Note: wordpad (write) and others do not support links. RTF_HYPERLINKS = NO # Load stylesheet definitions from file. Syntax is similar to doxygen's # config file, i.e. a series of assignments. You only have to provide # replacements, missing definitions are set to their default value. RTF_STYLESHEET_FILE = # Set optional variables used in the generation of an rtf document. # Syntax is similar to doxygen's config file. RTF_EXTENSIONS_FILE = #--------------------------------------------------------------------------- # configuration options related to the man page output #--------------------------------------------------------------------------- # If the GENERATE_MAN tag is set to YES (the default) Doxygen will # generate man pages GENERATE_MAN = YES # The MAN_OUTPUT tag is used to specify where the man pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `man' will be used as the default path. MAN_OUTPUT = man # The MAN_EXTENSION tag determines the extension that is added to # the generated man pages (default is the subroutine's section .3) MAN_EXTENSION = .3 # If the MAN_LINKS tag is set to YES and Doxygen generates man output, # then it will generate one additional man file for each entity # documented in the real man page(s). These additional files # only source the real man page, but without them the man command # would be unable to find the correct page. The default is NO. MAN_LINKS = NO #--------------------------------------------------------------------------- # configuration options related to the XML output #--------------------------------------------------------------------------- # If the GENERATE_XML tag is set to YES Doxygen will # generate an XML file that captures the structure of # the code including all documentation. GENERATE_XML = NO # The XML_OUTPUT tag is used to specify where the XML pages will be put. # If a relative path is entered the value of OUTPUT_DIRECTORY will be # put in front of it. If left blank `xml' will be used as the default path. XML_OUTPUT = xml # The XML_SCHEMA tag can be used to specify an XML schema, # which can be used by a validating XML parser to check the # syntax of the XML files. XML_SCHEMA = # The XML_DTD tag can be used to specify an XML DTD, # which can be used by a validating XML parser to check the # syntax of the XML files. XML_DTD = # If the XML_PROGRAMLISTING tag is set to YES Doxygen will # dump the program listings (including syntax highlighting # and cross-referencing information) to the XML output. Note that # enabling this will significantly increase the size of the XML output. XML_PROGRAMLISTING = YES #--------------------------------------------------------------------------- # configuration options for the AutoGen Definitions output #--------------------------------------------------------------------------- # If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will # generate an AutoGen Definitions (see autogen.sf.net) file # that captures the structure of the code including all # documentation. Note that this feature is still experimental # and incomplete at the moment. GENERATE_AUTOGEN_DEF = NO #--------------------------------------------------------------------------- # configuration options related to the Perl module output #--------------------------------------------------------------------------- # If the GENERATE_PERLMOD tag is set to YES Doxygen will # generate a Perl module file that captures the structure of # the code including all documentation. Note that this # feature is still experimental and incomplete at the # moment. GENERATE_PERLMOD = NO # If the PERLMOD_LATEX tag is set to YES Doxygen will generate # the necessary Makefile rules, Perl scripts and LaTeX code to be able # to generate PDF and DVI output from the Perl module output. PERLMOD_LATEX = NO # If the PERLMOD_PRETTY tag is set to YES the Perl module output will be # nicely formatted so it can be parsed by a human reader. # This is useful # if you want to understand what is going on. # On the other hand, if this # tag is set to NO the size of the Perl module output will be much smaller # and Perl will parse it just the same. PERLMOD_PRETTY = YES # The names of the make variables in the generated doxyrules.make file # are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. # This is useful so different doxyrules.make files included by the same # Makefile don't overwrite each other's variables. PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- # Configuration options related to the preprocessor #--------------------------------------------------------------------------- # If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will # evaluate all C-preprocessor directives found in the sources and include # files. ENABLE_PREPROCESSING = NO # If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro # names in the source code. If set to NO (the default) only conditional # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. MACRO_EXPANSION = NO # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the # PREDEFINED and EXPAND_AS_DEFINED tags. EXPAND_ONLY_PREDEF = NO # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files # in the INCLUDE_PATH (see below) will be search if a #include is found. SEARCH_INCLUDES = YES # The INCLUDE_PATH tag can be used to specify one or more directories that # contain include files that are not input files but should be processed by # the preprocessor. INCLUDE_PATH = # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the # directories. If left blank, the patterns specified with FILE_PATTERNS will # be used. INCLUDE_FILE_PATTERNS = # The PREDEFINED tag can be used to specify one or more macro names that # are defined before the preprocessor is started (similar to the -D option of # gcc). The argument of the tag is a list of macros of the form: name # or name=definition (no spaces). If the definition and the = are # omitted =1 is assumed. To prevent a macro definition from being # undefined via #undef or recursively expanded use the := operator # instead of the = operator. PREDEFINED = # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. # The macro definition that is found in the sources will be used. # Use the PREDEFINED tag if you want to use a different macro definition. EXPAND_AS_DEFINED = # If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then # doxygen's preprocessor will remove all function-like macros that are alone # on a line, have an all uppercase name, and do not end with a semicolon. Such # function macros are typically used for boiler-plate code, and will confuse # the parser if not removed. SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- # Configuration::additions related to external references #--------------------------------------------------------------------------- # The TAGFILES option can be used to specify one or more tagfiles. # Optionally an initial location of the external documentation # can be added for each tagfile. The format of a tag file without # this location is as follows: # # TAGFILES = file1 file2 ... # Adding location for the tag files is done as follows: # # TAGFILES = file1=loc1 "file2 = loc2" ... # where "loc1" and "loc2" can be relative or absolute paths or # URLs. If a location is present for each tag, the installdox tool # does not have to be run to correct the links. # Note that each tag file must have a unique name # (where the name does NOT include the path) # If a tag file is not located in the directory in which doxygen # is run, you must also specify the path to the tagfile here. TAGFILES = # When a file name is specified after GENERATE_TAGFILE, doxygen will create # a tag file that is based on the input files it reads. GENERATE_TAGFILE = # If the ALLEXTERNALS tag is set to YES all external classes will be listed # in the class index. If set to NO only the inherited external classes # will be listed. ALLEXTERNALS = NO # If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed # in the modules index. If set to NO, only the current project's groups will # be listed. EXTERNAL_GROUPS = YES # The PERL_PATH should be the absolute path and name of the perl script # interpreter (i.e. the result of `which perl'). PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- # Configuration options related to the dot tool #--------------------------------------------------------------------------- # If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will # generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base # or super classes. Setting the tag to NO turns the diagrams off. Note that # this option is superseded by the HAVE_DOT option below. This is only a # fallback. It is recommended to install and use dot, since it yields more # powerful graphs. CLASS_DIAGRAMS = YES # You can define message sequence charts within doxygen comments using the \msc # command. Doxygen will then run the mscgen tool (see # http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the # documentation. The MSCGEN_PATH tag allows you to specify the directory where # the mscgen tool resides. If left empty the tool is assumed to be found in the # default search path. MSCGEN_PATH = # If set to YES, the inheritance and collaboration graphs will hide # inheritance and usage relations if the target is undocumented # or is not a class. HIDE_UNDOC_RELATIONS = YES # If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is # available from the path. This tool is part of Graphviz, a graph visualization # toolkit from AT&T and Lucent Bell Labs. The other options in this section # have no effect if this option is set to NO (the default) HAVE_DOT = NO # By default doxygen will write a font called FreeSans.ttf to the output # directory and reference it in all dot files that doxygen generates. This # font does not include all possible unicode characters however, so when you need # these (or just want a differently looking font) you can specify the font name # using DOT_FONTNAME. You need need to make sure dot is able to find the font, # which can be done by putting it in a standard location or by setting the # DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory # containing the font. DOT_FONTNAME = FreeSans # The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. # The default size is 10pt. DOT_FONTSIZE = 10 # By default doxygen will tell dot to use the output directory to look for the # FreeSans.ttf font (which doxygen will put there itself). If you specify a # different font using DOT_FONTNAME you can set the path where dot # can find it using this tag. DOT_FONTPATH = # If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect inheritance relations. Setting this tag to YES will force the # the CLASS_DIAGRAMS tag to NO. CLASS_GRAPH = YES # If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect implementation dependencies (inheritance, containment, and # class references variables) of the class with other documented classes. COLLABORATION_GRAPH = YES # If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen # will generate a graph for groups, showing the direct groups dependencies GROUP_GRAPHS = YES # If the UML_LOOK tag is set to YES doxygen will generate inheritance and # collaboration diagrams in a style similar to the OMG's Unified Modeling # Language. UML_LOOK = NO # If set to YES, the inheritance and collaboration graphs will show the # relations between templates and their instances. TEMPLATE_RELATIONS = NO # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT # tags are set to YES then doxygen will generate a graph for each documented # file showing the direct and indirect include dependencies of the file with # other documented files. INCLUDE_GRAPH = YES # If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and # HAVE_DOT tags are set to YES then doxygen will generate a graph for each # documented header file showing the documented files that directly or # indirectly include this file. INCLUDED_BY_GRAPH = YES # If the CALL_GRAPH and HAVE_DOT options are set to YES then # doxygen will generate a call dependency graph for every global function # or class method. Note that enabling this option will significantly increase # the time of a run. So in most cases it will be better to enable call graphs # for selected functions only using the \callgraph command. CALL_GRAPH = NO # If the CALLER_GRAPH and HAVE_DOT tags are set to YES then # doxygen will generate a caller dependency graph for every global function # or class method. Note that enabling this option will significantly increase # the time of a run. So in most cases it will be better to enable caller # graphs for selected functions only using the \callergraph command. CALLER_GRAPH = NO # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen # will graphical hierarchy of all classes instead of a textual one. GRAPHICAL_HIERARCHY = YES # If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES # then doxygen will show the dependencies a directory has on other directories # in a graphical way. The dependency relations are determined by the #include # relations between the files in the directories. DIRECTORY_GRAPH = YES # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images # generated by dot. Possible values are png, jpg, or gif # If left blank png will be used. DOT_IMAGE_FORMAT = png # The tag DOT_PATH can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found in the path. DOT_PATH = # The DOTFILE_DIRS tag can be used to specify one or more directories that # contain dot files that are included in the documentation (see the # \dotfile command). DOTFILE_DIRS = # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of # nodes that will be shown in the graph. If the number of nodes in a graph # becomes larger than this value, doxygen will truncate the graph, which is # visualized by representing a node as a red box. Note that doxygen if the # number of direct children of the root node in a graph is already larger than # DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note # that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. DOT_GRAPH_MAX_NODES = 50 # The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the # graphs generated by dot. A depth value of 3 means that only nodes reachable # from the root by following a path via at most 3 edges will be shown. Nodes # that lay further from the root node will be omitted. Note that setting this # option to 1 or 2 may greatly reduce the computation time needed for large # code bases. Also note that the size of a graph can be further restricted by # DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. MAX_DOT_GRAPH_DEPTH = 0 # Set the DOT_TRANSPARENT tag to YES to generate images with a transparent # background. This is disabled by default, because dot on Windows does not # seem to support this out of the box. Warning: Depending on the platform used, # enabling this option may lead to badly anti-aliased labels on the edges of # a graph (i.e. they become hard to read). DOT_TRANSPARENT = NO # Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output # files in one run (i.e. multiple -o and -T options on the command line). This # makes dot run faster, but since only newer versions of dot (>1.8.10) # support this, this feature is disabled by default. DOT_MULTI_TARGETS = YES # If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will # generate a legend page explaining the meaning of the various boxes and # arrows in the dot generated graphs. GENERATE_LEGEND = YES # If the DOT_CLEANUP tag is set to YES (the default) Doxygen will # remove the intermediate dot files that are used to generate # the various graphs. DOT_CLEANUP = YES libsysactivity-0.6.5/COPYING0000644000175000017500000006350212220245547014640 0ustar hazelhazel GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! libsysactivity-0.6.5/CMakeLists.txt0000644000175000017500000000242612220245547016343 0ustar hazelhazel cmake_minimum_required(VERSION 2.6.0) project(libsysactivity C) set(LIBSA_VERSION "0.6.5") set(CMAKE_VERBOSE_MAKEFILE TRUE) enable_testing() if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "/usr") message(STATUS "CMAKE_INSTALL_PREFIX is not set, using default value: ${CMAKE_INSTALL_PREFIX}") endif (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) # Adding compiler and linker flags add_definitions(-Wall) # Checking if the -Wlogical-op flag is available include(CheckCCompilerFlag) check_c_compiler_flag("-Wlogical-op" HAS_LOGICAL_OP_FLAG) if (HAS_LOGICAL_OP_FLAG) add_definitions(-Wlogical-op) endif (HAS_LOGICAL_OP_FLAG) # Checking if the visibility flag is available check_c_compiler_flag("-fvisibility=hidden" HAS_VISIBILITY_FLAG) if (HAS_VISIBILITY_FLAG) add_definitions(-fvisibility=hidden) endif (HAS_VISIBILITY_FLAG) # Adding release flags check_c_compiler_flag("-flto" HAS_FLTO_FLAG) if (HAS_FLTO_FLAG) set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -flto") # "Combining -flto with -g is currently experimental and expected to produce wrong results." endif (HAS_FLTO_FLAG) # Adding debug flags set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wextra -Wshadow") add_subdirectory(src) add_subdirectory(cmake) add_subdirectory(test EXCLUDE_FROM_ALL) libsysactivity-0.6.5/CHANGELOG0000644000175000017500000001053412220245547015014 0ustar hazelhazel libsysactivity 0.6.5 (released 2013-09-24) * Replacing all fflush() with fclose()+fopen() * Only use FLTO on release builds. * The kinfo_proc2 interface has been removed from OpenBSD so use the correct replacement: kinfo_proc * Removed useless visibility attributes libsysactivity 0.6.4 (released 2012-10-22) * Linux version of sa_reset_net_interfaces() was not realoading data. libsysactivity 0.6.3 (released 2012-05-21) * Minor fixes in linux/network and test code. libsysactivity 0.6.2 (released 2011-06-01) * Added kernel 3.x compatibility. * Linux/cpu: Now the code is hot-plug and hot-remove safe. * tests: Don't suppose there are any swap device. * Stress tests updated. libsysactivity 0.6.1 (released 2011-04-13) * Added __restrict__ keyword. * Remove SA_SPECIFIC_* macros. * Added common/global.h * Linux version for sa_get_disks_ids() was not counting the number of disks properly. Fixed. * Fixed an error on parsing the disk statistics from linux sys filesystem. libsysactivity 0.6.0 (released 2011-02-18) * Added full support for DragonFly (>= 2.8.2). * API: "data_storage" identifier renamed to just "disk". * API: struct process split on struct process and struct process_activity. Added function sa_get_processes_activity(). See the documentation for more details. * API: Removed sa_get_processes(). * API: Changing type of dst_size and written in process funtions from pid_t to uint32_t. * API: Swap code moved to swap.h and swap.c files. * API: Added sa_reset_x(). It should be called everytime you want fresh statistics. * API: Added sa_get_x_ids(). * tests: Don't need to install the library in order to execute the tests anymore. * tests: Don't exit() on error so it's possible to detect following errors. * tests: Added tests for fields: nice, sys_time and user_time. * GCC: Added function attributes: hot and nonnull. * GCC: Added flags: -flto and -Wlogical-op when available (>= 4.5). * FreeBSD: A process can be created between two contiguous sysctl() calls. Fixed. * *BSD: Found a bug on machines with big memory. * Linux: Fixed a bug when tring to get all swaps (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=593018). * Some minor fixes. libsysactivity 0.5.4 (released 2010-07-25) * Added unit tests. See TEST file for instructions. * *BSD: percentages() replaced by a 3-clause BSD version. * docs: added detailed information about the returned error codes. * Linux/networking: selfmade strlcpy was null-terminating before the rest of data was parsed. Fixed. libsysactivity 0.5.3 (released 2010-06-01) * Added support for Debian GNU/kFreeBSD. It's almost the same code as FreeBSD. * Linux: Now the kernel version is obtained at startup and checked on each open_XXX * *scanf and *printf are too slow. Manual parsing instead. * Linux: Many small code optimizations. * Linux: Avoid to seek() to a hard-coded position. * strncpy is not safe enough so now using own strlcpy. * Added stress tests so it's easier to measure how fast is the code. libsysactivity 0.5.2 (released 2010-05-15) * Changed FSF address to the new one (Thanks to Niels Thykier). * Added LIB_SUFFIX to the installation path. * Better documentation schema. * Added cmake configuration and version files so the package can be properly found. libsysactivity 0.5.1 (released 2010-04-08) * Device names length fixed to system limits. * Added visibility attributes to functions, structs, enums... * Now CMAKE_INSTALL_PREFIX is correctly handled. libsysactivity 0.5.0 (released 2010-02-25) * Added script release.sh * Various optimizations and fixes in thread-storage initializations. * Added sa_get_processes_ids() for better processes retrieval. * OpenBSD and NetBSD: Improved keys handling. * NetBSD: Calling realloc() only when needed. * OpenBSD support completed. libsysactivity 0.4.0 (released 2010-01-14) * Finished support for NetBSD * Fixed compilation under some OS libsysactivity 0.3.1 (released 2010-01-04) * Improved count_X API * Better support for NetBSD * Improved building structure libsysactivity 0.3.0 (released 2009-09-30) * Restructured CMakeList files * Added support for SunOS. * Fixed compilation under FreeBSD libsysactivity 0.2.1 (released 2009-09-20) * Gathered headers into libsysactivity.h * Documentation written for doxygen. * CMakeLists.txt splitted. * Linux: fixed compilation under 64 bits. * Added sa_ prefix to function and structure names.