ia64/xen-unstable

changeset 6339:f51fe43c5d1c

Merge libxenstat and xentop.
author cl349@firebug.cl.cam.ac.uk
date Mon Aug 22 21:54:28 2005 +0000 (2005-08-22)
parents f3859247f2ed 59a6a0350158
children 43d91cbb1bfb 2d3a7be68ba3
files .hgignore Config.mk Makefile buildconfigs/Rules.mk docs/src/user.tex extras/mini-os/include/time.h extras/mini-os/kernel.c extras/mini-os/time.c linux-2.6-xen-sparse/arch/xen/Kconfig linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xen0_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xenU_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_32 linux-2.6-xen-sparse/arch/xen/configs/xen_defconfig_x86_64 linux-2.6-xen-sparse/arch/xen/i386/Kconfig linux-2.6-xen-sparse/arch/xen/i386/kernel/Makefile linux-2.6-xen-sparse/arch/xen/i386/kernel/cpu/common.c linux-2.6-xen-sparse/arch/xen/i386/kernel/head.S linux-2.6-xen-sparse/arch/xen/i386/kernel/i386_ksyms.c linux-2.6-xen-sparse/arch/xen/i386/kernel/ioport.c linux-2.6-xen-sparse/arch/xen/i386/kernel/ldt.c linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c linux-2.6-xen-sparse/arch/xen/i386/kernel/smp.c linux-2.6-xen-sparse/arch/xen/i386/kernel/smpboot.c linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c linux-2.6-xen-sparse/arch/xen/i386/mm/highmem.c linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c linux-2.6-xen-sparse/arch/xen/i386/mm/init.c linux-2.6-xen-sparse/arch/xen/i386/mm/ioremap.c linux-2.6-xen-sparse/arch/xen/i386/mm/pgtable.c linux-2.6-xen-sparse/arch/xen/i386/pci/Makefile linux-2.6-xen-sparse/arch/xen/kernel/evtchn.c linux-2.6-xen-sparse/arch/xen/kernel/reboot.c linux-2.6-xen-sparse/arch/xen/kernel/skbuff.c linux-2.6-xen-sparse/arch/xen/x86_64/Kconfig linux-2.6-xen-sparse/arch/xen/x86_64/Makefile linux-2.6-xen-sparse/arch/xen/x86_64/ia32/Makefile linux-2.6-xen-sparse/arch/xen/x86_64/kernel/Makefile linux-2.6-xen-sparse/arch/xen/x86_64/kernel/apic.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/e820.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/entry.S linux-2.6-xen-sparse/arch/xen/x86_64/kernel/pci-nommu.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/process.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup64.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/smpboot.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/vsyscall.c linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c linux-2.6-xen-sparse/arch/xen/x86_64/mm/ioremap.c linux-2.6-xen-sparse/arch/xen/x86_64/pci/Makefile linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/drivers/xen/blkback/Makefile linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c linux-2.6-xen-sparse/drivers/xen/blkback/common.h linux-2.6-xen-sparse/drivers/xen/blkback/interface.c linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c linux-2.6-xen-sparse/drivers/xen/blkfront/block.h linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap.h linux-2.6-xen-sparse/drivers/xen/blktap/blktap_controlmsg.c linux-2.6-xen-sparse/drivers/xen/blktap/blktap_userdev.c linux-2.6-xen-sparse/drivers/xen/console/console.c linux-2.6-xen-sparse/drivers/xen/netback/common.h linux-2.6-xen-sparse/drivers/xen/netback/interface.c linux-2.6-xen-sparse/drivers/xen/netback/netback.c linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c linux-2.6-xen-sparse/drivers/xen/usbback/usbback.c linux-2.6-xen-sparse/drivers/xen/usbfront/usbfront.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.h linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c linux-2.6-xen-sparse/include/asm-xen/asm-i386/desc.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/dma-mapping.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/fixmap.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/mmu_context.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pci.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgalloc.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-2level.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable-3level.h linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/desc.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/dma-mapping.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/pci.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/pgtable.h linux-2.6-xen-sparse/include/asm-xen/balloon.h linux-2.6-xen-sparse/include/asm-xen/hypervisor.h linux-2.6-xen-sparse/include/asm-xen/xenbus.h linux-2.6-xen-sparse/include/linux/highmem.h linux-2.6-xen-sparse/include/linux/mm.h linux-2.6-xen-sparse/mm/highmem.c linux-2.6-xen-sparse/mm/memory.c tools/Makefile tools/Rules.mk tools/console/daemon/io.c tools/debugger/libxendebug/xendebug.c tools/debugger/libxendebug/xendebug.h tools/debugger/pdb/Domain.ml tools/debugger/pdb/Domain.mli tools/debugger/pdb/Makefile tools/debugger/pdb/PDB.ml tools/debugger/pdb/Process.ml tools/debugger/pdb/Process.mli tools/debugger/pdb/debugger.ml tools/debugger/pdb/linux-2.6-module/debug.c tools/debugger/pdb/linux-2.6-module/module.c tools/debugger/pdb/linux-2.6-module/pdb_debug.h tools/debugger/pdb/linux-2.6-module/pdb_module.h tools/debugger/pdb/linux-2.6-patches/i386_ksyms.patch tools/debugger/pdb/pdb_caml_domain.c tools/debugger/pdb/pdb_caml_process.c tools/debugger/pdb/pdb_caml_xcs.c tools/debugger/pdb/readme tools/examples/Makefile tools/examples/xend-config.sxp tools/examples/xmexample.vmx tools/ioemu/hw/ide.c tools/libxc/Makefile tools/libxc/xc.h tools/libxc/xc_core.c tools/libxc/xc_gnttab.c tools/libxc/xc_linux_build.c tools/libxc/xc_linux_restore.c tools/libxc/xc_linux_save.c tools/libxc/xc_load_elf.c tools/libxc/xc_ptrace.c tools/libxc/xc_vmx_build.c tools/misc/xend tools/python/setup.py tools/python/xen/lowlevel/xu/xu.c tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendRoot.py tools/python/xen/xend/image.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/controller.py tools/python/xen/xend/server/event.py tools/python/xen/xend/server/netif.py tools/python/xen/xend/server/relocate.py tools/python/xen/xm/create.py tools/python/xen/xm/main.py tools/security/Makefile tools/security/secpol_tool.c tools/xenstat/Makefile tools/xenstat/libxenstat/COPYING tools/xenstat/libxenstat/Makefile tools/xenstat/libxenstat/bindings/swig/perl/.empty tools/xenstat/libxenstat/bindings/swig/python/.empty tools/xenstat/libxenstat/bindings/swig/xenstat.i tools/xenstat/libxenstat/src/xen-interface.c tools/xenstat/libxenstat/src/xen-interface.h tools/xenstat/libxenstat/src/xenstat.c tools/xenstat/libxenstat/src/xenstat.h tools/xenstat/xentop/Makefile tools/xenstat/xentop/TODO tools/xenstat/xentop/xentop.1 tools/xenstat/xentop/xentop.c tools/xenstore/xenstored.h tools/xenstore/xenstored_core.c tools/xentrace/xentrace.c xen/Rules.mk xen/arch/ia64/grant_table.c xen/arch/ia64/xenmisc.c xen/arch/ia64/xentime.c xen/arch/x86/domain.c xen/arch/x86/domain_build.c xen/arch/x86/mm.c xen/arch/x86/physdev.c xen/arch/x86/setup.c xen/arch/x86/shadow.c xen/arch/x86/shadow32.c xen/arch/x86/time.c xen/arch/x86/traps.c xen/arch/x86/vmx.c xen/arch/x86/x86_32/traps.c xen/arch/x86/x86_64/traps.c xen/common/domain.c xen/common/event_channel.c xen/common/grant_table.c xen/common/lib.c xen/common/perfc.c xen/common/schedule.c xen/common/trace.c xen/drivers/char/console.c xen/include/asm-x86/e820.h xen/include/asm-x86/mm.h xen/include/asm-x86/page.h xen/include/asm-x86/shadow.h xen/include/asm-x86/uaccess.h xen/include/asm-x86/vmx_vmcs.h xen/include/asm-x86/x86_32/page-3level.h xen/include/asm-x86/x86_32/uaccess.h xen/include/public/arch-ia64.h xen/include/public/arch-x86_32.h xen/include/public/arch-x86_64.h xen/include/public/dom0_ops.h xen/include/public/grant_table.h xen/include/public/io/blkif.h xen/include/public/io/domain_controller.h xen/include/public/io/netif.h xen/include/public/physdev.h xen/include/public/xen.h xen/include/xen/grant_table.h xen/include/xen/sched.h xen/include/xen/time.h
line diff
     1.1 --- a/Config.mk	Mon Aug 22 19:59:58 2005 +0000
     1.2 +++ b/Config.mk	Mon Aug 22 21:54:28 2005 +0000
     1.3 @@ -14,6 +14,7 @@ LD         = $(CROSS_COMPILE)ld
     1.4  CC         = $(CROSS_COMPILE)gcc
     1.5  CPP        = $(CROSS_COMPILE)gcc -E
     1.6  AR         = $(CROSS_COMPILE)ar
     1.7 +RANLIB     = $(CROSS_COMPILE)ranlib
     1.8  NM         = $(CROSS_COMPILE)nm
     1.9  STRIP      = $(CROSS_COMPILE)strip
    1.10  OBJCOPY    = $(CROSS_COMPILE)objcopy
    1.11 @@ -43,3 +44,7 @@ KERNEL_REPO = http://www.kernel.org
    1.12  #	ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY
    1.13  #	ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY
    1.14  ACM_USE_SECURITY_POLICY ?= ACM_NULL_POLICY
    1.15 +
    1.16 +# Optional components
    1.17 +XENSTAT_XENTOP ?= y
    1.18 +
     2.1 --- a/tools/Makefile	Mon Aug 22 19:59:58 2005 +0000
     2.2 +++ b/tools/Makefile	Mon Aug 22 21:54:28 2005 +0000
     2.3 @@ -14,6 +14,7 @@ SUBDIRS += xcutils
     2.4  SUBDIRS += firmware
     2.5  SUBDIRS += security
     2.6  SUBDIRS += console
     2.7 +SUBDIRS += xenstat
     2.8  
     2.9  .PHONY: all install clean check check_clean ioemu eioemuinstall ioemuclean
    2.10  
     3.1 --- a/tools/Rules.mk	Mon Aug 22 19:59:58 2005 +0000
     3.2 +++ b/tools/Rules.mk	Mon Aug 22 21:54:28 2005 +0000
     3.3 @@ -6,6 +6,7 @@ XEN_XC             = $(XEN_ROOT)/tools/p
     3.4  XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
     3.5  XEN_XCS            = $(XEN_ROOT)/tools/xcs
     3.6  XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
     3.7 +XEN_LIBXENSTAT     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
     3.8  
     3.9  ifeq ($(XEN_TARGET_ARCH),x86_32)
    3.10  CFLAGS  += -m32 -march=i686
     4.1 --- a/tools/python/xen/xm/main.py	Mon Aug 22 19:59:58 2005 +0000
     4.2 +++ b/tools/python/xen/xm/main.py	Mon Aug 22 21:54:28 2005 +0000
     4.3 @@ -49,6 +49,7 @@ xm common subcommands:
     4.4      restore <File>          create a domain from a saved state file
     4.5      save <DomId> <File>     save domain state (and config) to file
     4.6      shutdown <DomId>        shutdown a domain
     4.7 +    top                     monitor system and domains in real-time
     4.8      unpause <DomId>         unpause a paused domain
     4.9  
    4.10  For a complete list of subcommands run 'xm help --long'
    4.11 @@ -87,6 +88,7 @@ xm full list of subcommands:
    4.12      dmesg   [--clear]         read or clear Xen's message buffer
    4.13      info                      get information about the xen host
    4.14      log                       print the xend log
    4.15 +    top                       monitor system and domains in real-time
    4.16  
    4.17    Scheduler Commands:
    4.18      bvt <options>             set BVT scheduler parameters
    4.19 @@ -457,6 +459,9 @@ def xm_console(args):
    4.20      os.execvp('/usr/libexec/xen/xenconsole', cmd.split())
    4.21      console = sxp.child(info, "console")
    4.22  
    4.23 +def xm_top(args):
    4.24 +    os.execv('/usr/sbin/xentop', ['/usr/sbin/xentop'])
    4.25 +
    4.26  def xm_dmesg(args):
    4.27      
    4.28      gopts = Opts(use="""[-c|--clear]
    4.29 @@ -545,6 +550,8 @@ def xm_block_destroy(args):
    4.30  commands = {
    4.31      # console commands
    4.32      "console": xm_console,
    4.33 +    # xenstat commands
    4.34 +    "top": xm_top,
    4.35      # domain commands
    4.36      "domid": xm_domid,
    4.37      "domname": xm_domname,
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/xenstat/Makefile	Mon Aug 22 21:54:28 2005 +0000
     5.3 @@ -0,0 +1,13 @@
     5.4 +XEN_ROOT = ../..
     5.5 +include $(XEN_ROOT)/tools/Rules.mk
     5.6 +
     5.7 +SUBDIRS :=
     5.8 +SUBDIRS += libxenstat
     5.9 +SUBDIRS += xentop
    5.10 +
    5.11 +.PHONY: all install clean
    5.12 +
    5.13 +all install clean:
    5.14 +	@set -e; for subdir in $(SUBDIRS); do \
    5.15 +		$(MAKE) -C $$subdir $@; \
    5.16 +	done
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/xenstat/libxenstat/COPYING	Mon Aug 22 21:54:28 2005 +0000
     6.3 @@ -0,0 +1,510 @@
     6.4 +
     6.5 +                  GNU LESSER GENERAL PUBLIC LICENSE
     6.6 +                       Version 2.1, February 1999
     6.7 +
     6.8 + Copyright (C) 1991, 1999 Free Software Foundation, Inc.
     6.9 +	51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    6.10 + Everyone is permitted to copy and distribute verbatim copies
    6.11 + of this license document, but changing it is not allowed.
    6.12 +
    6.13 +[This is the first released version of the Lesser GPL.  It also counts
    6.14 + as the successor of the GNU Library Public License, version 2, hence
    6.15 + the version number 2.1.]
    6.16 +
    6.17 +                            Preamble
    6.18 +
    6.19 +  The licenses for most software are designed to take away your
    6.20 +freedom to share and change it.  By contrast, the GNU General Public
    6.21 +Licenses are intended to guarantee your freedom to share and change
    6.22 +free software--to make sure the software is free for all its users.
    6.23 +
    6.24 +  This license, the Lesser General Public License, applies to some
    6.25 +specially designated software packages--typically libraries--of the
    6.26 +Free Software Foundation and other authors who decide to use it.  You
    6.27 +can use it too, but we suggest you first think carefully about whether
    6.28 +this license or the ordinary General Public License is the better
    6.29 +strategy to use in any particular case, based on the explanations
    6.30 +below.
    6.31 +
    6.32 +  When we speak of free software, we are referring to freedom of use,
    6.33 +not price.  Our General Public Licenses are designed to make sure that
    6.34 +you have the freedom to distribute copies of free software (and charge
    6.35 +for this service if you wish); that you receive source code or can get
    6.36 +it if you want it; that you can change the software and use pieces of
    6.37 +it in new free programs; and that you are informed that you can do
    6.38 +these things.
    6.39 +
    6.40 +  To protect your rights, we need to make restrictions that forbid
    6.41 +distributors to deny you these rights or to ask you to surrender these
    6.42 +rights.  These restrictions translate to certain responsibilities for
    6.43 +you if you distribute copies of the library or if you modify it.
    6.44 +
    6.45 +  For example, if you distribute copies of the library, whether gratis
    6.46 +or for a fee, you must give the recipients all the rights that we gave
    6.47 +you.  You must make sure that they, too, receive or can get the source
    6.48 +code.  If you link other code with the library, you must provide
    6.49 +complete object files to the recipients, so that they can relink them
    6.50 +with the library after making changes to the library and recompiling
    6.51 +it.  And you must show them these terms so they know their rights.
    6.52 +
    6.53 +  We protect your rights with a two-step method: (1) we copyright the
    6.54 +library, and (2) we offer you this license, which gives you legal
    6.55 +permission to copy, distribute and/or modify the library.
    6.56 +
    6.57 +  To protect each distributor, we want to make it very clear that
    6.58 +there is no warranty for the free library.  Also, if the library is
    6.59 +modified by someone else and passed on, the recipients should know
    6.60 +that what they have is not the original version, so that the original
    6.61 +author's reputation will not be affected by problems that might be
    6.62 +introduced by others.
    6.63 +
    6.64 +  Finally, software patents pose a constant threat to the existence of
    6.65 +any free program.  We wish to make sure that a company cannot
    6.66 +effectively restrict the users of a free program by obtaining a
    6.67 +restrictive license from a patent holder.  Therefore, we insist that
    6.68 +any patent license obtained for a version of the library must be
    6.69 +consistent with the full freedom of use specified in this license.
    6.70 +
    6.71 +  Most GNU software, including some libraries, is covered by the
    6.72 +ordinary GNU General Public License.  This license, the GNU Lesser
    6.73 +General Public License, applies to certain designated libraries, and
    6.74 +is quite different from the ordinary General Public License.  We use
    6.75 +this license for certain libraries in order to permit linking those
    6.76 +libraries into non-free programs.
    6.77 +
    6.78 +  When a program is linked with a library, whether statically or using
    6.79 +a shared library, the combination of the two is legally speaking a
    6.80 +combined work, a derivative of the original library.  The ordinary
    6.81 +General Public License therefore permits such linking only if the
    6.82 +entire combination fits its criteria of freedom.  The Lesser General
    6.83 +Public License permits more lax criteria for linking other code with
    6.84 +the library.
    6.85 +
    6.86 +  We call this license the "Lesser" General Public License because it
    6.87 +does Less to protect the user's freedom than the ordinary General
    6.88 +Public License.  It also provides other free software developers Less
    6.89 +of an advantage over competing non-free programs.  These disadvantages
    6.90 +are the reason we use the ordinary General Public License for many
    6.91 +libraries.  However, the Lesser license provides advantages in certain
    6.92 +special circumstances.
    6.93 +
    6.94 +  For example, on rare occasions, there may be a special need to
    6.95 +encourage the widest possible use of a certain library, so that it
    6.96 +becomes a de-facto standard.  To achieve this, non-free programs must
    6.97 +be allowed to use the library.  A more frequent case is that a free
    6.98 +library does the same job as widely used non-free libraries.  In this
    6.99 +case, there is little to gain by limiting the free library to free
   6.100 +software only, so we use the Lesser General Public License.
   6.101 +
   6.102 +  In other cases, permission to use a particular library in non-free
   6.103 +programs enables a greater number of people to use a large body of
   6.104 +free software.  For example, permission to use the GNU C Library in
   6.105 +non-free programs enables many more people to use the whole GNU
   6.106 +operating system, as well as its variant, the GNU/Linux operating
   6.107 +system.
   6.108 +
   6.109 +  Although the Lesser General Public License is Less protective of the
   6.110 +users' freedom, it does ensure that the user of a program that is
   6.111 +linked with the Library has the freedom and the wherewithal to run
   6.112 +that program using a modified version of the Library.
   6.113 +
   6.114 +  The precise terms and conditions for copying, distribution and
   6.115 +modification follow.  Pay close attention to the difference between a
   6.116 +"work based on the library" and a "work that uses the library".  The
   6.117 +former contains code derived from the library, whereas the latter must
   6.118 +be combined with the library in order to run.
   6.119 +
   6.120 +                  GNU LESSER GENERAL PUBLIC LICENSE
   6.121 +   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
   6.122 +
   6.123 +  0. This License Agreement applies to any software library or other
   6.124 +program which contains a notice placed by the copyright holder or
   6.125 +other authorized party saying it may be distributed under the terms of
   6.126 +this Lesser General Public License (also called "this License").
   6.127 +Each licensee is addressed as "you".
   6.128 +
   6.129 +  A "library" means a collection of software functions and/or data
   6.130 +prepared so as to be conveniently linked with application programs
   6.131 +(which use some of those functions and data) to form executables.
   6.132 +
   6.133 +  The "Library", below, refers to any such software library or work
   6.134 +which has been distributed under these terms.  A "work based on the
   6.135 +Library" means either the Library or any derivative work under
   6.136 +copyright law: that is to say, a work containing the Library or a
   6.137 +portion of it, either verbatim or with modifications and/or translated
   6.138 +straightforwardly into another language.  (Hereinafter, translation is
   6.139 +included without limitation in the term "modification".)
   6.140 +
   6.141 +  "Source code" for a work means the preferred form of the work for
   6.142 +making modifications to it.  For a library, complete source code means
   6.143 +all the source code for all modules it contains, plus any associated
   6.144 +interface definition files, plus the scripts used to control
   6.145 +compilation and installation of the library.
   6.146 +
   6.147 +  Activities other than copying, distribution and modification are not
   6.148 +covered by this License; they are outside its scope.  The act of
   6.149 +running a program using the Library is not restricted, and output from
   6.150 +such a program is covered only if its contents constitute a work based
   6.151 +on the Library (independent of the use of the Library in a tool for
   6.152 +writing it).  Whether that is true depends on what the Library does
   6.153 +and what the program that uses the Library does.
   6.154 +
   6.155 +  1. You may copy and distribute verbatim copies of the Library's
   6.156 +complete source code as you receive it, in any medium, provided that
   6.157 +you conspicuously and appropriately publish on each copy an
   6.158 +appropriate copyright notice and disclaimer of warranty; keep intact
   6.159 +all the notices that refer to this License and to the absence of any
   6.160 +warranty; and distribute a copy of this License along with the
   6.161 +Library.
   6.162 +
   6.163 +  You may charge a fee for the physical act of transferring a copy,
   6.164 +and you may at your option offer warranty protection in exchange for a
   6.165 +fee.
   6.166 +
   6.167 +  2. You may modify your copy or copies of the Library or any portion
   6.168 +of it, thus forming a work based on the Library, and copy and
   6.169 +distribute such modifications or work under the terms of Section 1
   6.170 +above, provided that you also meet all of these conditions:
   6.171 +
   6.172 +    a) The modified work must itself be a software library.
   6.173 +
   6.174 +    b) You must cause the files modified to carry prominent notices
   6.175 +    stating that you changed the files and the date of any change.
   6.176 +
   6.177 +    c) You must cause the whole of the work to be licensed at no
   6.178 +    charge to all third parties under the terms of this License.
   6.179 +
   6.180 +    d) If a facility in the modified Library refers to a function or a
   6.181 +    table of data to be supplied by an application program that uses
   6.182 +    the facility, other than as an argument passed when the facility
   6.183 +    is invoked, then you must make a good faith effort to ensure that,
   6.184 +    in the event an application does not supply such function or
   6.185 +    table, the facility still operates, and performs whatever part of
   6.186 +    its purpose remains meaningful.
   6.187 +
   6.188 +    (For example, a function in a library to compute square roots has
   6.189 +    a purpose that is entirely well-defined independent of the
   6.190 +    application.  Therefore, Subsection 2d requires that any
   6.191 +    application-supplied function or table used by this function must
   6.192 +    be optional: if the application does not supply it, the square
   6.193 +    root function must still compute square roots.)
   6.194 +
   6.195 +These requirements apply to the modified work as a whole.  If
   6.196 +identifiable sections of that work are not derived from the Library,
   6.197 +and can be reasonably considered independent and separate works in
   6.198 +themselves, then this License, and its terms, do not apply to those
   6.199 +sections when you distribute them as separate works.  But when you
   6.200 +distribute the same sections as part of a whole which is a work based
   6.201 +on the Library, the distribution of the whole must be on the terms of
   6.202 +this License, whose permissions for other licensees extend to the
   6.203 +entire whole, and thus to each and every part regardless of who wrote
   6.204 +it.
   6.205 +
   6.206 +Thus, it is not the intent of this section to claim rights or contest
   6.207 +your rights to work written entirely by you; rather, the intent is to
   6.208 +exercise the right to control the distribution of derivative or
   6.209 +collective works based on the Library.
   6.210 +
   6.211 +In addition, mere aggregation of another work not based on the Library
   6.212 +with the Library (or with a work based on the Library) on a volume of
   6.213 +a storage or distribution medium does not bring the other work under
   6.214 +the scope of this License.
   6.215 +
   6.216 +  3. You may opt to apply the terms of the ordinary GNU General Public
   6.217 +License instead of this License to a given copy of the Library.  To do
   6.218 +this, you must alter all the notices that refer to this License, so
   6.219 +that they refer to the ordinary GNU General Public License, version 2,
   6.220 +instead of to this License.  (If a newer version than version 2 of the
   6.221 +ordinary GNU General Public License has appeared, then you can specify
   6.222 +that version instead if you wish.)  Do not make any other change in
   6.223 +these notices.
   6.224 +
   6.225 +  Once this change is made in a given copy, it is irreversible for
   6.226 +that copy, so the ordinary GNU General Public License applies to all
   6.227 +subsequent copies and derivative works made from that copy.
   6.228 +
   6.229 +  This option is useful when you wish to copy part of the code of
   6.230 +the Library into a program that is not a library.
   6.231 +
   6.232 +  4. You may copy and distribute the Library (or a portion or
   6.233 +derivative of it, under Section 2) in object code or executable form
   6.234 +under the terms of Sections 1 and 2 above provided that you accompany
   6.235 +it with the complete corresponding machine-readable source code, which
   6.236 +must be distributed under the terms of Sections 1 and 2 above on a
   6.237 +medium customarily used for software interchange.
   6.238 +
   6.239 +  If distribution of object code is made by offering access to copy
   6.240 +from a designated place, then offering equivalent access to copy the
   6.241 +source code from the same place satisfies the requirement to
   6.242 +distribute the source code, even though third parties are not
   6.243 +compelled to copy the source along with the object code.
   6.244 +
   6.245 +  5. A program that contains no derivative of any portion of the
   6.246 +Library, but is designed to work with the Library by being compiled or
   6.247 +linked with it, is called a "work that uses the Library".  Such a
   6.248 +work, in isolation, is not a derivative work of the Library, and
   6.249 +therefore falls outside the scope of this License.
   6.250 +
   6.251 +  However, linking a "work that uses the Library" with the Library
   6.252 +creates an executable that is a derivative of the Library (because it
   6.253 +contains portions of the Library), rather than a "work that uses the
   6.254 +library".  The executable is therefore covered by this License.
   6.255 +Section 6 states terms for distribution of such executables.
   6.256 +
   6.257 +  When a "work that uses the Library" uses material from a header file
   6.258 +that is part of the Library, the object code for the work may be a
   6.259 +derivative work of the Library even though the source code is not.
   6.260 +Whether this is true is especially significant if the work can be
   6.261 +linked without the Library, or if the work is itself a library.  The
   6.262 +threshold for this to be true is not precisely defined by law.
   6.263 +
   6.264 +  If such an object file uses only numerical parameters, data
   6.265 +structure layouts and accessors, and small macros and small inline
   6.266 +functions (ten lines or less in length), then the use of the object
   6.267 +file is unrestricted, regardless of whether it is legally a derivative
   6.268 +work.  (Executables containing this object code plus portions of the
   6.269 +Library will still fall under Section 6.)
   6.270 +
   6.271 +  Otherwise, if the work is a derivative of the Library, you may
   6.272 +distribute the object code for the work under the terms of Section 6.
   6.273 +Any executables containing that work also fall under Section 6,
   6.274 +whether or not they are linked directly with the Library itself.
   6.275 +
   6.276 +  6. As an exception to the Sections above, you may also combine or
   6.277 +link a "work that uses the Library" with the Library to produce a
   6.278 +work containing portions of the Library, and distribute that work
   6.279 +under terms of your choice, provided that the terms permit
   6.280 +modification of the work for the customer's own use and reverse
   6.281 +engineering for debugging such modifications.
   6.282 +
   6.283 +  You must give prominent notice with each copy of the work that the
   6.284 +Library is used in it and that the Library and its use are covered by
   6.285 +this License.  You must supply a copy of this License.  If the work
   6.286 +during execution displays copyright notices, you must include the
   6.287 +copyright notice for the Library among them, as well as a reference
   6.288 +directing the user to the copy of this License.  Also, you must do one
   6.289 +of these things:
   6.290 +
   6.291 +    a) Accompany the work with the complete corresponding
   6.292 +    machine-readable source code for the Library including whatever
   6.293 +    changes were used in the work (which must be distributed under
   6.294 +    Sections 1 and 2 above); and, if the work is an executable linked
   6.295 +    with the Library, with the complete machine-readable "work that
   6.296 +    uses the Library", as object code and/or source code, so that the
   6.297 +    user can modify the Library and then relink to produce a modified
   6.298 +    executable containing the modified Library.  (It is understood
   6.299 +    that the user who changes the contents of definitions files in the
   6.300 +    Library will not necessarily be able to recompile the application
   6.301 +    to use the modified definitions.)
   6.302 +
   6.303 +    b) Use a suitable shared library mechanism for linking with the
   6.304 +    Library.  A suitable mechanism is one that (1) uses at run time a
   6.305 +    copy of the library already present on the user's computer system,
   6.306 +    rather than copying library functions into the executable, and (2)
   6.307 +    will operate properly with a modified version of the library, if
   6.308 +    the user installs one, as long as the modified version is
   6.309 +    interface-compatible with the version that the work was made with.
   6.310 +
   6.311 +    c) Accompany the work with a written offer, valid for at least
   6.312 +    three years, to give the same user the materials specified in
   6.313 +    Subsection 6a, above, for a charge no more than the cost of
   6.314 +    performing this distribution.
   6.315 +
   6.316 +    d) If distribution of the work is made by offering access to copy
   6.317 +    from a designated place, offer equivalent access to copy the above
   6.318 +    specified materials from the same place.
   6.319 +
   6.320 +    e) Verify that the user has already received a copy of these
   6.321 +    materials or that you have already sent this user a copy.
   6.322 +
   6.323 +  For an executable, the required form of the "work that uses the
   6.324 +Library" must include any data and utility programs needed for
   6.325 +reproducing the executable from it.  However, as a special exception,
   6.326 +the materials to be distributed need not include anything that is
   6.327 +normally distributed (in either source or binary form) with the major
   6.328 +components (compiler, kernel, and so on) of the operating system on
   6.329 +which the executable runs, unless that component itself accompanies
   6.330 +the executable.
   6.331 +
   6.332 +  It may happen that this requirement contradicts the license
   6.333 +restrictions of other proprietary libraries that do not normally
   6.334 +accompany the operating system.  Such a contradiction means you cannot
   6.335 +use both them and the Library together in an executable that you
   6.336 +distribute.
   6.337 +
   6.338 +  7. You may place library facilities that are a work based on the
   6.339 +Library side-by-side in a single library together with other library
   6.340 +facilities not covered by this License, and distribute such a combined
   6.341 +library, provided that the separate distribution of the work based on
   6.342 +the Library and of the other library facilities is otherwise
   6.343 +permitted, and provided that you do these two things:
   6.344 +
   6.345 +    a) Accompany the combined library with a copy of the same work
   6.346 +    based on the Library, uncombined with any other library
   6.347 +    facilities.  This must be distributed under the terms of the
   6.348 +    Sections above.
   6.349 +
   6.350 +    b) Give prominent notice with the combined library of the fact
   6.351 +    that part of it is a work based on the Library, and explaining
   6.352 +    where to find the accompanying uncombined form of the same work.
   6.353 +
   6.354 +  8. You may not copy, modify, sublicense, link with, or distribute
   6.355 +the Library except as expressly provided under this License.  Any
   6.356 +attempt otherwise to copy, modify, sublicense, link with, or
   6.357 +distribute the Library is void, and will automatically terminate your
   6.358 +rights under this License.  However, parties who have received copies,
   6.359 +or rights, from you under this License will not have their licenses
   6.360 +terminated so long as such parties remain in full compliance.
   6.361 +
   6.362 +  9. You are not required to accept this License, since you have not
   6.363 +signed it.  However, nothing else grants you permission to modify or
   6.364 +distribute the Library or its derivative works.  These actions are
   6.365 +prohibited by law if you do not accept this License.  Therefore, by
   6.366 +modifying or distributing the Library (or any work based on the
   6.367 +Library), you indicate your acceptance of this License to do so, and
   6.368 +all its terms and conditions for copying, distributing or modifying
   6.369 +the Library or works based on it.
   6.370 +
   6.371 +  10. Each time you redistribute the Library (or any work based on the
   6.372 +Library), the recipient automatically receives a license from the
   6.373 +original licensor to copy, distribute, link with or modify the Library
   6.374 +subject to these terms and conditions.  You may not impose any further
   6.375 +restrictions on the recipients' exercise of the rights granted herein.
   6.376 +You are not responsible for enforcing compliance by third parties with
   6.377 +this License.
   6.378 +
   6.379 +  11. If, as a consequence of a court judgment or allegation of patent
   6.380 +infringement or for any other reason (not limited to patent issues),
   6.381 +conditions are imposed on you (whether by court order, agreement or
   6.382 +otherwise) that contradict the conditions of this License, they do not
   6.383 +excuse you from the conditions of this License.  If you cannot
   6.384 +distribute so as to satisfy simultaneously your obligations under this
   6.385 +License and any other pertinent obligations, then as a consequence you
   6.386 +may not distribute the Library at all.  For example, if a patent
   6.387 +license would not permit royalty-free redistribution of the Library by
   6.388 +all those who receive copies directly or indirectly through you, then
   6.389 +the only way you could satisfy both it and this License would be to
   6.390 +refrain entirely from distribution of the Library.
   6.391 +
   6.392 +If any portion of this section is held invalid or unenforceable under
   6.393 +any particular circumstance, the balance of the section is intended to
   6.394 +apply, and the section as a whole is intended to apply in other
   6.395 +circumstances.
   6.396 +
   6.397 +It is not the purpose of this section to induce you to infringe any
   6.398 +patents or other property right claims or to contest validity of any
   6.399 +such claims; this section has the sole purpose of protecting the
   6.400 +integrity of the free software distribution system which is
   6.401 +implemented by public license practices.  Many people have made
   6.402 +generous contributions to the wide range of software distributed
   6.403 +through that system in reliance on consistent application of that
   6.404 +system; it is up to the author/donor to decide if he or she is willing
   6.405 +to distribute software through any other system and a licensee cannot
   6.406 +impose that choice.
   6.407 +
   6.408 +This section is intended to make thoroughly clear what is believed to
   6.409 +be a consequence of the rest of this License.
   6.410 +
   6.411 +  12. If the distribution and/or use of the Library is restricted in
   6.412 +certain countries either by patents or by copyrighted interfaces, the
   6.413 +original copyright holder who places the Library under this License
   6.414 +may add an explicit geographical distribution limitation excluding those
   6.415 +countries, so that distribution is permitted only in or among
   6.416 +countries not thus excluded.  In such case, this License incorporates
   6.417 +the limitation as if written in the body of this License.
   6.418 +
   6.419 +  13. The Free Software Foundation may publish revised and/or new
   6.420 +versions of the Lesser General Public License from time to time.
   6.421 +Such new versions will be similar in spirit to the present version,
   6.422 +but may differ in detail to address new problems or concerns.
   6.423 +
   6.424 +Each version is given a distinguishing version number.  If the Library
   6.425 +specifies a version number of this License which applies to it and
   6.426 +"any later version", you have the option of following the terms and
   6.427 +conditions either of that version or of any later version published by
   6.428 +the Free Software Foundation.  If the Library does not specify a
   6.429 +license version number, you may choose any version ever published by
   6.430 +the Free Software Foundation.
   6.431 +
   6.432 +  14. If you wish to incorporate parts of the Library into other free
   6.433 +programs whose distribution conditions are incompatible with these,
   6.434 +write to the author to ask for permission.  For software which is
   6.435 +copyrighted by the Free Software Foundation, write to the Free
   6.436 +Software Foundation; we sometimes make exceptions for this.  Our
   6.437 +decision will be guided by the two goals of preserving the free status
   6.438 +of all derivatives of our free software and of promoting the sharing
   6.439 +and reuse of software generally.
   6.440 +
   6.441 +                            NO WARRANTY
   6.442 +
   6.443 +  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
   6.444 +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
   6.445 +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
   6.446 +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
   6.447 +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
   6.448 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   6.449 +PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
   6.450 +LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
   6.451 +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
   6.452 +
   6.453 +  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
   6.454 +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
   6.455 +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
   6.456 +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
   6.457 +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
   6.458 +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
   6.459 +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
   6.460 +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
   6.461 +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
   6.462 +DAMAGES.
   6.463 +
   6.464 +                     END OF TERMS AND CONDITIONS
   6.465 +
   6.466 +           How to Apply These Terms to Your New Libraries
   6.467 +
   6.468 +  If you develop a new library, and you want it to be of the greatest
   6.469 +possible use to the public, we recommend making it free software that
   6.470 +everyone can redistribute and change.  You can do so by permitting
   6.471 +redistribution under these terms (or, alternatively, under the terms
   6.472 +of the ordinary General Public License).
   6.473 +
   6.474 +  To apply these terms, attach the following notices to the library.
   6.475 +It is safest to attach them to the start of each source file to most
   6.476 +effectively convey the exclusion of warranty; and each file should
   6.477 +have at least the "copyright" line and a pointer to where the full
   6.478 +notice is found.
   6.479 +
   6.480 +
   6.481 +    <one line to give the library's name and a brief idea of what it does.>
   6.482 +    Copyright (C) <year>  <name of author>
   6.483 +
   6.484 +    This library is free software; you can redistribute it and/or
   6.485 +    modify it under the terms of the GNU Lesser General Public
   6.486 +    License as published by the Free Software Foundation; either
   6.487 +    version 2.1 of the License, or (at your option) any later version.
   6.488 +
   6.489 +    This library is distributed in the hope that it will be useful,
   6.490 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   6.491 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   6.492 +    Lesser General Public License for more details.
   6.493 +
   6.494 +    You should have received a copy of the GNU Lesser General Public
   6.495 +    License along with this library; if not, write to the Free Software
   6.496 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   6.497 +
   6.498 +Also add information on how to contact you by electronic and paper mail.
   6.499 +
   6.500 +You should also get your employer (if you work as a programmer) or
   6.501 +your school, if any, to sign a "copyright disclaimer" for the library,
   6.502 +if necessary.  Here is a sample; alter the names:
   6.503 +
   6.504 +  Yoyodyne, Inc., hereby disclaims all copyright interest in the
   6.505 +  library `Frob' (a library for tweaking knobs) written by James
   6.506 +  Random Hacker.
   6.507 +
   6.508 +  <signature of Ty Coon>, 1 April 1990
   6.509 +  Ty Coon, President of Vice
   6.510 +
   6.511 +That's all there is to it!
   6.512 +
   6.513 +
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/xenstat/libxenstat/Makefile	Mon Aug 22 21:54:28 2005 +0000
     7.3 @@ -0,0 +1,142 @@
     7.4 +# libxenstat: statistics-collection library for Xen
     7.5 +# Copyright (C) International Business Machines Corp., 2005
     7.6 +# Author: Josh Triplett <josht@us.ibm.com>
     7.7 +# 
     7.8 +# This library is free software; you can redistribute it and/or
     7.9 +# modify it under the terms of the GNU Lesser General Public
    7.10 +# License as published by the Free Software Foundation; either
    7.11 +# version 2.1 of the License, or (at your option) any later version.
    7.12 +# 
    7.13 +# This library is distributed in the hope that it will be useful,
    7.14 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +# Lesser General Public License for more details.
    7.17 +
    7.18 +XEN_ROOT=../../..
    7.19 +include $(XEN_ROOT)/tools/Rules.mk
    7.20 +LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse
    7.21 +
    7.22 +INSTALL         = install
    7.23 +INSTALL_PROG    = $(INSTALL) -m0755 -D
    7.24 +INSTALL_DATA    = $(INSTALL) -m0644 -D
    7.25 +
    7.26 +prefix=/usr
    7.27 +includedir=$(prefix)/include
    7.28 +libdir=$(prefix)/lib
    7.29 +
    7.30 +LDCONFIG=ldconfig
    7.31 +MAKE_LINK=ln -sf
    7.32 +
    7.33 +MAJOR=0
    7.34 +MINOR=0
    7.35 +
    7.36 +LIB=src/libxenstat.a
    7.37 +SHLIB=src/libxenstat.so.$(MAJOR).$(MINOR)
    7.38 +SHLIB_LINKS=src/libxenstat.so.$(MAJOR) src/libxenstat.so
    7.39 +OBJECTS=src/xenstat.o src/xen-interface.o
    7.40 +SONAME_FLAGS=-Wl,-soname -Wl,libxenstat.so.$(MAJOR)
    7.41 +
    7.42 +WARN_FLAGS=-Wall -Werror
    7.43 +
    7.44 +CFLAGS+=-Isrc
    7.45 +CFLAGS+=-I$(XEN_ROOT)/xen/include/public
    7.46 +CFLAGS+=-I$(LINUX_ROOT)/include/asm-xen/linux-public/
    7.47 +LDFLAGS+=-Lsrc
    7.48 +
    7.49 +all: $(LIB)
    7.50 +
    7.51 +$(LIB): $(OBJECTS)
    7.52 +	$(AR) rc $@ $^
    7.53 +	$(RANLIB) $@
    7.54 +
    7.55 +$(SHLIB): $(OBJECTS)
    7.56 +	$(CC) $(LDFLAGS) $(SONAME_FLAGS) -shared -o $@ $(OBJECTS)
    7.57 +
    7.58 +src/xenstat.o: src/xenstat.c src/xenstat.h src/xen-interface.h
    7.59 +	$(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $<
    7.60 +
    7.61 +src/xen-interface.o: src/xen-interface.c src/xen-interface.h
    7.62 +	$(CC) $(CFLAGS) $(WARN_FLAGS) -c -o $@ $<
    7.63 +
    7.64 +src/libxenstat.so.$(MAJOR): $(LIB)
    7.65 +	$(MAKE_LINK) $(<F) $@
    7.66 +
    7.67 +src/libxenstat.so: src/libxenstat.so.$(MAJOR)
    7.68 +	$(MAKE_LINK) $(<F) $@
    7.69 +
    7.70 +install: all
    7.71 +#install: all
    7.72 +#	$(INSTALL_DATA) src/xenstat.h $(DESTDIR)$(includedir)/xenstat.h
    7.73 +#	$(INSTALL_PROG) $(LIB) $(DESTDIR)$(libdir)/libxenstat.a
    7.74 +#	$(INSTALL_PROG) $(SHLIB) \
    7.75 +#	                $(DESTDIR)$(libdir)/libxenstat.so.$(MAJOR).$(MINOR)
    7.76 +#	$(MAKE_LINK) libxenstat.so.$(MAJOR).$(MINOR) \
    7.77 +#	             $(DESTDIR)$(libdir)/libxenstat.so.$(MAJOR)
    7.78 +#	$(MAKE_LINK) libxenstat.so.$(MAJOR) \
    7.79 +#	             $(DESTDIR)$(libdir)/libxenstat.so
    7.80 +#	-$(LDCONFIG)
    7.81 +
    7.82 +PYLIB=bindings/swig/python/_xenstat.so
    7.83 +PYMOD=bindings/swig/python/xenstat.py
    7.84 +PYSRC=bindings/swig/python/_xenstat.c
    7.85 +PERLLIB=bindings/swig/perl/xenstat.so
    7.86 +PERLMOD=bindings/swig/perl/xenstat.pm
    7.87 +PERLSRC=bindings/swig/perl/xenstat.c
    7.88 +BINDINGS=$(PYLIB) $(PYMOD) $(PERLLIB) $(PERLMOD)
    7.89 +BINDINGSRC=$(PYSRC) $(PERLSRC)
    7.90 +
    7.91 +# The all-bindings target builds all the language bindings
    7.92 +all-bindings: perl-bindings python-bindings
    7.93 +
    7.94 +# The install-bindings target installs all the language bindings
    7.95 +install-bindings: install-perl-bindings install-python-bindings
    7.96 +
    7.97 +$(BINDINGS): $(SHLIB) $(SHLIB_LINKS) src/xenstat.h
    7.98 +
    7.99 +SWIG_FLAGS=-module xenstat -Isrc
   7.100 +
   7.101 +# Python bindings
   7.102 +PYTHON_VERSION=2.3
   7.103 +PYTHON_FLAGS=-I/usr/include/python$(PYTHON_VERSION) -lpython$(PYTHON_VERSION)
   7.104 +$(PYSRC) $(PYMOD): bindings/swig/xenstat.i
   7.105 +	swig -python $(SWIG_FLAGS) -outdir $(@D) -o $(PYSRC) $<
   7.106 +
   7.107 +$(PYLIB): $(PYSRC)
   7.108 +	$(CC) $(CFLAGS) $(LDFLAGS) $(PYTHON_FLAGS) -shared -lxenstat -o $@ $<
   7.109 +
   7.110 +python-bindings: $(PYLIB) $(PYMOD)
   7.111 +
   7.112 +pythonlibdir=$(prefix)/lib/python$(PYTHON_VERSION)/site-packages
   7.113 +install-python-bindings: $(PYLIB) $(PYMOD)
   7.114 +	$(INSTALL_PROG) $(PYLIB) $(DESTDIR)$(pythonlibdir)/_xenstat.so
   7.115 +	$(INSTALL_PROG) $(PYMOD) $(DESTDIR)$(pythonlibdir)/xenstat.py
   7.116 +
   7.117 +ifeq ($(XENSTAT_PYTHON_BINDINGS),y)
   7.118 +all: python-bindings
   7.119 +install: install-python-bindings
   7.120 +endif
   7.121 +
   7.122 +# Perl bindings
   7.123 +PERL_FLAGS=`perl -MConfig -e 'print "$$Config{ccflags} -I$$Config{archlib}/CORE";'`
   7.124 +$(PERLSRC) $(PERLMOD): bindings/swig/xenstat.i
   7.125 +	swig -perl $(SWIG_FLAGS) -outdir $(@D) -o $(PERLSRC) $<
   7.126 +
   7.127 +$(PERLLIB): $(PERLSRC)
   7.128 +	$(CC) $(CFLAGS) $(LDFLAGS) $(PERL_FLAGS) -shared -lxenstat -o $@ $<
   7.129 +
   7.130 +perl-bindings: $(PERLLIB) $(PERLMOD)
   7.131 +
   7.132 +perllibdir=$(prefix)/lib/perl5
   7.133 +perlmoddir=$(prefix)/share/perl5
   7.134 +install-perl-bindings: $(PERLLIB) $(PERLMOD)
   7.135 +	$(INSTALL_PROG) $(PERLLIB) $(DESTDIR)$(perllibdir)/xenstat.so
   7.136 +	$(INSTALL_PROG) $(PERLMOD) $(DESTDIR)$(perlmoddir)/xenstat.pm
   7.137 +
   7.138 +ifeq ($(XENSTAT_PERL_BINDINGS),y)
   7.139 +all: perl-bindings
   7.140 +install: install-perl-bindings
   7.141 +endif
   7.142 +
   7.143 +clean:
   7.144 +	rm -f $(LIB) $(SHLIB) $(SHLIB_LINKS) $(OBJECTS) \
   7.145 +	      $(BINDINGS) $(BINDINGSRC)
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/xenstat/libxenstat/bindings/swig/perl/.empty	Mon Aug 22 21:54:28 2005 +0000
     8.3 @@ -0,0 +1,1 @@
     8.4 +This directory is empty; this file is included to prevent version control systems from removing the directory.
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/xenstat/libxenstat/bindings/swig/python/.empty	Mon Aug 22 21:54:28 2005 +0000
     9.3 @@ -0,0 +1,1 @@
     9.4 +This directory is empty; this file is included to prevent version control systems from removing the directory.
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/xenstat/libxenstat/bindings/swig/xenstat.i	Mon Aug 22 21:54:28 2005 +0000
    10.3 @@ -0,0 +1,8 @@
    10.4 +%module xenstat_swig
    10.5 +%{
    10.6 +/* Includes the header in the wrapper code */
    10.7 +#include "xenstat.h"
    10.8 +%}
    10.9 +
   10.10 +/* Parse the header file to generate wrappers */
   10.11 +%include "xenstat.h"
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/tools/xenstat/libxenstat/src/xen-interface.c	Mon Aug 22 21:54:28 2005 +0000
    11.3 @@ -0,0 +1,144 @@
    11.4 +/* xen-interface.c
    11.5 + *
    11.6 + * Copyright (C) International Business Machines Corp., 2005
    11.7 + * Authors: Josh Triplett <josht@us.ibm.com>
    11.8 + *          Judy Fischbach <jfisch@us.ibm.com>
    11.9 + *
   11.10 + * This library is free software; you can redistribute it and/or
   11.11 + * modify it under the terms of the GNU Lesser General Public
   11.12 + * License as published by the Free Software Foundation; either
   11.13 + * version 2.1 of the License, or (at your option) any later version.
   11.14 + *
   11.15 + * This library is distributed in the hope that it will be useful,
   11.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
   11.18 + * Lesser General Public License for more details.
   11.19 + */
   11.20 +
   11.21 +#include "xen-interface.h"
   11.22 +#include <fcntl.h>
   11.23 +#include <sys/ioctl.h>
   11.24 +#include <sys/mman.h>
   11.25 +#include <stdio.h>
   11.26 +#include <stdlib.h>
   11.27 +#include <unistd.h>
   11.28 +#include "privcmd.h"
   11.29 +#include "xen.h"
   11.30 +
   11.31 +struct xi_handle {
   11.32 +	int fd;
   11.33 +};
   11.34 +
   11.35 +/* Initialize for xen-interface.  Returns a handle to be used with subsequent
   11.36 + * calls to the xen-interface functions or NULL if an error occurs. */
   11.37 +xi_handle *xi_init()
   11.38 +{
   11.39 +	xi_handle *handle;
   11.40 +
   11.41 +	handle = (xi_handle *)calloc(1, sizeof(xi_handle));
   11.42 +	if (handle == NULL)
   11.43 +		return NULL;
   11.44 +
   11.45 +	handle->fd = open("/proc/xen/privcmd", O_RDWR);
   11.46 +	if (handle->fd < 0) {
   11.47 +		perror("Couldn't open /proc/xen/privcmd");
   11.48 +		free(handle);
   11.49 +		return NULL;
   11.50 +	}
   11.51 +
   11.52 +	return handle;
   11.53 +}
   11.54 +
   11.55 +/* Release the handle to libxc, free resources, etc. */
   11.56 +void xi_uninit(xi_handle *handle)
   11.57 +{
   11.58 +	close (handle->fd);
   11.59 +	free (handle);
   11.60 +}
   11.61 +
   11.62 +/* Make Xen hypervisor call */
   11.63 +int xi_make_dom0_op(xi_handle *handle, dom0_op_t *op, int opcode)
   11.64 +{
   11.65 +	privcmd_hypercall_t privcmd;
   11.66 +	int ret = 0;
   11.67 +
   11.68 +	/* set up for doing hypercall */
   11.69 +	privcmd.op = __HYPERVISOR_dom0_op;
   11.70 +	privcmd.arg[0] = (unsigned long)op;
   11.71 +	op->cmd = opcode;
   11.72 +	op->interface_version = DOM0_INTERFACE_VERSION;
   11.73 +
   11.74 +	if (mlock( &privcmd, sizeof(privcmd_hypercall_t)) < 0) {
   11.75 +		perror("Failed to mlock privcmd structure");
   11.76 +		return -1;
   11.77 +	}
   11.78 +
   11.79 +	if (mlock( op, sizeof(dom0_op_t)) < 0) {
   11.80 +		perror("Failed to mlock dom0_op structure");
   11.81 +		munlock( &privcmd, sizeof(privcmd_hypercall_t));
   11.82 +		return -1;
   11.83 +	}
   11.84 +
   11.85 +	if (ioctl( handle->fd, IOCTL_PRIVCMD_HYPERCALL, &privcmd) < 0) {
   11.86 +		perror("Hypercall failed");
   11.87 +		ret = -1;
   11.88 +	}
   11.89 +
   11.90 +	munlock( &privcmd, sizeof(privcmd_hypercall_t));
   11.91 +	munlock( op, sizeof(dom0_op_t));
   11.92 +
   11.93 +	return ret;
   11.94 +}
   11.95 +
   11.96 +/* Obtain domain data from dom0 */
   11.97 +int xi_get_physinfo(xi_handle *handle, dom0_physinfo_t *physinfo)
   11.98 +{
   11.99 +	dom0_op_t op;
  11.100 +
  11.101 +	if (xi_make_dom0_op(handle, &op, DOM0_PHYSINFO) < 0) {
  11.102 +		perror("DOM0_PHYSINFO Hypercall failed");
  11.103 +		return -1;
  11.104 +	}
  11.105 +
  11.106 +	*physinfo = op.u.physinfo;
  11.107 +	return 0;
  11.108 +}
  11.109 +
  11.110 +/* Obtain domain data from dom0 */
  11.111 +int xi_get_domaininfolist(xi_handle *handle, dom0_getdomaininfo_t *info,
  11.112 +                          unsigned int first_domain, unsigned int max_domains)
  11.113 +{
  11.114 +	dom0_op_t op;
  11.115 +	op.u.getdomaininfolist.first_domain = first_domain;
  11.116 +	op.u.getdomaininfolist.max_domains = max_domains;
  11.117 +	op.u.getdomaininfolist.buffer = info;
  11.118 +
  11.119 +	if (mlock( info, max_domains * sizeof(dom0_getdomaininfo_t)) < 0) {
  11.120 +		perror("Failed to mlock domaininfo array");
  11.121 +		return -1;
  11.122 +	}
  11.123 +
  11.124 +	if (xi_make_dom0_op(handle, &op, DOM0_GETDOMAININFOLIST) < 0) {
  11.125 +		perror("DOM0_GETDOMAININFOLIST Hypercall failed");
  11.126 +		return -1;
  11.127 +	}
  11.128 +
  11.129 +	return op.u.getdomaininfolist.num_domains;
  11.130 +}
  11.131 +
  11.132 +/* Returns cpu usage data from dom0 */
  11.133 +long long xi_get_vcpu_usage(xi_handle *handle, unsigned int domain,
  11.134 +                            unsigned int vcpu)
  11.135 +{
  11.136 +	dom0_op_t op;
  11.137 +	op.u.getvcpucontext.domain = domain;
  11.138 +	op.u.getvcpucontext.vcpu = vcpu;
  11.139 +	op.u.getvcpucontext.ctxt = NULL;
  11.140 +
  11.141 +	if (xi_make_dom0_op(handle, &op, DOM0_GETVCPUCONTEXT) < 0) {
  11.142 +		perror("DOM0_GETVCPUCONTEXT Hypercall failed");
  11.143 +		return -1;
  11.144 +	}
  11.145 +
  11.146 +	return op.u.getvcpucontext.cpu_time;
  11.147 +}
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/tools/xenstat/libxenstat/src/xen-interface.h	Mon Aug 22 21:54:28 2005 +0000
    12.3 @@ -0,0 +1,49 @@
    12.4 +/* xen-interface.h
    12.5 + *
    12.6 + * Copyright (C) International Business Machines Corp., 2005
    12.7 + * Authors: Josh Triplett <josht@us.ibm.com>
    12.8 + *          Judy Fischbach <jfisch@us.ibm.com>
    12.9 + *
   12.10 + * This library is free software; you can redistribute it and/or
   12.11 + * modify it under the terms of the GNU Lesser General Public
   12.12 + * License as published by the Free Software Foundation; either
   12.13 + * version 2.1 of the License, or (at your option) any later version.
   12.14 + *
   12.15 + * This library is distributed in the hope that it will be useful,
   12.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.18 + * Lesser General Public License for more details.
   12.19 + */
   12.20 +
   12.21 +#include <stdint.h>
   12.22 +
   12.23 +typedef int8_t   s8;
   12.24 +typedef int16_t  s16;
   12.25 +typedef int32_t  s32;
   12.26 +typedef int64_t  s64;
   12.27 +typedef uint8_t  u8;
   12.28 +typedef uint16_t u16;
   12.29 +typedef uint32_t u32;
   12.30 +typedef uint64_t u64;
   12.31 +
   12.32 +#include "dom0_ops.h"
   12.33 +
   12.34 +/* Opaque handles */
   12.35 +typedef struct xi_handle xi_handle;
   12.36 +
   12.37 +/* Initialize for xen-interface.  Returns a handle to be used with subsequent
   12.38 + * calls to the xen-interface functions or NULL if an error occurs. */
   12.39 +xi_handle *xi_init();
   12.40 +
   12.41 +/* Release the handle to libxc, free resources, etc. */
   12.42 +void xi_uninit(xi_handle *handle);
   12.43 +
   12.44 +/* Obtain physinfo data from dom0 */
   12.45 +int xi_get_physinfo(xi_handle *, dom0_physinfo_t *);
   12.46 +
   12.47 +/* Obtain domain data from dom0 */
   12.48 +int xi_get_domaininfolist(xi_handle *, dom0_getdomaininfo_t *, unsigned int,
   12.49 +                          unsigned int);
   12.50 +
   12.51 +/* Returns cpu usage data from dom0 */
   12.52 +long long xi_get_vcpu_usage(xi_handle *, unsigned int, unsigned int);
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/tools/xenstat/libxenstat/src/xenstat.c	Mon Aug 22 21:54:28 2005 +0000
    13.3 @@ -0,0 +1,620 @@
    13.4 +/* libxenstat: statistics-collection library for Xen
    13.5 + * Copyright (C) International Business Machines Corp., 2005
    13.6 + * Authors: Josh Triplett <josht@us.ibm.com>
    13.7 + *          Judy Fischbach <jfisch@us.ibm.com>
    13.8 + *          David Hendricks <dhendrix@us.ibm.com>
    13.9 + *
   13.10 + * This library is free software; you can redistribute it and/or
   13.11 + * modify it under the terms of the GNU Lesser General Public
   13.12 + * License as published by the Free Software Foundation; either
   13.13 + * version 2.1 of the License, or (at your option) any later version.
   13.14 + *
   13.15 + * This library is distributed in the hope that it will be useful,
   13.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13.18 + * Lesser General Public License for more details.
   13.19 + */
   13.20 +
   13.21 +#include <limits.h>
   13.22 +#include <stdlib.h>
   13.23 +#include <stdio.h>
   13.24 +#include <string.h>
   13.25 +#include <unistd.h>
   13.26 +#include <xen-interface.h>
   13.27 +#include "xenstat.h"
   13.28 +
   13.29 +/*
   13.30 + * Types
   13.31 + */
   13.32 +struct xenstat_handle {
   13.33 +	xi_handle *xihandle;
   13.34 +	int page_size;
   13.35 +	FILE *procnetdev;
   13.36 +};
   13.37 +
   13.38 +struct xenstat_node {
   13.39 +	unsigned int flags;
   13.40 +	unsigned long long cpu_hz;
   13.41 +	unsigned int num_cpus;
   13.42 +	unsigned long long tot_mem;
   13.43 +	unsigned long long free_mem;
   13.44 +	unsigned int num_domains;
   13.45 +	xenstat_domain *domains;	/* Array of length num_domains */
   13.46 +};
   13.47 +
   13.48 +struct xenstat_domain {
   13.49 +	unsigned int id;
   13.50 +	unsigned int state;
   13.51 +	unsigned long long cpu_ns;
   13.52 +	unsigned int num_vcpus;
   13.53 +	xenstat_vcpu *vcpus;	/* Array of length num_vcpus */
   13.54 +	unsigned long long cur_mem;	/* Current memory reservation */
   13.55 +	unsigned long long max_mem;	/* Total memory allowed */
   13.56 +	unsigned int ssid;
   13.57 +	unsigned int num_networks;
   13.58 +	xenstat_network *networks;	/* Array of length num_networks */
   13.59 +};
   13.60 +
   13.61 +struct xenstat_vcpu {
   13.62 +	unsigned long long ns;
   13.63 +};
   13.64 +
   13.65 +struct xenstat_network {
   13.66 +	unsigned int id;
   13.67 +	/* Received */
   13.68 +	unsigned long long rbytes;
   13.69 +	unsigned long long rpackets;
   13.70 +	unsigned long long rerrs;
   13.71 +	unsigned long long rdrop;
   13.72 +	/* Transmitted */
   13.73 +	unsigned long long tbytes;
   13.74 +	unsigned long long tpackets;
   13.75 +	unsigned long long terrs;
   13.76 +	unsigned long long tdrop;
   13.77 +};
   13.78 +
   13.79 +/*
   13.80 + * Data-collection types
   13.81 + */
   13.82 +/* Called to collect the information for the node and all the domains on
   13.83 + * it. When called, the domain information has already been collected. */
   13.84 +typedef int (*xenstat_collect_func)(xenstat_handle * handle,
   13.85 +				    xenstat_node * node);
   13.86 +/* Called to free the information collected by the collect function.  The free
   13.87 + * function will only be called on a xenstat_node if that node includes
   13.88 + * information collected by the corresponding collector. */
   13.89 +typedef void (*xenstat_free_func)(xenstat_node * node);
   13.90 +/* Called to free any information stored in the handle.  Note the lack of a
   13.91 + * matching init function; the collect functions should initialize on first
   13.92 + * use.  Also, the uninit function must handle the case that the collector has
   13.93 + * never been initialized. */
   13.94 +typedef void (*xenstat_uninit_func)(xenstat_handle * handle);
   13.95 +typedef struct xenstat_collector {
   13.96 +	unsigned int flag;
   13.97 +	xenstat_collect_func collect;
   13.98 +	xenstat_free_func free;
   13.99 +	xenstat_uninit_func uninit;
  13.100 +} xenstat_collector;
  13.101 +
  13.102 +static int  xenstat_collect_vcpus(xenstat_handle * handle,
  13.103 +				  xenstat_node * node);
  13.104 +static int  xenstat_collect_networks(xenstat_handle * handle,
  13.105 +				    xenstat_node * node);
  13.106 +static void xenstat_free_vcpus(xenstat_node * node);
  13.107 +static void xenstat_free_networks(xenstat_node * node);
  13.108 +static void xenstat_uninit_vcpus(xenstat_handle * handle);
  13.109 +static void xenstat_uninit_networks(xenstat_handle * handle);
  13.110 +
  13.111 +static xenstat_collector collectors[] = {
  13.112 +	{ XENSTAT_VCPU, xenstat_collect_vcpus,
  13.113 +	  xenstat_free_vcpus, xenstat_uninit_vcpus },
  13.114 +	{ XENSTAT_NETWORK, xenstat_collect_networks,
  13.115 +	  xenstat_free_networks, xenstat_uninit_networks }
  13.116 +};
  13.117 +
  13.118 +#define NUM_COLLECTORS (sizeof(collectors)/sizeof(xenstat_collector))
  13.119 +
  13.120 +/*
  13.121 + * libxenstat API
  13.122 + */
  13.123 +xenstat_handle *xenstat_init()
  13.124 +{
  13.125 +	xenstat_handle *handle;
  13.126 +
  13.127 +	handle = (xenstat_handle *) calloc(1, sizeof(xenstat_handle));
  13.128 +	if (handle == NULL)
  13.129 +		return NULL;
  13.130 +
  13.131 +#if defined(PAGESIZE)
  13.132 +	handle->page_size = PAGESIZE;
  13.133 +#elif defined(PAGE_SIZE)
  13.134 +	handle->page_size = PAGE_SIZE;
  13.135 +#else
  13.136 +	handle->page_size = sysconf(_SC_PAGE_SIZE);
  13.137 +	if (handle->page_size < 0) {
  13.138 +		perror("Failed to retrieve page size.");
  13.139 +		free(handle);
  13.140 +		return NULL;
  13.141 +	}
  13.142 +#endif
  13.143 +
  13.144 +	handle->xihandle = xi_init();
  13.145 +	if (handle->xihandle == NULL) {
  13.146 +		perror("xi_init");
  13.147 +		free(handle);
  13.148 +		return NULL;
  13.149 +	}
  13.150 +
  13.151 +	return handle;
  13.152 +}
  13.153 +
  13.154 +void xenstat_uninit(xenstat_handle * handle)
  13.155 +{
  13.156 +	unsigned int i;
  13.157 +	if (handle) {
  13.158 +		for (i = 0; i < NUM_COLLECTORS; i++)
  13.159 +			collectors[i].uninit(handle);
  13.160 +		xi_uninit(handle->xihandle);
  13.161 +		free(handle);
  13.162 +	}
  13.163 +}
  13.164 +
  13.165 +xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags)
  13.166 +{
  13.167 +#define DOMAIN_CHUNK_SIZE 256
  13.168 +	xenstat_node *node;
  13.169 +	dom0_physinfo_t physinfo;
  13.170 +	dom0_getdomaininfo_t domaininfo[DOMAIN_CHUNK_SIZE];
  13.171 +	unsigned int num_domains, new_domains;
  13.172 +	unsigned int i;
  13.173 +
  13.174 +	/* Create the node */
  13.175 +	node = (xenstat_node *) calloc(1, sizeof(xenstat_node));
  13.176 +	if (node == NULL)
  13.177 +		return NULL;
  13.178 +
  13.179 +	/* Get information about the physical system */
  13.180 +	if (xi_get_physinfo(handle->xihandle, &physinfo) < 0) {
  13.181 +		free(node);
  13.182 +		return NULL;
  13.183 +	}
  13.184 +
  13.185 +	node->cpu_hz = ((unsigned long long)physinfo.cpu_khz) * 1000ULL;
  13.186 +	node->num_cpus =
  13.187 +	    (physinfo.threads_per_core * physinfo.cores_per_socket *
  13.188 +	     physinfo.sockets_per_node * physinfo.nr_nodes);
  13.189 +	node->tot_mem = ((unsigned long long)physinfo.total_pages)
  13.190 +	    * handle->page_size;
  13.191 +	node->free_mem = ((unsigned long long)physinfo.free_pages)
  13.192 +	    * handle->page_size;
  13.193 +
  13.194 +	/* malloc(0) is not portable, so allocate a single domain.  This will
  13.195 +	 * be resized below. */
  13.196 +	node->domains = malloc(sizeof(xenstat_domain));
  13.197 +	if (node->domains == NULL) {
  13.198 +		free(node);
  13.199 +		return NULL;
  13.200 +	}
  13.201 +
  13.202 +	num_domains = 0;
  13.203 +	do {
  13.204 +		xenstat_domain *domain;
  13.205 +
  13.206 +		new_domains = xi_get_domaininfolist(handle->xihandle,
  13.207 +		                                    domaininfo, num_domains,
  13.208 +		                                    DOMAIN_CHUNK_SIZE);
  13.209 +
  13.210 +		node->domains = realloc(node->domains,
  13.211 +					(num_domains + new_domains)
  13.212 +					* sizeof(xenstat_domain));
  13.213 +		if (node->domains == NULL) {
  13.214 +			free(node);
  13.215 +			return NULL;
  13.216 +		}
  13.217 +
  13.218 +		domain = node->domains + num_domains;
  13.219 +
  13.220 +		for (i = 0; i < new_domains; i++) {
  13.221 +			/* Fill in domain using domaininfo[i] */
  13.222 +			domain->id = domaininfo[i].domain;
  13.223 +			domain->state = domaininfo[i].flags;
  13.224 +			domain->cpu_ns = domaininfo[i].cpu_time;
  13.225 +			domain->num_vcpus = domaininfo[i].n_vcpu;
  13.226 +			domain->vcpus = NULL;
  13.227 +			domain->cur_mem =
  13.228 +			    ((unsigned long long)domaininfo[i].tot_pages)
  13.229 +			    * handle->page_size;
  13.230 +			domain->max_mem =
  13.231 +			    domaininfo[i].max_pages == UINT_MAX
  13.232 +			    ? (unsigned long long)-1
  13.233 +			    : (unsigned long long)(domaininfo[i].max_pages
  13.234 +						   * handle->page_size);
  13.235 +			domain->ssid = domaininfo[i].ssidref;
  13.236 +			domain->num_networks = 0;
  13.237 +			domain->networks = NULL;
  13.238 +
  13.239 +			domain++;
  13.240 +		}
  13.241 +		num_domains += new_domains;
  13.242 +	} while (new_domains == DOMAIN_CHUNK_SIZE);
  13.243 +	node->num_domains = num_domains;
  13.244 +
  13.245 +	/* Run all the extra data collectors requested */
  13.246 +	node->flags = 0;
  13.247 +	for (i = 0; i < NUM_COLLECTORS; i++) {
  13.248 +		if ((flags & collectors[i].flag) == collectors[i].flag) {
  13.249 +			node->flags |= collectors[i].flag;
  13.250 +			if(collectors[i].collect(handle, node) == 0) {
  13.251 +				xenstat_free_node(node);
  13.252 +				return NULL;
  13.253 +                        }
  13.254 +                }
  13.255 +	}
  13.256 +
  13.257 +	return node;
  13.258 +}
  13.259 +
  13.260 +void xenstat_free_node(xenstat_node * node)
  13.261 +{
  13.262 +	int i;
  13.263 +
  13.264 +	if (node) {
  13.265 +		if (node->domains) {
  13.266 +			for (i = 0; i < NUM_COLLECTORS; i++)
  13.267 +				if((node->flags & collectors[i].flag)
  13.268 +				   == collectors[i].flag)
  13.269 +					collectors[i].free(node);
  13.270 +			free(node->domains);
  13.271 +		}
  13.272 +		free(node);
  13.273 +	}
  13.274 +}
  13.275 +
  13.276 +xenstat_domain *xenstat_node_domain(xenstat_node * node, unsigned int domid)
  13.277 +{
  13.278 +	unsigned int i;
  13.279 +
  13.280 +	/* FIXME: binary search */
  13.281 +	/* Find the appropriate domain entry in the node struct. */
  13.282 +	for (i = 0; i < node->num_domains; i++) {
  13.283 +		if (node->domains[i].id == domid)
  13.284 +			return &(node->domains[i]);
  13.285 +	}
  13.286 +	return NULL;
  13.287 +}
  13.288 +
  13.289 +xenstat_domain *xenstat_node_domain_by_index(xenstat_node * node,
  13.290 +					     unsigned int index)
  13.291 +{
  13.292 +	if (0 <= index && index < node->num_domains)
  13.293 +		return &(node->domains[index]);
  13.294 +	return NULL;
  13.295 +}
  13.296 +
  13.297 +unsigned long long xenstat_node_tot_mem(xenstat_node * node)
  13.298 +{
  13.299 +	return node->tot_mem;
  13.300 +}
  13.301 +
  13.302 +unsigned long long xenstat_node_free_mem(xenstat_node * node)
  13.303 +{
  13.304 +	return node->free_mem;
  13.305 +}
  13.306 +
  13.307 +unsigned int xenstat_node_num_domains(xenstat_node * node)
  13.308 +{
  13.309 +	return node->num_domains;
  13.310 +}
  13.311 +
  13.312 +unsigned int xenstat_node_num_cpus(xenstat_node * node)
  13.313 +{
  13.314 +	return node->num_cpus;
  13.315 +}
  13.316 +
  13.317 +/* Get information about the CPU speed */
  13.318 +unsigned long long xenstat_node_cpu_hz(xenstat_node * node)
  13.319 +{
  13.320 +	return node->cpu_hz;
  13.321 +}
  13.322 +
  13.323 +/* Get the domain ID for this domain */
  13.324 +unsigned xenstat_domain_id(xenstat_domain * domain)
  13.325 +{
  13.326 +	return domain->id;
  13.327 +}
  13.328 +
  13.329 +/* Get information about how much CPU time has been used */
  13.330 +unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain)
  13.331 +{
  13.332 +	return domain->cpu_ns;
  13.333 +}
  13.334 +
  13.335 +/* Find the number of VCPUs allocated to a domain */
  13.336 +unsigned int xenstat_domain_num_vcpus(xenstat_domain * domain)
  13.337 +{
  13.338 +	return domain->num_vcpus;
  13.339 +}
  13.340 +
  13.341 +xenstat_vcpu *xenstat_domain_vcpu(xenstat_domain * domain, unsigned int vcpu)
  13.342 +{
  13.343 +	if (0 <= vcpu && vcpu < domain->num_vcpus)
  13.344 +		return &(domain->vcpus[vcpu]);
  13.345 +	return NULL;
  13.346 +}
  13.347 +
  13.348 +/* Find the current memory reservation for this domain */
  13.349 +unsigned long long xenstat_domain_cur_mem(xenstat_domain * domain)
  13.350 +{
  13.351 +	return domain->cur_mem;
  13.352 +}
  13.353 +
  13.354 +/* Find the maximum memory reservation for this domain */
  13.355 +unsigned long long xenstat_domain_max_mem(xenstat_domain * domain)
  13.356 +{
  13.357 +	return domain->max_mem;
  13.358 +}
  13.359 +
  13.360 +/* Find the domain's SSID */
  13.361 +unsigned int xenstat_domain_ssid(xenstat_domain * domain)
  13.362 +{
  13.363 +	return domain->ssid;
  13.364 +}
  13.365 +
  13.366 +/* Get domain states */
  13.367 +unsigned int xenstat_domain_dying(xenstat_domain * domain)
  13.368 +{
  13.369 +	return (domain->state & DOMFLAGS_DYING) == DOMFLAGS_DYING;
  13.370 +}
  13.371 +
  13.372 +unsigned int xenstat_domain_crashed(xenstat_domain * domain)
  13.373 +{
  13.374 +	return ((domain->state & DOMFLAGS_SHUTDOWN) == DOMFLAGS_SHUTDOWN)
  13.375 +	    && (((domain->state >> DOMFLAGS_SHUTDOWNSHIFT)
  13.376 +		 & DOMFLAGS_SHUTDOWNMASK) == SHUTDOWN_crash);
  13.377 +}
  13.378 +
  13.379 +unsigned int xenstat_domain_shutdown(xenstat_domain * domain)
  13.380 +{
  13.381 +	return ((domain->state & DOMFLAGS_SHUTDOWN) == DOMFLAGS_SHUTDOWN)
  13.382 +	    && (((domain->state >> DOMFLAGS_SHUTDOWNSHIFT)
  13.383 +		 & DOMFLAGS_SHUTDOWNMASK) != SHUTDOWN_crash);
  13.384 +}
  13.385 +
  13.386 +unsigned int xenstat_domain_paused(xenstat_domain * domain)
  13.387 +{
  13.388 +	return (domain->state & DOMFLAGS_PAUSED) == DOMFLAGS_PAUSED;
  13.389 +}
  13.390 +
  13.391 +unsigned int xenstat_domain_blocked(xenstat_domain * domain)
  13.392 +{
  13.393 +	return (domain->state & DOMFLAGS_BLOCKED) == DOMFLAGS_BLOCKED;
  13.394 +}
  13.395 +
  13.396 +unsigned int xenstat_domain_running(xenstat_domain * domain)
  13.397 +{
  13.398 +	return (domain->state & DOMFLAGS_RUNNING) == DOMFLAGS_RUNNING;
  13.399 +}
  13.400 +
  13.401 +/* Get the number of networks for a given domain */
  13.402 +unsigned int xenstat_domain_num_networks(xenstat_domain * domain)
  13.403 +{
  13.404 +	return domain->num_networks;
  13.405 +}
  13.406 +
  13.407 +/* Get the network handle to obtain network stats */
  13.408 +xenstat_network *xenstat_domain_network(xenstat_domain * domain,
  13.409 +					unsigned int network)
  13.410 +{
  13.411 +	if (domain->networks && 0 <= network && network < domain->num_networks)
  13.412 +		return &(domain->networks[network]);
  13.413 +	return NULL;
  13.414 +}
  13.415 +
  13.416 +/*
  13.417 + * VCPU functions
  13.418 + */
  13.419 +/* Collect information about VCPUs */
  13.420 +static int xenstat_collect_vcpus(xenstat_handle * handle, xenstat_node * node)
  13.421 +{
  13.422 +	unsigned int i, vcpu;
  13.423 +	/* Fill in VCPU information */
  13.424 +	for (i = 0; i < node->num_domains; i++) {
  13.425 +		node->domains[i].vcpus = malloc(node->domains[i].num_vcpus
  13.426 +						* sizeof(xenstat_vcpu));
  13.427 +		if (node->domains[i].vcpus == NULL)
  13.428 +			return 0;
  13.429 +
  13.430 +		for (vcpu = 0; vcpu < node->domains[i].num_vcpus; vcpu++) {
  13.431 +			/* FIXME: need to be using a more efficient mechanism*/
  13.432 +			long long vcpu_time;
  13.433 +			vcpu_time =
  13.434 +			    xi_get_vcpu_usage(handle->xihandle,
  13.435 +					      node->domains[i].id,
  13.436 +					      vcpu);
  13.437 +			if (vcpu_time < 0)
  13.438 +				return 0;
  13.439 +			node->domains[i].vcpus[vcpu].ns = vcpu_time;
  13.440 +		}
  13.441 +	}
  13.442 +	return 1;
  13.443 +}
  13.444 +
  13.445 +/* Free VCPU information */
  13.446 +static void xenstat_free_vcpus(xenstat_node * node)
  13.447 +{
  13.448 +	unsigned int i;
  13.449 +	for (i = 0; i < node->num_domains; i++)
  13.450 +		free(node->domains[i].vcpus);
  13.451 +}
  13.452 +
  13.453 +/* Free VCPU information in handle - nothing to do */
  13.454 +static void xenstat_uninit_vcpus(xenstat_handle * handle)
  13.455 +{
  13.456 +}
  13.457 +
  13.458 +/* Get VCPU usage */
  13.459 +unsigned long long xenstat_vcpu_ns(xenstat_vcpu * vcpu)
  13.460 +{
  13.461 +	return vcpu->ns;
  13.462 +}
  13.463 +
  13.464 +/*
  13.465 + * Network functions
  13.466 + */
  13.467 +
  13.468 +/* Expected format of /proc/net/dev */
  13.469 +static const char PROCNETDEV_HEADER[] =
  13.470 +    "Inter-|   Receive                                                |"
  13.471 +    "  Transmit\n"
  13.472 +    " face |bytes    packets errs drop fifo frame compressed multicast|"
  13.473 +    "bytes    packets errs drop fifo colls carrier compressed\n";
  13.474 +
  13.475 +/* Collect information about networks */
  13.476 +static int xenstat_collect_networks(xenstat_handle * handle,
  13.477 +				    xenstat_node * node)
  13.478 +{
  13.479 +	/* Open and validate /proc/net/dev if we haven't already */
  13.480 +	if (handle->procnetdev == NULL) {
  13.481 +		char header[sizeof(PROCNETDEV_HEADER)];
  13.482 +		handle->procnetdev = fopen("/proc/net/dev", "r");
  13.483 +		if (handle->procnetdev == NULL) {
  13.484 +			perror("Error opening /proc/net/dev");
  13.485 +			return 1;
  13.486 +		}
  13.487 +
  13.488 +		/* Validate the format of /proc/net/dev */
  13.489 +		if (fread(header, sizeof(PROCNETDEV_HEADER) - 1, 1,
  13.490 +			  handle->procnetdev) != 1) {
  13.491 +			perror("Error reading /proc/net/dev header");
  13.492 +			return 1;
  13.493 +		}
  13.494 +		header[sizeof(PROCNETDEV_HEADER) - 1] = '\0';
  13.495 +		if (strcmp(header, PROCNETDEV_HEADER) != 0) {
  13.496 +			fprintf(stderr,
  13.497 +				"Unexpected /proc/net/dev format\n");
  13.498 +			return 1;
  13.499 +		}
  13.500 +	}
  13.501 +
  13.502 +	/* Fill in networks */
  13.503 +	/* FIXME: optimize this */
  13.504 +	fseek(handle->procnetdev, sizeof(PROCNETDEV_HEADER) - 1, SEEK_SET);
  13.505 +	while (1) {
  13.506 +		xenstat_domain *domain;
  13.507 +		xenstat_network net;
  13.508 +		unsigned int domid;
  13.509 +		int ret = fscanf(handle->procnetdev,
  13.510 +				 "vif%u.%u:%llu%llu%llu%llu%*u%*u%*u%*u"
  13.511 +				 "%llu%llu%llu%llu%*u%*u%*u%*u",
  13.512 +				 &domid, &net.id,
  13.513 +				 &net.tbytes, &net.tpackets, &net.terrs,
  13.514 +				 &net.tdrop,
  13.515 +				 &net.rbytes, &net.rpackets, &net.rerrs,
  13.516 +				 &net.rdrop);
  13.517 +		if (ret == EOF)
  13.518 +			break;
  13.519 +		if (ret != 10) {
  13.520 +			unsigned int c;
  13.521 +			do {
  13.522 +				c = fgetc(handle->procnetdev);
  13.523 +			} while (c != '\n' && c != EOF);
  13.524 +			if (c == EOF)
  13.525 +				break;
  13.526 +			continue;
  13.527 +		}
  13.528 +
  13.529 +		/* FIXME: this does a search for the domid */
  13.530 +		domain = xenstat_node_domain(node, domid);
  13.531 +		if (domain == NULL) {
  13.532 +			fprintf(stderr,
  13.533 +				"Found interface vif%u.%u but domain %u"
  13.534 +				" does not exist.\n", domid, net.id,
  13.535 +				domid);
  13.536 +			continue;
  13.537 +		}
  13.538 +		if (domain->networks == NULL) {
  13.539 +			domain->num_networks = 1;
  13.540 +			domain->networks = malloc(sizeof(xenstat_network));
  13.541 +		} else {
  13.542 +			domain->num_networks++;
  13.543 +			domain->networks =
  13.544 +			    realloc(domain->networks,
  13.545 +				    domain->num_networks *
  13.546 +				    sizeof(xenstat_network));
  13.547 +		}
  13.548 +		if (domain->networks == NULL)
  13.549 +			return 1;
  13.550 +		domain->networks[domain->num_networks - 1] = net;
  13.551 +	}
  13.552 +
  13.553 +	return 1;
  13.554 +}
  13.555 +
  13.556 +/* Free network information */
  13.557 +static void xenstat_free_networks(xenstat_node * node)
  13.558 +{
  13.559 +	unsigned int i;
  13.560 +	for (i = 0; i < node->num_domains; i++)
  13.561 +		free(node->domains[i].networks);
  13.562 +}
  13.563 +
  13.564 +/* Free network information in handle */
  13.565 +static void xenstat_uninit_networks(xenstat_handle * handle)
  13.566 +{
  13.567 +	if(handle->procnetdev)
  13.568 +		fclose(handle->procnetdev);
  13.569 +}
  13.570 +
  13.571 +/* Get the network ID */
  13.572 +unsigned int xenstat_network_id(xenstat_network * network)
  13.573 +{
  13.574 +	return network->id;
  13.575 +}
  13.576 +
  13.577 +/* Get the number of receive bytes */
  13.578 +unsigned long long xenstat_network_rbytes(xenstat_network * network)
  13.579 +{
  13.580 +	return network->rbytes;
  13.581 +}
  13.582 +
  13.583 +/* Get the number of receive packets */
  13.584 +unsigned long long xenstat_network_rpackets(xenstat_network * network)
  13.585 +{
  13.586 +	return network->rpackets;
  13.587 +}
  13.588 +
  13.589 +/* Get the number of receive errors */
  13.590 +unsigned long long xenstat_network_rerrs(xenstat_network * network)
  13.591 +{
  13.592 +	return network->rerrs;
  13.593 +}
  13.594 +
  13.595 +/* Get the number of receive drops */
  13.596 +unsigned long long xenstat_network_rdrop(xenstat_network * network)
  13.597 +{
  13.598 +	return network->rdrop;
  13.599 +}
  13.600 +
  13.601 +/* Get the number of transmit bytes */
  13.602 +unsigned long long xenstat_network_tbytes(xenstat_network * network)
  13.603 +{
  13.604 +	return network->tbytes;
  13.605 +}
  13.606 +
  13.607 +/* Get the number of transmit packets */
  13.608 +unsigned long long xenstat_network_tpackets(xenstat_network * network)
  13.609 +{
  13.610 +	return network->tpackets;
  13.611 +}
  13.612 +
  13.613 +/* Get the number of transmit errors */
  13.614 +unsigned long long xenstat_network_terrs(xenstat_network * network)
  13.615 +{
  13.616 +	return network->terrs;
  13.617 +}
  13.618 +
  13.619 +/* Get the number of transmit dropped packets */
  13.620 +unsigned long long xenstat_network_tdrop(xenstat_network * network)
  13.621 +{
  13.622 +	return network->tdrop;
  13.623 +}
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/tools/xenstat/libxenstat/src/xenstat.h	Mon Aug 22 21:54:28 2005 +0000
    14.3 @@ -0,0 +1,148 @@
    14.4 +/* libxenstat: statistics-collection library for Xen
    14.5 + * Copyright (C) International Business Machines Corp., 2005
    14.6 + * Authors: Josh Triplett <josht@us.ibm.com>
    14.7 + *          Judy Fischbach <jfisch@us.ibm.com>
    14.8 + *          David Hendricks <dhendrix@us.ibm.com>
    14.9 + *
   14.10 + * This library is free software; you can redistribute it and/or
   14.11 + * modify it under the terms of the GNU Lesser General Public
   14.12 + * License as published by the Free Software Foundation; either
   14.13 + * version 2.1 of the License, or (at your option) any later version.
   14.14 + *
   14.15 + * This library is distributed in the hope that it will be useful,
   14.16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14.18 + * Lesser General Public License for more details.
   14.19 + */
   14.20 +
   14.21 +/* libxenstat API */
   14.22 +
   14.23 +/* Opaque handles */
   14.24 +typedef struct xenstat_handle xenstat_handle;
   14.25 +typedef struct xenstat_domain xenstat_domain;
   14.26 +typedef struct xenstat_node xenstat_node;
   14.27 +typedef struct xenstat_vcpu xenstat_vcpu;
   14.28 +typedef struct xenstat_network xenstat_network;
   14.29 +
   14.30 +/* Initialize the xenstat library.  Returns a handle to be used with
   14.31 + * subsequent calls to the xenstat library, or NULL if an error occurs. */
   14.32 +xenstat_handle *xenstat_init();
   14.33 +
   14.34 +/* Release the handle to libxc, free resources, etc. */
   14.35 +void xenstat_uninit(xenstat_handle * handle);
   14.36 +
   14.37 +/* Get all available information about a node */
   14.38 +#define XENSTAT_VCPU 0x1
   14.39 +#define XENSTAT_NETWORK 0x2
   14.40 +#define XENSTAT_ALL (XENSTAT_VCPU|XENSTAT_NETWORK)
   14.41 +xenstat_node *xenstat_get_node(xenstat_handle * handle, unsigned int flags);
   14.42 +
   14.43 +/* Free the information */
   14.44 +void xenstat_free_node(xenstat_node * node);
   14.45 +
   14.46 +/*
   14.47 + * Node functions - extract information from a xenstat_node
   14.48 + */
   14.49 +
   14.50 +/* Get information about the domain with the given domain ID */
   14.51 +xenstat_domain *xenstat_node_domain(xenstat_node * node,
   14.52 +				    unsigned int domid);
   14.53 +
   14.54 +/* Get the domain with the given index; used to loop over all domains. */
   14.55 +xenstat_domain *xenstat_node_domain_by_index(xenstat_node * node,
   14.56 +					     unsigned index);
   14.57 +
   14.58 +/* Get amount of total memory on a node */
   14.59 +unsigned long long xenstat_node_tot_mem(xenstat_node * node);
   14.60 +
   14.61 +/* Get amount of free memory on a node */
   14.62 +unsigned long long xenstat_node_free_mem(xenstat_node * node);
   14.63 +
   14.64 +/* Find the number of domains existing on a node */
   14.65 +unsigned int xenstat_node_num_domains(xenstat_node * node);
   14.66 +
   14.67 +/* Find the number of CPUs existing on a node */
   14.68 +unsigned int xenstat_node_num_cpus(xenstat_node * node);
   14.69 +
   14.70 +/* Get information about the CPU speed */
   14.71 +unsigned long long xenstat_node_cpu_hz(xenstat_node * node);
   14.72 +
   14.73 +/*
   14.74 + * Domain functions - extract information from a xenstat_domain
   14.75 + */
   14.76 +
   14.77 +/* Get the domain ID for this domain */
   14.78 +unsigned xenstat_domain_id(xenstat_domain * domain);
   14.79 +
   14.80 +/* Get information about how much CPU time has been used */
   14.81 +unsigned long long xenstat_domain_cpu_ns(xenstat_domain * domain);
   14.82 +
   14.83 +/* Find the number of VCPUs allocated to a domain */
   14.84 +unsigned int xenstat_domain_num_vcpus(xenstat_domain * domain);
   14.85 +
   14.86 +/* Get the VCPU handle to obtain VCPU stats */
   14.87 +xenstat_vcpu *xenstat_domain_vcpu(xenstat_domain * domain,
   14.88 +				  unsigned int vcpu);
   14.89 +
   14.90 +/* Find the current memory reservation for this domain */
   14.91 +unsigned long long xenstat_domain_cur_mem(xenstat_domain * domain);
   14.92 +
   14.93 +/* Find the maximum memory reservation for this domain */
   14.94 +unsigned long long xenstat_domain_max_mem(xenstat_domain * domain);
   14.95 +
   14.96 +/* Find the domain's SSID */
   14.97 +unsigned int xenstat_domain_ssid(xenstat_domain * domain);
   14.98 +
   14.99 +/* Get domain states */
  14.100 +unsigned int xenstat_domain_dying(xenstat_domain * domain);
  14.101 +unsigned int xenstat_domain_crashed(xenstat_domain * domain);
  14.102 +unsigned int xenstat_domain_shutdown(xenstat_domain * domain);
  14.103 +unsigned int xenstat_domain_paused(xenstat_domain * domain);
  14.104 +unsigned int xenstat_domain_blocked(xenstat_domain * domain);
  14.105 +unsigned int xenstat_domain_running(xenstat_domain * domain);
  14.106 +
  14.107 +/* Get the number of networks for a given domain */
  14.108 +unsigned int xenstat_domain_num_networks(xenstat_domain *);
  14.109 +
  14.110 +/* Get the network handle to obtain network stats */
  14.111 +xenstat_network *xenstat_domain_network(xenstat_domain * domain,
  14.112 +					unsigned int network);
  14.113 +
  14.114 +/*
  14.115 + * VCPU functions - extract information from a xenstat_vcpu
  14.116 + */
  14.117 +
  14.118 +/* Get VCPU usage */
  14.119 +unsigned long long xenstat_vcpu_ns(xenstat_vcpu * vcpu);
  14.120 +
  14.121 +
  14.122 +/*
  14.123 + * Network functions - extract information from a xenstat_network
  14.124 + */
  14.125 +
  14.126 +/* Get the ID for this network */
  14.127 +unsigned int xenstat_network_id(xenstat_network * network);
  14.128 +
  14.129 +/* Get the number of receive bytes for this network */
  14.130 +unsigned long long xenstat_network_rbytes(xenstat_network * network);
  14.131 +
  14.132 +/* Get the number of receive packets for this network */
  14.133 +unsigned long long xenstat_network_rpackets(xenstat_network * network);
  14.134 +
  14.135 +/* Get the number of receive errors for this network */
  14.136 +unsigned long long xenstat_network_rerrs(xenstat_network * network);
  14.137 +
  14.138 +/* Get the number of receive drops for this network */
  14.139 +unsigned long long xenstat_network_rdrop(xenstat_network * network);
  14.140 +
  14.141 +/* Get the number of transmit bytes for this network */
  14.142 +unsigned long long xenstat_network_tbytes(xenstat_network * network);
  14.143 +
  14.144 +/* Get the number of transmit packets for this network */
  14.145 +unsigned long long xenstat_network_tpackets(xenstat_network * network);
  14.146 +
  14.147 +/* Get the number of transmit errors for this network */
  14.148 +unsigned long long xenstat_network_terrs(xenstat_network * network);
  14.149 +
  14.150 +/* Get the number of transmit drops for this network */
  14.151 +unsigned long long xenstat_network_tdrop(xenstat_network * network);
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/tools/xenstat/xentop/Makefile	Mon Aug 22 21:54:28 2005 +0000
    15.3 @@ -0,0 +1,44 @@
    15.4 +# Copyright (C) International Business Machines Corp., 2005
    15.5 +# Author: Josh Triplett <josht@us.ibm.com>
    15.6 +# 
    15.7 +# This program is free software; you can redistribute it and/or modify
    15.8 +# it under the terms of the GNU General Public License as published by
    15.9 +# the Free Software Foundation; under version 2 of the License.
   15.10 +#
   15.11 +# This program is distributed in the hope that it will be useful,
   15.12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15.14 +# GNU General Public License for more details.
   15.15 +
   15.16 +XEN_ROOT=../../..
   15.17 +include $(XEN_ROOT)/tools/Rules.mk
   15.18 +
   15.19 +ifneq ($(XENSTAT_XENTOP),y)
   15.20 +all install xentop:
   15.21 +else
   15.22 +
   15.23 +INSTALL         = install
   15.24 +INSTALL_PROG    = $(INSTALL) -m0755 -D
   15.25 +INSTALL_DATA    = $(INSTALL) -m0644 -D
   15.26 +
   15.27 +prefix=/usr
   15.28 +mandir=$(prefix)/share/man
   15.29 +man1dir=$(mandir)/man1
   15.30 +sbindir=$(prefix)/sbin
   15.31 +
   15.32 +CFLAGS += -DGCC_PRINTF -Wall -Werror -I$(XEN_LIBXENSTAT)
   15.33 +LDFLAGS += -L$(XEN_LIBXENSTAT)
   15.34 +LDLIBS += -lxenstat -lcurses
   15.35 +
   15.36 +all: xentop
   15.37 +
   15.38 +xentop: xentop.o
   15.39 +
   15.40 +install: xentop xentop.1
   15.41 +	$(INSTALL_PROG) xentop $(DESTDIR)$(sbindir)/xentop
   15.42 +	$(INSTALL_DATA) xentop.1 $(DESTDIR)$(man1dir)/xentop.1
   15.43 +
   15.44 +endif
   15.45 +
   15.46 +clean:
   15.47 +	rm -f xentop xentop.o
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/tools/xenstat/xentop/TODO	Mon Aug 22 21:54:28 2005 +0000
    16.3 @@ -0,0 +1,34 @@
    16.4 +Display error messages on the help line after bad input at a prompt.
    16.5 +Fractional delay times
    16.6 +Use prompting to search for domains
    16.7 +Better line editing?
    16.8 +
    16.9 +* Make CPU in % more accurate
   16.10 +* Domain total network TX % and RX %
   16.11 +
   16.12 +Like Top, f feature, field select of domain columns, toggle the display of
   16.13 +field by typing the letter associated with field, if displayed it shows in
   16.14 +bold and the letter is Capitalized along with a leading asterisk for the
   16.15 +field, if not selected for display letter is lowercase, no leading asterisk
   16.16 +and field is not bolded.
   16.17 +
   16.18 +Like Top, ordering of domain columns, o feature Capital letter shifts left,
   16.19 +lowercase letter shifts right?
   16.20 +
   16.21 +Color
   16.22 +Full management: pause, destroy, create domains
   16.23 +
   16.24 +Add support for Virtual Block Devices (vbd)
   16.25 +
   16.26 +To think about:
   16.27 +Support for one than one node display (distributed monitoring 
   16.28 +from any node of all other nodes in a cluster)
   16.29 +Bottom line option (Switch node, Search node [tab completion?])
   16.30 +
   16.31 +Capture/Logging of resource information generated during a time interval.
   16.32 +-b batch mode dump snapshots to standard output (used with -n)
   16.33 +-n number of iterations to dump to standard output (unlimited if not specified)
   16.34 +-d monitor DomIDs as -dD1,-dD2 or -dD1,D2...
   16.35 +   Monitor only domains with specified domain IDs
   16.36 +-m monitor nodeIDs as -mN1,-mN2 or -mN1,N2...
   16.37 +   Monitor only domains with specified node IDs
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/tools/xenstat/xentop/xentop.1	Mon Aug 22 21:54:28 2005 +0000
    17.3 @@ -0,0 +1,88 @@
    17.4 +.\" Copyright (C) International Business Machines  Corp., 2005
    17.5 +.\" Author: Josh Triplett <josht@us.ibm.com>
    17.6 +.\"
    17.7 +.\" This program is free software; you can redistribute it and/or modify
    17.8 +.\" it under the terms of the GNU General Public License as published by
    17.9 +.\" the Free Software Foundation; under version 2 of the License.
   17.10 +.\"
   17.11 +.\" This program is distributed in the hope that it will be useful,
   17.12 +.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
   17.13 +.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17.14 +.\" GNU General Public License for more details.
   17.15 +.\"
   17.16 +.\" You should have received a copy of the GNU General Public License
   17.17 +.\" along with this program; if not, write to the Free Software
   17.18 +.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   17.19 +.TH xentop 1 "August 2005"
   17.20 +.SH NAME
   17.21 +\fBxentop\fR \- displays real-time information about a Xen system and domains
   17.22 +
   17.23 +.SH SYNOPSIS
   17.24 +.B xentop
   17.25 +[\fB\-h\fR]
   17.26 +[\fB\-V\fR]
   17.27 +[\fB\-d\fRSECONDS]
   17.28 +[\fB\-n\fR]
   17.29 +[\fB\-r\fR]
   17.30 +[\fB\-v\fR]
   17.31 +
   17.32 +.SH DESCRIPTION
   17.33 +\fBxentop\fR displays information about the Xen system and domains, in a
   17.34 +continually-updating manner.  Command-line options and interactive commands
   17.35 +can change the detail and format of the information displayed by \fBxentop\fR.
   17.36 +
   17.37 +.SH OPTIONS
   17.38 +.TP
   17.39 +\fB\-h\fR, \fB\-\-help\fR
   17.40 +display help and exit
   17.41 +.TP
   17.42 +\fB\-V\fR, \fB\-\-version\fR
   17.43 +output version information and exit
   17.44 +.TP
   17.45 +\fB\-d\fR, \fB\-\-delay\fR=\fISECONDS\fR
   17.46 +seconds between updates (default 1)
   17.47 +.TP
   17.48 +\fB\-n\fR, \fB\-\-networks\fR
   17.49 +output network information
   17.50 +.TP
   17.51 +\fB\-r\fR, \fB\-\-repeat\-header\fR
   17.52 +repeat table header before each domain
   17.53 +.TP
   17.54 +\fB\-v\fR, \fB\-\-vcpus\fR
   17.55 +output VCPU data
   17.56 +
   17.57 +.SH "INTERACTIVE COMMANDS"
   17.58 +All interactive commands are case-insensitive.
   17.59 +.TP
   17.60 +.B D
   17.61 +set delay between updates
   17.62 +.TP
   17.63 +.B N
   17.64 +toggle display of network information
   17.65 +.TP
   17.66 +.B Q, Esc
   17.67 +quit
   17.68 +.TP
   17.69 +.B R
   17.70 +toggle table header before each domain
   17.71 +.TP
   17.72 +.B S
   17.73 +cycle sort order
   17.74 +.TP
   17.75 +.B V
   17.76 +toggle display of VCPU information
   17.77 +.TP
   17.78 +.B Arrows
   17.79 +scroll domain display
   17.80 +
   17.81 +.SH AUTHORS
   17.82 +Written by Judy Fischbach, David Hendricks, and Josh Triplett
   17.83 +
   17.84 +.SH "REPORTING BUGS"
   17.85 +Report bugs to <dsteklof@us.ibm.com>.
   17.86 +
   17.87 +.SH COPYRIGHT
   17.88 +Copyright \(co 2005  International Business Machines  Corp
   17.89 +.br
   17.90 +This is free software; see the source for copying conditions.  There is NO
   17.91 +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tools/xenstat/xentop/xentop.c	Mon Aug 22 21:54:28 2005 +0000
    18.3 @@ -0,0 +1,876 @@
    18.4 +/*
    18.5 + *  Copyright (C) International Business Machines  Corp., 2005
    18.6 + *  Author(s): Judy Fischbach <jfisch@us.ibm.com>
    18.7 + *             David Hendricks <dhendrix@us.ibm.com>
    18.8 + *             Josh Triplett <josht@us.ibm.com>
    18.9 + *    based on code from Anthony Liguori <aliguori@us.ibm.com>
   18.10 + *
   18.11 + *  This program is free software; you can redistribute it and/or modify
   18.12 + *  it under the terms of the GNU General Public License as published by
   18.13 + *  the Free Software Foundation; under version 2 of the License.
   18.14 + *
   18.15 + *  This program is distributed in the hope that it will be useful,
   18.16 + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   18.17 + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18.18 + *  GNU General Public License for more details.
   18.19 + *
   18.20 + *  You should have received a copy of the GNU General Public License
   18.21 + *  along with this program; if not, write to the Free Software
   18.22 + *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   18.23 + */
   18.24 +#include <curses.h>
   18.25 +#include <ctype.h>
   18.26 +#include <errno.h>
   18.27 +#include <stdio.h>
   18.28 +#include <stdlib.h>
   18.29 +#include <string.h>
   18.30 +#include <sys/time.h>
   18.31 +#include <time.h>
   18.32 +#include <unistd.h>
   18.33 +
   18.34 +#include <xenstat.h>
   18.35 +
   18.36 +#define XENTOP_VERSION "1.0"
   18.37 +
   18.38 +#define XENTOP_DISCLAIMER \
   18.39 +"Copyright (C) 2005  International Business Machines  Corp\n"\
   18.40 +"This is free software; see the source for copying conditions.There is NO\n"\
   18.41 +"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
   18.42 +#define XENTOP_BUGSTO "Report bugs to <dsteklof@us.ibm.com>.\n"
   18.43 +
   18.44 +#define _GNU_SOURCE
   18.45 +#include <getopt.h>
   18.46 +
   18.47 +#if !defined(__GNUC__) && !defined(__GNUG__)
   18.48 +#define __attribute__(arg) /* empty */
   18.49 +#endif
   18.50 +
   18.51 +#define KEY_ESCAPE '\x1B'
   18.52 +
   18.53 +/*
   18.54 + * Function prototypes
   18.55 + */
   18.56 +/* Utility functions */
   18.57 +static void usage(const char *);
   18.58 +static void version(void);
   18.59 +static void cleanup(void);
   18.60 +static void fail(const char *);
   18.61 +static int current_row(void);
   18.62 +static int lines(void);
   18.63 +static void print(const char *, ...) __attribute__((format(printf,1,2)));
   18.64 +static void attr_addstr(int attr, const char *str);
   18.65 +static void set_delay(char *value);
   18.66 +static void set_prompt(char *new_prompt, void (*func)(char *));
   18.67 +static int handle_key(int);
   18.68 +static int compare(unsigned long long, unsigned long long);
   18.69 +static int compare_domains(xenstat_domain **, xenstat_domain **);
   18.70 +static unsigned long long tot_net_bytes( xenstat_domain *, int);
   18.71 +
   18.72 +/* Field functions */
   18.73 +static int compare_domid(xenstat_domain *domain1, xenstat_domain *domain2);
   18.74 +static void print_domid(xenstat_domain *domain);
   18.75 +static int compare_state(xenstat_domain *domain1, xenstat_domain *domain2);
   18.76 +static void print_state(xenstat_domain *domain);
   18.77 +static int compare_cpu(xenstat_domain *domain1, xenstat_domain *domain2);
   18.78 +static void print_cpu(xenstat_domain *domain);
   18.79 +static int compare_cpu_pct(xenstat_domain *domain1, xenstat_domain *domain2);
   18.80 +static void print_cpu_pct(xenstat_domain *domain);
   18.81 +static int compare_mem(xenstat_domain *domain1, xenstat_domain *domain2);
   18.82 +static void print_mem(xenstat_domain *domain);
   18.83 +static void print_mem_pct(xenstat_domain *domain);
   18.84 +static int compare_maxmem(xenstat_domain *domain1, xenstat_domain *domain2);
   18.85 +static void print_maxmem(xenstat_domain *domain);
   18.86 +static void print_max_pct(xenstat_domain *domain);
   18.87 +static int compare_vcpus(xenstat_domain *domain1, xenstat_domain *domain2);
   18.88 +static void print_vcpus(xenstat_domain *domain);
   18.89 +static int compare_nets(xenstat_domain *domain1, xenstat_domain *domain2);
   18.90 +static void print_nets(xenstat_domain *domain);
   18.91 +static int compare_net_tx(xenstat_domain *domain1, xenstat_domain *domain2);
   18.92 +static void print_net_tx(xenstat_domain *domain);
   18.93 +static int compare_net_rx(xenstat_domain *domain1, xenstat_domain *domain2);
   18.94 +static void print_net_rx(xenstat_domain *domain);
   18.95 +static int compare_ssid(xenstat_domain *domain1, xenstat_domain *domain2);
   18.96 +static void print_ssid(xenstat_domain *domain);
   18.97 +
   18.98 +/* Section printing functions */
   18.99 +static void do_summary(void);
  18.100 +static void do_header(void);
  18.101 +static void do_bottom_line(void);
  18.102 +static void do_domain(xenstat_domain *);
  18.103 +static void do_vcpu(xenstat_domain *);
  18.104 +static void do_network(xenstat_domain *);
  18.105 +static void top(void);
  18.106 +
  18.107 +/* Field types */
  18.108 +typedef enum field_id {
  18.109 +	FIELD_DOMID,
  18.110 +	FIELD_STATE,
  18.111 +	FIELD_CPU,
  18.112 +	FIELD_CPU_PCT,
  18.113 +	FIELD_MEM,
  18.114 +	FIELD_MEM_PCT,
  18.115 +	FIELD_MAXMEM,
  18.116 +	FIELD_MAX_PCT,
  18.117 +	FIELD_VCPUS,
  18.118 +	FIELD_NETS,
  18.119 +	FIELD_NET_TX,
  18.120 +	FIELD_NET_RX,
  18.121 +	FIELD_SSID
  18.122 +} field_id;
  18.123 +
  18.124 +typedef struct field {
  18.125 +	field_id num;
  18.126 +	const char *header;
  18.127 +	unsigned int default_width;
  18.128 +	int (*compare)(xenstat_domain *domain1, xenstat_domain *domain2);
  18.129 +	void (*print)(xenstat_domain *domain);
  18.130 +} field;
  18.131 +
  18.132 +field fields[] = {
  18.133 +	{ FIELD_DOMID,   "DOMID",      5, compare_domid,   print_domid   },
  18.134 +	{ FIELD_STATE,   "STATE",      6, compare_state,   print_state   },
  18.135 +	{ FIELD_CPU,     "CPU(sec)",  10, compare_cpu,     print_cpu     },
  18.136 +	{ FIELD_CPU_PCT, "CPU(%)",     6, compare_cpu_pct, print_cpu_pct },
  18.137 +	{ FIELD_MEM,     "MEM(k)",    10, compare_mem,     print_mem     },
  18.138 +	{ FIELD_MEM_PCT, "MEM(%)",     6, compare_mem,     print_mem_pct },
  18.139 +	{ FIELD_MAXMEM,  "MAXMEM(k)", 10, compare_maxmem,  print_maxmem  },
  18.140 +	{ FIELD_MAX_PCT, "MAXMEM(%)",  9, compare_maxmem,  print_max_pct },
  18.141 +	{ FIELD_VCPUS,   "VCPUS",      5, compare_vcpus,   print_vcpus   },
  18.142 +	{ FIELD_NETS,    "NETS",       4, compare_nets,    print_nets    },
  18.143 +	{ FIELD_NET_TX,  "NETTX(k)",   8, compare_net_tx,  print_net_tx  },
  18.144 +	{ FIELD_NET_RX,  "NETRX(k)",   8, compare_net_rx,  print_net_rx  },
  18.145 +	{ FIELD_SSID,    "SSID",       4, compare_ssid,    print_ssid    }
  18.146 +};
  18.147 +
  18.148 +const unsigned int NUM_FIELDS = sizeof(fields)/sizeof(field);
  18.149 +
  18.150 +/* Globals */
  18.151 +struct timeval curtime, oldtime;
  18.152 +xenstat_handle *xhandle = NULL;
  18.153 +xenstat_node *prev_node = NULL;
  18.154 +xenstat_node *cur_node = NULL;
  18.155 +field_id sort_field = FIELD_DOMID;
  18.156 +unsigned int first_domain_index = 0;
  18.157 +unsigned int delay = 1;
  18.158 +int show_vcpus = 0;
  18.159 +int show_networks = 0;
  18.160 +int repeat_header = 0;
  18.161 +#define PROMPT_VAL_LEN 80
  18.162 +char *prompt = NULL;
  18.163 +char prompt_val[PROMPT_VAL_LEN];
  18.164 +int prompt_val_len = 0;
  18.165 +void (*prompt_complete_func)(char *);
  18.166 +
  18.167 +/*
  18.168 + * Function definitions
  18.169 + */
  18.170 +
  18.171 +/* Utility functions */
  18.172 +
  18.173 +/* Print usage message, using given program name */
  18.174 +static void usage(const char *program)
  18.175 +{
  18.176 +	printf("Usage: %s [OPTION]\n"
  18.177 +	       "Displays ongoing information about xen vm resources \n\n"
  18.178 +	       "-h, --help           display this help and exit\n"
  18.179 +	       "-V, --version        output version information and exit\n"
  18.180 +	       "-d, --delay=SECONDS  seconds between updates (default 1)\n"
  18.181 +	       "-n, --networks       output vif network data\n"
  18.182 +	       "-r, --repeat-header  repeat table header before each domain\n"
  18.183 +	       "-v, --vcpus          output vcpu data\n"
  18.184 +	       "\n" XENTOP_BUGSTO,
  18.185 +	       program);
  18.186 +	return;
  18.187 +}
  18.188 +
  18.189 +/* Print program version information */
  18.190 +static void version(void)
  18.191 +{
  18.192 +	printf("xentop " XENTOP_VERSION "\n"
  18.193 +	       "Written by Judy Fischbach, David Hendricks, Josh Triplett\n"
  18.194 +	       "\n" XENTOP_DISCLAIMER);
  18.195 +}
  18.196 +
  18.197 +/* Clean up any open resources */
  18.198 +static void cleanup(void)
  18.199 +{
  18.200 +	if(!isendwin())
  18.201 +		endwin();
  18.202 +	if(prev_node != NULL)
  18.203 +		xenstat_free_node(prev_node);
  18.204 +	if(cur_node != NULL)
  18.205 +		xenstat_free_node(cur_node);
  18.206 +	if(xhandle != NULL)
  18.207 +		xenstat_uninit(xhandle);
  18.208 +}
  18.209 +
  18.210 +/* Display the given message and gracefully exit */
  18.211 +static void fail(const char *str)
  18.212 +{
  18.213 +	if(!isendwin())
  18.214 +		endwin();
  18.215 +	fprintf(stderr, str);
  18.216 +	exit(1);
  18.217 +}
  18.218 +
  18.219 +/* Return the row containing the cursor. */
  18.220 +static int current_row(void)
  18.221 +{
  18.222 +	int y, x;
  18.223 +	getyx(stdscr, y, x);
  18.224 +	return y;
  18.225 +}
  18.226 +
  18.227 +/* Return the number of lines on the screen. */
  18.228 +static int lines(void)
  18.229 +{
  18.230 +	int y, x;
  18.231 +	getmaxyx(stdscr, y, x);
  18.232 +	return y;
  18.233 +}
  18.234 +
  18.235 +/* printf-style print function which calls printw, but only if the cursor is
  18.236 + * not on the last line. */
  18.237 +static void print(const char *fmt, ...)
  18.238 +{
  18.239 +	va_list args;
  18.240 +
  18.241 +	if(current_row() < lines()-1) {
  18.242 +		va_start(args, fmt);
  18.243 +		vw_printw(stdscr, fmt, args);
  18.244 +		va_end(args);
  18.245 +	}
  18.246 +}
  18.247 +
  18.248 +/* Print a string with the given attributes set. */
  18.249 +static void attr_addstr(int attr, const char *str)
  18.250 +{
  18.251 +	attron(attr);
  18.252 +	addstr(str);
  18.253 +	attroff(attr);
  18.254 +}
  18.255 +
  18.256 +/* Handle setting the delay from the user-supplied value in prompt_val */
  18.257 +static void set_delay(char *value)
  18.258 +{
  18.259 +	int new_delay;
  18.260 +	new_delay = atoi(prompt_val);
  18.261 +	if(new_delay > 0)
  18.262 +		delay = new_delay;
  18.263 +}
  18.264 +
  18.265 +/* Enable prompting mode with the given prompt string; call the given function
  18.266 + * when a value is available. */
  18.267 +static void set_prompt(char *new_prompt, void (*func)(char *))
  18.268 +{
  18.269 +	prompt = new_prompt;
  18.270 +	prompt_val[0] = '\0';
  18.271 +	prompt_val_len = 0;
  18.272 +	prompt_complete_func = func;
  18.273 +}
  18.274 +
  18.275 +/* Handle user input, return 0 if the program should quit, or 1 if not */
  18.276 +static int handle_key(int ch)
  18.277 +{
  18.278 +	if(prompt == NULL) {
  18.279 +		/* Not prompting for input; handle interactive commands */
  18.280 +		switch(ch) {
  18.281 +		case 'n': case 'N':
  18.282 +			show_networks ^= 1;
  18.283 +			break;
  18.284 +		case 'r': case 'R':
  18.285 +			repeat_header ^= 1;
  18.286 +			break;
  18.287 +		case 's': case 'S':
  18.288 +			sort_field = (sort_field + 1) % NUM_FIELDS;
  18.289 +			break;
  18.290 +		case 'v': case 'V':
  18.291 +			show_vcpus ^= 1;
  18.292 +			break;
  18.293 +		case KEY_DOWN:
  18.294 +			first_domain_index++;
  18.295 +			break;
  18.296 +		case KEY_UP:
  18.297 +			if(first_domain_index > 0)
  18.298 +				first_domain_index--;
  18.299 +			break;
  18.300 +		case 'd': case 'D':
  18.301 +			set_prompt("Delay(sec)", set_delay);
  18.302 +			break;
  18.303 +		case 'q': case 'Q': case KEY_ESCAPE:
  18.304 +			return 0;
  18.305 +		}
  18.306 +	} else {
  18.307 +		/* Prompting for input; handle line editing */
  18.308 +		switch(ch) {
  18.309 +		case '\r':
  18.310 +			prompt_complete_func(prompt_val);
  18.311 +			set_prompt(NULL, NULL);
  18.312 +			break;
  18.313 +		case KEY_ESCAPE:
  18.314 +			set_prompt(NULL, NULL);
  18.315 +			break;
  18.316 +		case KEY_BACKSPACE:
  18.317 +			if(prompt_val_len > 0)
  18.318 +				prompt_val[--prompt_val_len] = '\0';
  18.319 +		default:
  18.320 +			if((prompt_val_len+1) < PROMPT_VAL_LEN
  18.321 +			   && isprint(ch)) {
  18.322 +				prompt_val[prompt_val_len++] = (char)ch;
  18.323 +				prompt_val[prompt_val_len] = '\0';
  18.324 +			}
  18.325 +		}
  18.326 +	}
  18.327 +
  18.328 +	return 1;
  18.329 +}
  18.330 +
  18.331 +/* Compares two integers, returning -1,0,1 for <,=,> */
  18.332 +static int compare(unsigned long long i1, unsigned long long i2)
  18.333 +{
  18.334 +	if(i1 < i2)
  18.335 +		return -1;
  18.336 +	if(i1 > i2)
  18.337 +		return 1;
  18.338 +	return 0;
  18.339 +}
  18.340 +
  18.341 +/* Comparison function for use with qsort.  Compares two domains using the
  18.342 + * current sort field. */
  18.343 +static int compare_domains(xenstat_domain **domain1, xenstat_domain **domain2)
  18.344 +{
  18.345 +	return fields[sort_field].compare(*domain1, *domain2);
  18.346 +}
  18.347 +
  18.348 +/* Field functions */
  18.349 +
  18.350 +/* Compares domain ids of two domains, returning -1,0,1 for <,=,> */
  18.351 +int compare_domid(xenstat_domain *domain1, xenstat_domain *domain2)
  18.352 +{
  18.353 +	return compare(xenstat_domain_id(domain1), xenstat_domain_id(domain2));
  18.354 +}
  18.355 +
  18.356 +/* Prints domain identification number */
  18.357 +void print_domid(xenstat_domain *domain)
  18.358 +{
  18.359 +	print("%5u", xenstat_domain_id(domain));
  18.360 +}
  18.361 +
  18.362 +struct {
  18.363 +	unsigned int (*get)(xenstat_domain *);
  18.364 +	char ch;
  18.365 +} state_funcs[] = {
  18.366 +	{ xenstat_domain_dying,    'd' },
  18.367 +	{ xenstat_domain_shutdown, 's' },
  18.368 +	{ xenstat_domain_blocked,  'b' },
  18.369 +	{ xenstat_domain_crashed,  'c' },
  18.370 +	{ xenstat_domain_paused,   'p' },
  18.371 +	{ xenstat_domain_running,  'r' }
  18.372 +};
  18.373 +const unsigned int NUM_STATES = sizeof(state_funcs)/sizeof(*state_funcs);
  18.374 +
  18.375 +/* Compare states of two domains, returning -1,0,1 for <,=,> */
  18.376 +static int compare_state(xenstat_domain *domain1, xenstat_domain *domain2)
  18.377 +{
  18.378 +	unsigned int i, d1s, d2s;
  18.379 +	for(i = 0; i < NUM_STATES; i++) {
  18.380 +		d1s = state_funcs[i].get(domain1);
  18.381 +		d2s = state_funcs[i].get(domain2);
  18.382 +		if(d1s && !d2s)
  18.383 +			return -1;
  18.384 +		if(d2s && !d1s)
  18.385 +			return 1;
  18.386 +	}
  18.387 +	return 0;
  18.388 +}
  18.389 +
  18.390 +/* Prints domain state in abbreviated letter format */
  18.391 +static void print_state(xenstat_domain *domain)
  18.392 +{
  18.393 +	unsigned int i;
  18.394 +	for(i = 0; i < NUM_STATES; i++)
  18.395 +		print("%c", state_funcs[i].get(domain) ? state_funcs[i].ch
  18.396 +		                                       : '-');
  18.397 +}
  18.398 +
  18.399 +/* Compares cpu usage of two domains, returning -1,0,1 for <,=,> */
  18.400 +static int compare_cpu(xenstat_domain *domain1, xenstat_domain *domain2)
  18.401 +{
  18.402 +	return -compare(xenstat_domain_cpu_ns(domain1),
  18.403 +			xenstat_domain_cpu_ns(domain2));
  18.404 +}
  18.405 +
  18.406 +/* Prints domain cpu usage in seconds */
  18.407 +static void print_cpu(xenstat_domain *domain)
  18.408 +{
  18.409 +	print("%10llu", xenstat_domain_cpu_ns(domain)/1000000000);
  18.410 +}
  18.411 +
  18.412 +/* Computes the CPU percentage used for a specified domain */
  18.413 +static double get_cpu_pct(xenstat_domain *domain)
  18.414 +{
  18.415 +	xenstat_domain *old_domain;
  18.416 +	double us_elapsed;
  18.417 +
  18.418 +	/* Can't calculate CPU percentage without a previous sample. */
  18.419 +	if(prev_node == NULL)
  18.420 +		return 0.0;
  18.421 +
  18.422 +	old_domain = xenstat_node_domain(prev_node, xenstat_domain_id(domain));
  18.423 +	if(old_domain == NULL)
  18.424 +		return 0.0;
  18.425 +
  18.426 +	/* Calculate the time elapsed in microseconds */
  18.427 +	us_elapsed = ((curtime.tv_sec-oldtime.tv_sec)*1000000.0
  18.428 +		      +(curtime.tv_usec - oldtime.tv_usec));
  18.429 +
  18.430 +	/* In the following, nanoseconds must be multiplied by 1000.0 to
  18.431 +	 * convert to microseconds, then divided by 100.0 to get a percentage,
  18.432 +	 * resulting in a multiplication by 10.0 */
  18.433 +	return ((xenstat_domain_cpu_ns(domain)
  18.434 +		 -xenstat_domain_cpu_ns(old_domain))/10.0)/us_elapsed;
  18.435 +}
  18.436 +
  18.437 +static int compare_cpu_pct(xenstat_domain *domain1, xenstat_domain *domain2)
  18.438 +{
  18.439 +	return -compare(get_cpu_pct(domain1), get_cpu_pct(domain2));
  18.440 +}
  18.441 +
  18.442 +/* Prints cpu percentage statistic */
  18.443 +static void print_cpu_pct(xenstat_domain *domain)
  18.444 +{
  18.445 +	print("%6.1f", get_cpu_pct(domain));
  18.446 +}
  18.447 +
  18.448 +/* Compares current memory of two domains, returning -1,0,1 for <,=,> */
  18.449 +static int compare_mem(xenstat_domain *domain1, xenstat_domain *domain2)
  18.450 +{
  18.451 +	return -compare(xenstat_domain_cur_mem(domain1),
  18.452 +	                xenstat_domain_cur_mem(domain2));
  18.453 +}
  18.454 +
  18.455 +/* Prints current memory statistic */
  18.456 +static void print_mem(xenstat_domain *domain)
  18.457 +{
  18.458 +	print("%10llu", xenstat_domain_cur_mem(domain)/1024);
  18.459 +}
  18.460 +
  18.461 +/* Prints memory percentage statistic, ratio of current domain memory to total
  18.462 + * node memory */
  18.463 +static void print_mem_pct(xenstat_domain *domain)
  18.464 +{
  18.465 +	print("%6.1f", (double)xenstat_domain_cur_mem(domain) /
  18.466 +	               (double)xenstat_node_tot_mem(cur_node) * 100);
  18.467 +}
  18.468 +
  18.469 +/* Compares maximum memory of two domains, returning -1,0,1 for <,=,> */
  18.470 +static int compare_maxmem(xenstat_domain *domain1, xenstat_domain *domain2)
  18.471 +{
  18.472 +	return -compare(xenstat_domain_max_mem(domain1),
  18.473 +	                xenstat_domain_max_mem(domain2));
  18.474 +}
  18.475 +
  18.476 +/* Prints maximum domain memory statistic in KB */
  18.477 +static void print_maxmem(xenstat_domain *domain)
  18.478 +{
  18.479 +	unsigned long long max_mem = xenstat_domain_max_mem(domain);
  18.480 +	if(max_mem == ((unsigned long long)-1))
  18.481 +		print("%10s", "no limit");
  18.482 +	else
  18.483 +		print("%10llu", max_mem/1024);
  18.484 +}
  18.485 +
  18.486 +/* Prints memory percentage statistic, ratio of current domain memory to total
  18.487 + * node memory */
  18.488 +static void print_max_pct(xenstat_domain *domain)
  18.489 +{
  18.490 +	if (xenstat_domain_max_mem(domain) == (unsigned long long)-1)
  18.491 +		print("%9s", "n/a");
  18.492 +	else
  18.493 +		print("%9.1f", (double)xenstat_domain_max_mem(domain) /
  18.494 +		               (double)xenstat_node_tot_mem(cur_node) * 100);
  18.495 +}
  18.496 +
  18.497 +/* Compares number of virtual CPUs of two domains, returning -1,0,1 for
  18.498 + * <,=,> */
  18.499 +static int compare_vcpus(xenstat_domain *domain1, xenstat_domain *domain2)
  18.500 +{
  18.501 +	return -compare(xenstat_domain_num_vcpus(domain1),
  18.502 +	                xenstat_domain_num_vcpus(domain2));
  18.503 +}
  18.504 +
  18.505 +/* Prints number of virtual CPUs statistic */
  18.506 +static void print_vcpus(xenstat_domain *domain)
  18.507 +{
  18.508 +	print("%5u", xenstat_domain_num_vcpus(domain));
  18.509 +}
  18.510 +
  18.511 +/* Compares number of virtual networks of two domains, returning -1,0,1 for
  18.512 + * <,=,> */
  18.513 +static int compare_nets(xenstat_domain *domain1, xenstat_domain *domain2)
  18.514 +{
  18.515 +	return -compare(xenstat_domain_num_networks(domain1),
  18.516 +	                xenstat_domain_num_networks(domain2));
  18.517 +}
  18.518 +
  18.519 +/* Prints number of virtual networks statistic */
  18.520 +static void print_nets(xenstat_domain *domain)
  18.521 +{
  18.522 +	print("%4u", xenstat_domain_num_networks(domain));
  18.523 +}
  18.524 +
  18.525 +/* Compares number of total network tx bytes of two domains, returning -1,0,1 for
  18.526 + * <,=,> */
  18.527 +static int compare_net_tx(xenstat_domain *domain1, xenstat_domain *domain2)
  18.528 +{
  18.529 +	return -compare(tot_net_bytes(domain1, FALSE),
  18.530 +	                tot_net_bytes(domain2, FALSE));
  18.531 +}
  18.532 +
  18.533 +/* Prints number of total network tx bytes statistic */
  18.534 +static void print_net_tx(xenstat_domain *domain)
  18.535 +{
  18.536 +	print("%8llu", tot_net_bytes(domain, FALSE)/1024);
  18.537 +}
  18.538 +
  18.539 +/* Compares number of total network rx bytes of two domains, returning -1,0,1 for
  18.540 + * <,=,> */
  18.541 +static int compare_net_rx(xenstat_domain *domain1, xenstat_domain *domain2)
  18.542 +{
  18.543 +	return -compare(tot_net_bytes(domain1, TRUE),
  18.544 +	                tot_net_bytes(domain2, TRUE));
  18.545 +}
  18.546 +
  18.547 +/* Prints number of total network rx bytes statistic */
  18.548 +static void print_net_rx(xenstat_domain *domain)
  18.549 +{
  18.550 +	print("%8llu", tot_net_bytes(domain, TRUE)/1024);
  18.551 +}
  18.552 +
  18.553 +/* Gets number of total network bytes statistic, if rx true, then rx bytes
  18.554 + * otherwise tx bytes
  18.555 + */
  18.556 +static unsigned long long tot_net_bytes(xenstat_domain *domain, int rx_flag)
  18.557 +{
  18.558 +	int i = 0;
  18.559 +	xenstat_network *network;
  18.560 +	unsigned num_networks = 0;
  18.561 +        unsigned long long total = 0;
  18.562 +
  18.563 +	/* How many networks? */
  18.564 +	num_networks = xenstat_domain_num_networks(domain);
  18.565 +
  18.566 +	/* Dump information for each network */
  18.567 +	for (i=0; i < num_networks; i++) {
  18.568 +		/* Next get the network information */
  18.569 +		network = xenstat_domain_network(domain,i);
  18.570 +                if (rx_flag) 
  18.571 +			total += xenstat_network_rbytes(network);
  18.572 +                else 
  18.573 +			total += xenstat_network_tbytes(network);
  18.574 +	}
  18.575 +        return (total);
  18.576 +}
  18.577 +
  18.578 +/* Compares security id (ssid) of two domains, returning -1,0,1 for <,=,> */
  18.579 +static int compare_ssid(xenstat_domain *domain1, xenstat_domain *domain2)
  18.580 +{
  18.581 +	return compare(xenstat_domain_ssid(domain1),
  18.582 +		       xenstat_domain_ssid(domain2));
  18.583 +}
  18.584 +
  18.585 +/* Prints ssid statistic */
  18.586 +static void print_ssid(xenstat_domain *domain)
  18.587 +{
  18.588 +	print("%4u", xenstat_domain_ssid(domain));
  18.589 +}
  18.590 +
  18.591 +/* Section printing functions */
  18.592 +/* Prints the top summary, above the domain table */
  18.593 +void do_summary(void)
  18.594 +{
  18.595 +#define TIME_STR_LEN 9
  18.596 +	const char *TIME_STR_FORMAT = "%H:%M:%S";
  18.597 +	char time_str[TIME_STR_LEN];
  18.598 +	unsigned run = 0, block = 0, pause = 0,
  18.599 +	         crash = 0, dying = 0, shutdown = 0;
  18.600 +	unsigned i, num_domains = 0;
  18.601 +	unsigned long long used = 0;
  18.602 +	xenstat_domain *domain;
  18.603 +
  18.604 +	/* Print program name, current time, and number of domains */
  18.605 +	strftime(time_str, TIME_STR_LEN, TIME_STR_FORMAT,
  18.606 +	         localtime(&curtime.tv_sec));
  18.607 +	num_domains = xenstat_node_num_domains(cur_node);
  18.608 +	print("xentop - %s\n", time_str);
  18.609 +
  18.610 +	/* Tabulate what states domains are in for summary */
  18.611 +	for (i=0; i < num_domains; i++) {
  18.612 +		domain = xenstat_node_domain_by_index(cur_node,i);
  18.613 +		if (xenstat_domain_running(domain)) run++;
  18.614 +		else if (xenstat_domain_blocked(domain)) block++;
  18.615 +		else if (xenstat_domain_paused(domain)) pause++;
  18.616 +		else if (xenstat_domain_shutdown(domain)) shutdown++;
  18.617 +		else if (xenstat_domain_crashed(domain)) crash++;
  18.618 +		else if (xenstat_domain_dying(domain)) dying++;
  18.619 +	}
  18.620 +
  18.621 +	print("%u domains: %u running, %u blocked, %u paused, "
  18.622 +	      "%u crashed, %u dying, %u shutdown \n",
  18.623 +	      num_domains, run, block, pause, crash, dying, shutdown);
  18.624 +
  18.625 +	used = xenstat_node_tot_mem(cur_node)-xenstat_node_free_mem(cur_node);
  18.626 +
  18.627 +	/* Dump node memory and cpu information */
  18.628 +	print("Mem: %lluk total, %lluk used, %lluk free    "
  18.629 +	      "CPUs: %u @ %lluMHz\n",
  18.630 +	      xenstat_node_tot_mem(cur_node)/1024, used/1024,
  18.631 +	      xenstat_node_free_mem(cur_node)/1024,
  18.632 +	      xenstat_node_num_cpus(cur_node),
  18.633 +	      xenstat_node_cpu_hz(cur_node)/1000000);
  18.634 +}
  18.635 +
  18.636 +/* Display the top header for the domain table */
  18.637 +void do_header(void)
  18.638 +{
  18.639 +	field_id i;
  18.640 +
  18.641 +	/* Turn on REVERSE highlight attribute for headings */
  18.642 +	attron(A_REVERSE);
  18.643 +	for(i = 0; i < NUM_FIELDS; i++) {
  18.644 +		if(i != 0)
  18.645 +			print(" ");
  18.646 +		/* The BOLD attribute is turned on for the sort column */
  18.647 +		if(i == sort_field)
  18.648 +			attron(A_BOLD);
  18.649 +		print("%*s", fields[i].default_width, fields[i].header);
  18.650 +		if(i == sort_field)
  18.651 +			attroff(A_BOLD);
  18.652 +	}
  18.653 +	attroff(A_REVERSE);
  18.654 +	print("\n");
  18.655 +}
  18.656 +
  18.657 +/* Displays bottom status line or current prompt */
  18.658 +void do_bottom_line(void)
  18.659 +{
  18.660 +	move(lines()-1, 2);
  18.661 +
  18.662 +	if (prompt != NULL) {
  18.663 +		printw("%s: %s", prompt, prompt_val);
  18.664 +	} else {
  18.665 +		addch(A_REVERSE | 'D'); addstr("elay  ");
  18.666 +
  18.667 +		/* network */
  18.668 +		addch(A_REVERSE | 'N');
  18.669 +		attr_addstr(show_networks ? COLOR_PAIR(1) : 0, "etworks");
  18.670 +		addstr("  ");
  18.671 +
  18.672 +		/* vcpus */
  18.673 +		addch(A_REVERSE | 'V');
  18.674 +		attr_addstr(show_vcpus ? COLOR_PAIR(1) : 0, "CPUs");
  18.675 +		addstr("  ");
  18.676 +
  18.677 +		/* repeat */
  18.678 +		addch(A_REVERSE | 'R');
  18.679 +		attr_addstr(repeat_header ? COLOR_PAIR(1) : 0, "epeat header");
  18.680 +		addstr("  ");
  18.681 +
  18.682 +		/* sort order */
  18.683 +		addch(A_REVERSE | 'S'); addstr("ort order  ");
  18.684 +
  18.685 +		addch(A_REVERSE | 'Q'); addstr("uit  ");
  18.686 +	}
  18.687 +}
  18.688 +
  18.689 +/* Prints Domain information */
  18.690 +void do_domain(xenstat_domain *domain)
  18.691 +{
  18.692 +	unsigned int i;
  18.693 +	for(i = 0; i < NUM_FIELDS; i++) {
  18.694 +		if(i != 0)
  18.695 +			print(" ");
  18.696 +		if(i == sort_field)
  18.697 +			attron(A_BOLD);
  18.698 +		fields[i].print(domain);
  18.699 +		if(i == sort_field)
  18.700 +			attroff(A_BOLD);
  18.701 +	}
  18.702 +	print("\n");
  18.703 +}
  18.704 +
  18.705 +/* Output all vcpu information */
  18.706 +void do_vcpu(xenstat_domain *domain)
  18.707 +{
  18.708 +	int i = 0;
  18.709 +	unsigned num_vcpus = 0;
  18.710 +	xenstat_vcpu *vcpu;
  18.711 +
  18.712 +	print("VCPUs(sec): ");
  18.713 +
  18.714 +	num_vcpus = xenstat_domain_num_vcpus(domain);
  18.715 +
  18.716 +	/* for all vcpus dump out values */
  18.717 +	for (i=0; i< num_vcpus; i++) {
  18.718 +		vcpu = xenstat_domain_vcpu(domain,i);
  18.719 +
  18.720 +		if (i != 0 && (i%5)==0)
  18.721 +			print("\n        ");
  18.722 +		print(" %2u: %10llus", i, xenstat_vcpu_ns(vcpu)/1000000000);
  18.723 +	}
  18.724 +	print("\n");
  18.725 +}
  18.726 +
  18.727 +/* Output all network information */
  18.728 +void do_network(xenstat_domain *domain)
  18.729 +{
  18.730 +	int i = 0;
  18.731 +	xenstat_network *network;
  18.732 +	unsigned num_networks = 0;
  18.733 +
  18.734 +	/* How many networks? */
  18.735 +	num_networks = xenstat_domain_num_networks(domain);
  18.736 +
  18.737 +	/* Dump information for each network */
  18.738 +	for (i=0; i < num_networks; i++) {
  18.739 +		/* Next get the network information */
  18.740 +		network = xenstat_domain_network(domain,i);
  18.741 +
  18.742 +		print("Net%d RX: %8llubytes %8llupkts %8lluerr %8lludrop  ",
  18.743 +		      i,
  18.744 +		      xenstat_network_rbytes(network),
  18.745 +		      xenstat_network_rpackets(network),
  18.746 +		      xenstat_network_rerrs(network),
  18.747 +		      xenstat_network_rdrop(network));
  18.748 +
  18.749 +		print("TX: %8llubytes %8llupkts %8lluerr %8lludrop\n",
  18.750 +		      xenstat_network_tbytes(network),
  18.751 +		      xenstat_network_tpackets(network),
  18.752 +		      xenstat_network_terrs(network),
  18.753 +		      xenstat_network_tdrop(network));
  18.754 +	}
  18.755 +}
  18.756 +
  18.757 +static void top(void)
  18.758 +{
  18.759 +	xenstat_domain **domains;
  18.760 +	unsigned int i, num_domains = 0;
  18.761 +
  18.762 +	/* Now get the node information */
  18.763 +	if (prev_node != NULL)
  18.764 +		xenstat_free_node(prev_node);
  18.765 +	prev_node = cur_node;
  18.766 +	cur_node = xenstat_get_node(xhandle, XENSTAT_ALL);
  18.767 +	if (cur_node == NULL)
  18.768 +		fail("Failed to retrieve statistics from libxenstat\n");
  18.769 +
  18.770 +	/* dump summary top information */
  18.771 +	do_summary();
  18.772 +
  18.773 +	/* Count the number of domains for which to report data */
  18.774 +	num_domains = xenstat_node_num_domains(cur_node);
  18.775 +
  18.776 +	domains = malloc(num_domains*sizeof(xenstat_domain *));
  18.777 +	if(domains == NULL)
  18.778 +		fail("Failed to allocate memory\n");
  18.779 +
  18.780 +	for (i=0; i < num_domains; i++)
  18.781 +		domains[i] = xenstat_node_domain_by_index(cur_node, i);
  18.782 +
  18.783 +	/* Sort */
  18.784 +	qsort(domains, num_domains, sizeof(xenstat_domain *),
  18.785 +	      (int(*)(const void *, const void *))compare_domains);
  18.786 +
  18.787 +	if(first_domain_index >= num_domains)
  18.788 +		first_domain_index = num_domains-1;
  18.789 +
  18.790 +	for (i = first_domain_index; i < num_domains; i++) {
  18.791 +		if(current_row() == lines()-1)
  18.792 +			break;
  18.793 +		if (i == first_domain_index || repeat_header)
  18.794 +			do_header();
  18.795 +		do_domain(domains[i]);
  18.796 +		if (show_vcpus)
  18.797 +			do_vcpu(domains[i]);
  18.798 +		if (show_networks)
  18.799 +			do_network(domains[i]);
  18.800 +	}
  18.801 +
  18.802 +	do_bottom_line();
  18.803 +}
  18.804 +
  18.805 +int main(int argc, char **argv)
  18.806 +{
  18.807 +	int opt, optind = 0;
  18.808 +	int ch = ERR;
  18.809 +
  18.810 +	struct option lopts[] = {
  18.811 +		{ "help",          no_argument,       NULL, 'h' },
  18.812 +		{ "version",       no_argument,       NULL, 'V' },
  18.813 +		{ "networks",      no_argument,       NULL, 'n' },
  18.814 +		{ "repeat-header", no_argument,       NULL, 'r' },
  18.815 +		{ "vcpus",         no_argument,       NULL, 'v' },
  18.816 +		{ "delay",         required_argument, NULL, 'd' },
  18.817 +		{ 0, 0, 0, 0 },
  18.818 +	};
  18.819 +	const char *sopts = "hVbnvd:";
  18.820 +
  18.821 +	if (atexit(cleanup) != 0)
  18.822 +		fail("Failed to install cleanup handler.\n");
  18.823 +
  18.824 +	while ((opt = getopt_long(argc, argv, sopts, lopts, &optind)) != -1) {
  18.825 +		switch (opt) {
  18.826 +		case 'h':
  18.827 +		case '?':
  18.828 +		default:
  18.829 +			usage(argv[0]);
  18.830 +			exit(0);
  18.831 +		case 'V':
  18.832 +			version();
  18.833 +			exit(0);
  18.834 +		case 'n':
  18.835 +			show_networks = 1;
  18.836 +			break;
  18.837 +		case 'r':
  18.838 +			repeat_header = 1;
  18.839 +			break;
  18.840 +		case 'v':
  18.841 +			show_vcpus = 1;
  18.842 +			break;
  18.843 +		case 'd':
  18.844 +			delay = atoi(optarg);
  18.845 +			break;
  18.846 +		}
  18.847 +	}
  18.848 +
  18.849 +	/* Get xenstat handle */
  18.850 +	xhandle = xenstat_init();
  18.851 +	if (xhandle == NULL)
  18.852 +		fail("Failed to initialize xenstat library\n");
  18.853 +
  18.854 +	/* Begin curses stuff */
  18.855 +	initscr();
  18.856 +	start_color();
  18.857 +	cbreak();
  18.858 +	noecho();
  18.859 +	nonl();
  18.860 +	keypad(stdscr, TRUE);
  18.861 +	halfdelay(5);
  18.862 +	use_default_colors();
  18.863 +	init_pair(1, -1, COLOR_YELLOW);
  18.864 +
  18.865 +	do {
  18.866 +		gettimeofday(&curtime, NULL);
  18.867 +		if(ch != ERR || (curtime.tv_sec - oldtime.tv_sec) >= delay) {
  18.868 +			clear();
  18.869 +			top();
  18.870 +			oldtime = curtime;
  18.871 +			refresh();
  18.872 +		}
  18.873 +		ch = getch();
  18.874 +	} while (handle_key(ch));
  18.875 +
  18.876 +	/* Cleanup occurs in cleanup(), so no work to do here. */
  18.877 +
  18.878 +	return 0;
  18.879 +}