diff --git a/Makefile.am b/Makefile.am index b3558776..d535e49e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -179,8 +179,8 @@ proc_libprocps_la_SOURCES = \ proc/vmstat.h \ proc/wchan.c \ proc/wchan.h \ - proc/whattime.c \ - proc/whattime.h + proc/uptime.c \ + proc/uptime.h proc_libprocps_la_includedir = $(includedir)/proc/ proc_libprocps_la_include_HEADERS = \ diff --git a/proc/meminfo.c b/proc/meminfo.c index dee1fac6..9102eccc 100644 --- a/proc/meminfo.c +++ b/proc/meminfo.c @@ -1,4 +1,24 @@ - +/* + * meminfo - Memory statistics part of procps + * + * Copyright (C) 1992-1998 by Michael K. Johnson + * Copyright (C) 1998-2003 Albert Cahalan + * Copyright (C) 2015 Craig Small + * + * 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 diff --git a/proc/meminfo.h b/proc/meminfo.h index 8debb5c7..11eb7401 100644 --- a/proc/meminfo.h +++ b/proc/meminfo.h @@ -1,6 +1,9 @@ /* - * libprocps - Library to read proc filesystem - * meminfo - Parse /proc/meminfo + * meminfo - Memory statistics part of procps + * + * Copyright (C) 1992-1998 by Michael K. Johnson + * Copyright (C) 1998-2003 Albert Cahalan + * Copyright (C) 2015 Craig Small * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/proc/vmstat.c b/proc/vmstat.c index fc432a2c..3f79d028 100644 --- a/proc/vmstat.c +++ b/proc/vmstat.c @@ -25,7 +25,7 @@ struct mem_table_struct { unsigned long *slot; }; -struct vmstat_info { +struct procps_vmstat { int refcount; int vmstat_fd; struct vmstat_data data; @@ -39,12 +39,12 @@ struct vmstat_info { * The initial refcount is 1, and needs to be decremented * to release the resources of the structure. * - * Returns: a new vmstat info container + * Returns: a new procps_vmstat container */ -PROCPS_EXPORT int procps_vmstat_new(struct vmstat_info **info) +PROCPS_EXPORT int procps_vmstat_new(struct procps_vmstat **info) { - struct vmstat_info *v; - v = calloc(1, sizeof(struct vmstat_info)); + struct procps_vmstat *v; + v = calloc(1, sizeof(struct procps_vmstat)); if (!v) return -ENOMEM; @@ -59,8 +59,10 @@ PROCPS_EXPORT int procps_vmstat_new(struct vmstat_info **info) * * Read the data out of /proc/vmstat putting the information * into the supplied info structure + * + * Returns: 0 on success, negative on error */ -PROCPS_EXPORT int procps_vmstat_read(struct vmstat_info *info) +PROCPS_EXPORT int procps_vmstat_read(struct procps_vmstat *info) { char buf[8192]; char *head, *tail; @@ -114,7 +116,7 @@ PROCPS_EXPORT int procps_vmstat_read(struct vmstat_info *info) return 0; } -PROCPS_EXPORT struct vmstat_info *procps_vmstat_ref(struct vmstat_info *info) +PROCPS_EXPORT struct procps_vmstat *procps_vmstat_ref(struct procps_vmstat *info) { if (info == NULL) return NULL; @@ -122,7 +124,7 @@ PROCPS_EXPORT struct vmstat_info *procps_vmstat_ref(struct vmstat_info *info) return info; } -PROCPS_EXPORT struct vmstat_info *procps_vmstat_unref(struct vmstat_info *info) +PROCPS_EXPORT struct procps_vmstat *procps_vmstat_unref(struct procps_vmstat *info) { if (info == NULL) return NULL; @@ -135,17 +137,17 @@ PROCPS_EXPORT struct vmstat_info *procps_vmstat_unref(struct vmstat_info *info) /* Accessor functions */ PROCPS_EXPORT unsigned long procps_vmstat_get( - struct vmstat_info *info, + struct procps_vmstat *info, enum vmstat_item item) { switch(item) { - case VMSTAT_INFO_PGPGIN: + case PROCPS_VMSTAT_PGPGIN: return info->data.pgpgin; - case VMSTAT_INFO_PGPGOUT: + case PROCPS_VMSTAT_PGPGOUT: return info->data.pgpgout; - case VMSTAT_INFO_PSWPIN: + case PROCPS_VMSTAT_PSWPIN: return info->data.pswpin; - case VMSTAT_INFO_PSWPOUT: + case PROCPS_VMSTAT_PSWPOUT: return info->data.pswpout; } return 0; diff --git a/proc/vmstat.h b/proc/vmstat.h index e0cbfae1..9f64d8b1 100644 --- a/proc/vmstat.h +++ b/proc/vmstat.h @@ -27,18 +27,19 @@ __BEGIN_DECLS -struct vmstat_info; -int procps_vmstat_new(struct vmstat_info **info); -int procps_vmstat_read(struct vmstat_info *info); -struct vmstat_info *procps_vmstat_ref(struct vmstat_info *info); -struct vmstat_info *procps_vmstat_unref(struct vmstat_info *info); +struct procps_vmstat; +int procps_vmstat_new(struct procps_vmstat **info); +int procps_vmstat_read(struct procps_vmstat *info); +struct procps_vmstat *procps_vmstat_ref(struct procps_vmstat *info); +struct procps_vmstat *procps_vmstat_unref(struct procps_vmstat *info); + enum vmstat_item { - VMSTAT_INFO_PGPGIN, - VMSTAT_INFO_PGPGOUT, - VMSTAT_INFO_PSWPIN, - VMSTAT_INFO_PSWPOUT + PROCPS_VMSTAT_PGPGIN, + PROCPS_VMSTAT_PGPGOUT, + PROCPS_VMSTAT_PSWPIN, + PROCPS_VMSTAT_PSWPOUT }; -unsigned long procps_vmstat_get(struct vmstat_info *info, enum vmstat_item item); +unsigned long procps_vmstat_get(struct procps_vmstat *info, enum vmstat_item item); __END_DECLS #endif diff --git a/vmstat.c b/vmstat.c index 480bb89e..e3037c68 100644 --- a/vmstat.c +++ b/vmstat.c @@ -297,7 +297,7 @@ static void new_format(void) struct tm *tm_ptr; time_t the_time; char timebuf[32]; - struct vmstat_info *vm_info; + struct procps_vmstat *vm_info; struct procps_stat_info *sys_info; sleep_half = (sleep_time / 2); @@ -339,10 +339,10 @@ static void new_format(void) unitConvert(kb_swap_used), unitConvert(kb_main_free), unitConvert(a_option?kb_inactive:kb_main_buffers), unitConvert(a_option?kb_active:kb_main_cached), - (unsigned)( (unitConvert(procps_vmstat_get(vm_info, VMSTAT_INFO_PSWPIN) * kb_per_page) * hz + divo2) / Div ), - (unsigned)( (unitConvert(procps_vmstat_get(vm_info, VMSTAT_INFO_PSWPOUT) * kb_per_page) * hz + divo2) / Div ), - (unsigned)( (procps_vmstat_get(vm_info, VMSTAT_INFO_PGPGIN) * hz + divo2) / Div ), - (unsigned)( (procps_vmstat_get(vm_info, VMSTAT_INFO_PGPGOUT) * hz + divo2) / Div ), + (unsigned)( (unitConvert(procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPIN) * kb_per_page) * hz + divo2) / Div ), + (unsigned)( (unitConvert(procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPOUT) * kb_per_page) * hz + divo2) / Div ), + (unsigned)( (procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGIN) * hz + divo2) / Div ), + (unsigned)( (procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGOUT) * hz + divo2) / Div ), (unsigned)( (procps_stat_get(sys_info, PROCPS_STAT_INTERRUPTS) * hz + divo2) / Div ), (unsigned)( (procps_stat_get(sys_info, PROCPS_STAT_CONTEXT) * hz + divo2) / Div ), (unsigned)( (100*duse + divo2) / Div ), @@ -382,10 +382,10 @@ static void new_format(void) if (procps_vmstat_read(vm_info) < 0) xerrx(EXIT_FAILURE, _("Unable to read vmstat information")); - pgpgin[tog] = procps_vmstat_get(vm_info, VMSTAT_INFO_PGPGIN); - pgpgout[tog] = procps_vmstat_get(vm_info, VMSTAT_INFO_PGPGOUT); - pswpin[tog] = procps_vmstat_get(vm_info, VMSTAT_INFO_PSWPIN); - pswpout[tog] = procps_vmstat_get(vm_info, VMSTAT_INFO_PSWPOUT); + pgpgin[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGIN); + pgpgout[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGOUT); + pswpin[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPIN); + pswpout[tog] = procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPOUT); if (t_option) { @@ -815,7 +815,7 @@ static void disksum_format(void) static void sum_format(void) { struct procps_stat_info *sys_info; - struct vmstat_info *vm_info; + struct procps_vmstat *vm_info; meminfo(); @@ -852,10 +852,10 @@ static void sum_format(void) printf(_("%13lld stolen cpu ticks\n"), procps_stat_get_cpu(sys_info, PROCPS_CPU_STOLEN)); printf(_("%13lld non-nice guest cpu ticks\n"), procps_stat_get_cpu(sys_info, PROCPS_CPU_GUEST)); printf(_("%13lld nice guest cpu ticks\n"), procps_stat_get_cpu(sys_info, PROCPS_CPU_GNICE)); - printf(_("%13lu pages paged in\n"), procps_vmstat_get(vm_info, VMSTAT_INFO_PGPGIN)); - printf(_("%13lu pages paged out\n"), procps_vmstat_get(vm_info, VMSTAT_INFO_PGPGOUT)); - printf(_("%13lu pages swapped in\n"), procps_vmstat_get(vm_info, VMSTAT_INFO_PSWPIN)); - printf(_("%13lu pages swapped out\n"), procps_vmstat_get(vm_info, VMSTAT_INFO_PSWPOUT)); + printf(_("%13lu pages paged in\n"), procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGIN)); + printf(_("%13lu pages paged out\n"), procps_vmstat_get(vm_info, PROCPS_VMSTAT_PGPGOUT)); + printf(_("%13lu pages swapped in\n"), procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPIN)); + printf(_("%13lu pages swapped out\n"), procps_vmstat_get(vm_info, PROCPS_VMSTAT_PSWPOUT)); printf(_("%13u interrupts\n"), procps_stat_get(sys_info, PROCPS_STAT_INTERRUPTS)); printf(_("%13u CPU context switches\n"), procps_stat_get(sys_info, PROCPS_STAT_CONTEXT)); printf(_("%13u boot time\n"), procps_stat_get(sys_info, PROCPS_STAT_BTIME));