Commit Graph

8 Commits

Author SHA1 Message Date
Cole Robinson
da176bf6b7 examples: Use one top level makefile
Using one Makefile per example subdirectory essentially serializes 'make'
calls. Convert to one example/Makefile that builds and distributes
all the subdir files. This reduces example/ rebuild time from about 5.8
seconds to 1.5 seconds on my machine.

One slight difference is that we no longer ship Makefile.am with the
examples in the rpm. This was virtually useless anyways since the Makefile
was very specific to libvirt infrastructure, so wasn't generically
reusable anyways.

Tested with 'make distcheck' and 'make rpm'
2016-01-09 21:14:12 -05:00
Michal Privoznik
498d7b2bf5 domtop: Properly free cpu status
So, in the example the cpu stats are collected within a function
called do_top. At the beginning of the function we ask the daemon for
how much vCPUs can we get stats, and how many stats for a vCPU can we
get. This is because it's how our API works - users are required to
preallocate a chunk of memory for the results. Now, at the end, we try
to free the allocated array, but we are not doing it correctly.
There's this virTypedParamsFree() function which gets a pointer to the
array and the length of the array. However, if there was an error in
getting vCPU stats we pass a negative number instead of the originally
computed value. This flaw results in SIGSEGV:

libvirt: QEMU Driver error : Requested operation is not valid: domain is not running
ERROR do_top:333 : Unable to get cpu stats
==29201== Invalid read of size 4
==29201==    at 0x4F1DF8B: virTypedParamsClear (virtypedparam.c:1145)
==29201==    by 0x4F1DFEB: virTypedParamsFree (virtypedparam.c:1165)
==29201==    by 0x4023C3: do_top (domtop.c:349)
==29201==    by 0x40260B: main (domtop.c:386)
==29201==  Address 0x131cd7c0 is 16 bytes after a block of size 768 alloc'd
==29201==    at 0x4C2C070: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==29201==    by 0x401FF1: do_top (domtop.c:295)
==29201==    by 0x40260B: main (domtop.c:386)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-04-21 10:56:50 +02:00
Michal Privoznik
dc64be90b5 domtop: Remove unused variable
The variable 'k' in the print_cpu_usage function is not used anywhere
and can fire a warning on some compilers.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-08-04 14:40:52 +02:00
Michal Privoznik
859aa405e1 domtop: Turn parse_argv into void
Currently, the function follows the usual pattern used in our code:

  int ret = -1;
  ...
  ret = 0;
 cleanup:
  return ret;

However, the function always call exit() on error, so the cleanup
label is never jumped onto. Therefore, it doesn't make any sense to
have the parse_argv function return an integer value, if it
effectively can return only value of zero.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-08-04 14:37:14 +02:00
Michal Privoznik
d82170d757 domtop: Fix build on mingw
Firstly, there's no sigaction() nor struct sigaction on mingw. We have
to use the one implemented by gnulib (and hence link with gnulib).
Then, for some reason one header file from windows defines ERROR
symbol. Yes it does. Sigh.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-07-22 09:53:18 +02:00
Peter Krempa
ba2b4da02d examples: domtop: Avoid leaking memory
Use the virTypedParamsFree unconditionally as it handles NULL well and
has the benefit of freeing a typed parameter array even if it wasn't yet
assigned, but only allocated.
2014-07-21 15:20:59 +02:00
Peter Krempa
abab113bd2 examples: domtop: Fix uninitialized variable use
max_id could be used uninitialized in the cleanup section after the
domain wasn't found.

Discovered by Coverity.
2014-07-21 15:20:59 +02:00
Michal Privoznik
28d54aab05 examples: Introduce domtop
There's this question on the list that is asked over and over again.
How do I get {cpu, memory, ...} usage in percentage? Or its modified
version: How do I plot nice graphs like virt-manager does?

It would be nice if we have an example to inspire people. And that's
what domtop should do. Yes, it could be written in different ways, but
I've chosen this one as I think it show explicitly what users need to
implement in order to imitate virt-manager's graphing.

Note: The usage is displayed from host perspective. That is, how much
host CPUs the domain is using. But it should be fairly simple to
switch do just guest CPU usage if needed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-07-18 16:39:54 +02:00