From 2b605c6b940bbdf82a1e5c0c7152d629b9001711 Mon Sep 17 00:00:00 2001
From: Stefan Hajnoczi <stefanha@redhat.com>
Date: Tue, 21 Oct 2014 16:17:23 +0200
Subject: [PATCH 19/21] trace: add SystemTap init scripts for simpletrace
 bridge

Message-id: <1413908245-19510-7-git-send-email-stefanha@redhat.com>
Patchwork-id: 61770
O-Subject: [RHEL7.1 qemu-kvm-rhev PATCH 6/8] trace: add SystemTap init scripts for simpletrace bridge
Bugzilla: 1155015
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>

Add example files for use with the systemtap-initscript package.  These
example files set up the SystemTap flight recorder with our simpletrace
bridge script.  In other words, they set up always-on simpletrace.

The example file enables a small subset of trace events across all
qemu-kvm processes with 4MB per CPU trace buffers.  This example
configuration may be useful to customers who wish to run with always-on
tracing.

To enable it:

  # yum install systemtap-initscript
  # cp /usr/share/qemu-kvm/systemtap/conf.d/qemu_kvm.conf /etc/systemtap/conf.d/
  # cp /usr/share/qemu-kvm/systemtap/script.d/qemu_kvm.stp /etc/systemtap/script.d/
  # service systemtap start qemu_kvm

Note that due to systemtap-initscript naming restrictions the scripts
are called "qemu_kvm" instead of "qemu-kvm".

Once installed the script will be activated on boot.

Note that since gitignore(1) hides *.d we explicitly unhide
scripts/systemtap/{conf.d,script.d} in this patch.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
(cherry picked from commit 3a83a60ee0fd25580499695e4781fc473de147c5)
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>

Conflicts:

This was forward-ported from a RHEL6.6 commit so there are conflicts.

	.gitignore

  Prefix '/' as done in QEMU 2.1.2 commit
  5556332aba80c0579244c4458d3e35f13badd5ed ("gitignore: anchor all
  ignored names").  Downstream did not have this commit so there was a
  context conflict.

	Makefile

  Different Makefile variable name: s/datadir/qemu_datadir/

	redhat/qemu-kvm.spec.template

  The RHEL7.1 RHEV spec file is different from RHEL6.6.  Move things
  around.
---
 .gitignore                              | 2 ++
 Makefile                                | 4 ++++
 redhat/qemu-kvm.spec.template           | 4 +++-
 scripts/systemtap/conf.d/qemu_kvm.conf  | 4 ++++
 scripts/systemtap/script.d/qemu_kvm.stp | 1 +
 5 files changed, 14 insertions(+), 1 deletion(-)
 create mode 100644 scripts/systemtap/conf.d/qemu_kvm.conf
 create mode 100644 scripts/systemtap/script.d/qemu_kvm.stp

diff --git a/.gitignore b/.gitignore
index 750f592..710e207 100644
--- a/.gitignore
+++ b/.gitignore
@@ -76,6 +76,8 @@
 *.vr
 *.d
 !/scripts/qemu-guest-agent/fsfreeze-hook.d
+!/scripts/systemtap/script.d
+!/scripts/systemtap/conf.d
 *.o
 *.lo
 *.la
diff --git a/Makefile b/Makefile
index 523f069..e6af04f 100644
--- a/Makefile
+++ b/Makefile
@@ -419,6 +419,10 @@ endif
 		$(INSTALL_DATA) $(SRC_PATH)/pc-bios/keymaps/$$x "$(DESTDIR)$(qemu_datadir)/keymaps"; \
 	done
 	$(INSTALL_DATA) $(SRC_PATH)/trace-events "$(DESTDIR)$(qemu_datadir)/trace-events"
+	$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/systemtap/script.d"
+	$(INSTALL_DATA) $(SRC_PATH)/scripts/systemtap/script.d/qemu_kvm.stp "$(DESTDIR)$(qemu_datadir)/systemtap/script.d/"
+	$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/systemtap/conf.d"
+	$(INSTALL_DATA) $(SRC_PATH)/scripts/systemtap/conf.d/qemu_kvm.conf "$(DESTDIR)$(qemu_datadir)/systemtap/conf.d/"
 	for d in $(TARGET_DIRS); do \
 	$(MAKE) $(SUBDIR_MAKEFLAGS) TARGET_DIR=$$d/ -C $$d $@ || exit 1 ; \
         done
diff --git a/scripts/systemtap/conf.d/qemu_kvm.conf b/scripts/systemtap/conf.d/qemu_kvm.conf
new file mode 100644
index 0000000..372d816
--- /dev/null
+++ b/scripts/systemtap/conf.d/qemu_kvm.conf
@@ -0,0 +1,4 @@
+# Force load uprobes (see BZ#1118352)
+stap -e 'probe process("/usr/libexec/qemu-kvm").function("main") { printf("") }' -c true
+
+qemu_kvm_OPT="-s4" # per-CPU buffer size, in megabytes
diff --git a/scripts/systemtap/script.d/qemu_kvm.stp b/scripts/systemtap/script.d/qemu_kvm.stp
new file mode 100644
index 0000000..c04abf9
--- /dev/null
+++ b/scripts/systemtap/script.d/qemu_kvm.stp
@@ -0,0 +1 @@
+probe qemu.kvm.simpletrace.handle_qmp_command,qemu.kvm.simpletrace.monitor_protocol_*,qemu.kvm.simpletrace.migrate_set_state {}
-- 
1.8.3.1

