From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpEhR-0008P8-EE for qemu-devel@nongnu.org; Wed, 28 Sep 2016 09:15:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpEhM-0001bH-Ug for qemu-devel@nongnu.org; Wed, 28 Sep 2016 09:15:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58746) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpEhM-0001ay-Lh for qemu-devel@nongnu.org; Wed, 28 Sep 2016 09:14:56 -0400 Date: Wed, 28 Sep 2016 14:14:52 +0100 From: "Daniel P. Berrange" Message-ID: <20160928131452.GC15510@redhat.com> Reply-To: "Daniel P. Berrange" References: <147506793053.18187.11460694747365824870.stgit@fimbulvetr.bsc.es> <147506793596.18187.14194318363118441846.stgit@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <147506793596.18187.14194318363118441846.stgit@fimbulvetr.bsc.es> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 1/6] hypertrace: Add documentation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?B?TGx1w61z?= Vilanova Cc: qemu-devel@nongnu.org, Luiz Capitulino , Eric Blake , Stefan Hajnoczi On Wed, Sep 28, 2016 at 03:05:36PM +0200, Llu=C3=ADs Vilanova wrote: > Signed-off-by: Llu=C3=ADs Vilanova > --- > docs/hypertrace.txt | 232 +++++++++++++++++++++++++++++++++++++++++++= ++++++++ > docs/tracing.txt | 3 + > 2 files changed, 235 insertions(+) > create mode 100644 docs/hypertrace.txt > +=3D=3D Quick guide =3D=3D > + > +This shows an example of using the hypertrace channel to trace the gue= st memory > +accesses only in a specific guest code region, which is identified by = calls to > +the hypertrace channel. > + > +We are going to trace memory accesses to disk using QEMU's "log" backe= nd, and > +will use QEMU's "dtrace" (SystemTap) backend to ensure memory accesses= are only > +traced in the guest code region of interest. The first time the guest = code > +invokes the hypertrace channel, we will start tracing the > +"guest_mem_before_exec" event using dtrace, and then will disable it t= he second > +time around. > + > +Tracing is done with "log" because it is more efficient than using "dt= race" in > +high-volume events like memory accesses. If the event rate is low, you= can > +ignore the "log" backend and simply use "dtrace"'s printf, while still= using the > +hypertrace events to identify guest semantics. > + > +1. Set the tracing backends and number of arguments for the hypertrace= events: > + > + mkdir /tmp/qemu-build > + cd /tmp/qemu-build > + /path/to/qemu-source/configure \ > + --enable-trace-backends=3Ddtrace,log \ > + --with-hypertrace-args=3D4 \ > + --prefix=3D/tmp/qemu-install > + make -j install > + > +2. Enable the event "guest_mem_before_exec": > + > + sed -i -e 's/disable vcpu tcg guest_mem_before/vcpu tcg guest_mem_= before/g' /path/to/qemu-source/trace-events > + > +3. Compile the guest support code: > + > + make -C /tmp/qemu-build/x86_64-linux-user/hypertrace/guest/user > + make -C /tmp/qemu-build/x86_64-softmmu/hypertrace/guest/user > + make -C /tmp/qemu-build/x86_64-softmmu/hypertrace/guest/linux-modu= le > + > + If you need to cross-compile the guest library, set the 'CC' variab= le: > + > + make -C /tmp/qemu-build/mipsel-linux-user/hypertrace/guest/user CC= =3Dmipsel-gnu-linux-gcc > + > +3. Create a guest application using "qemu-hypertrace.h" to interact wi= th the > + hypertrace channel: > + > + cat > /tmp/my-hypertrace.c <<\EOF > + #include > + #include > + #include > + #include > + #include > + =20 > + =20 > + int main(int argc, char **argv) > + { > + char *base =3D NULL; > + if (argc > 1) { > + base =3D argv[1]; > + } > + =20 > + /* In 'user' mode this path must be the same we will use to st= art QEMU. */ > + if (qemu_hypertrace_init(base) !=3D 0) { > + perror("error: qemu_hypertrace_init"); > + abort(); > + } > + =20 > + /* Set additional event arguments */ > + uint64_t client =3D 0; IIUC, 'client' is the field that the host uses to distinguish between different guest applications or different guest threads. How are applications expected to assign themselves a unique value for this field ?=20 It feels that life would be easier if you made this field be 128-bits instead of 64-bit, as then you could encode a UUID in it, making it much easier to guarnatee uniqueness without having to have a central authority. > + uint64_t *data =3D qemu_hypertrace_data(client); > + data[0] =3D 0xcafe; > + data[1] =3D 0xdead; > + data[2] =3D 0xbeef; > + =20 > + /* Emit event to start tracing */ > + qemu_hypertrace(client, 1); > + > + /* Computation in between */ > + printf("Some computation...\n"); > + > + /* Emit event to stop tracing */ > + qemu_hypertrace(client, 0); > + } > + EOF > + > + gcc -o /tmp/my-hypertrace-user /tmp/my-hypertrace.c = \ > + /tmp/qemu-build/x86_64-linux-user/hypertrace/guest/user/libqem= u-hypertrace-guest.a \ > + -I/tmp/qemu-install/include -lpthread > + > + gcc -o /tmp/my-hypertrace-softmmu /tmp/my-hypertrace.c = \ > + /tmp/qemu-build/x86_64-softmmu/hypertrace/guest/user/libqemu-h= ypertrace-guest.a \ > + -I/tmp/qemu-install/include -lpthread Regards, Daniel --=20 |: http://berrange.com -o- http://www.flickr.com/photos/dberrange= / :| |: http://libvirt.org -o- http://virt-manager.or= g :| |: http://entangle-photo.org -o- http://search.cpan.org/~danberr= / :|