Skip to contentSkip to conversation

powertop: use external traceevent library

PATCH New Tzvetomir Stoyanov 1 participant 1 message Sep 28, 2018 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powertop: use external traceevent library

This patch switches powertop to use the external libtraceevent.so, instead of the internal implementation located in traceevent directory. The library libtraceevent.so must be installed on the system and properly hooked to pkg-config.

---
 Doxyfile.in                |  2 +-
 Makefile.am                |  1 -
 configure.ac               |  9 +++++-
 po/POTFILES.in             |  4 +--
 src/Makefile.am            | 12 +++----
 src/cpu/cpu.cpp            | 12 +++----
 src/perf/perf.cpp          | 12 +++----
 src/perf/perf.h            |  4 +--
 src/perf/perf_bundle.cpp   | 12 +++----
 src/process/do_process.cpp | 64 +++++++++++++++++++-------------------
 10 files changed, 68 insertions(+), 64 deletions(-)
Doxyfile.in +1 -1
index 1f1d8b4..6617357 100644
@@ -733,7 +733,7 @@ WARN_LOGFILE           =
 # spaces.
 # Note: If this tag is empty the current directory is searched.
 
-INPUT                  = src traceevent
+INPUT                  = src
 
 # This tag can be used to specify the character encoding of the source files
 # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Makefile.am +0 -1
index 3aabb22..15f2120 100644
@@ -2,7 +2,6 @@ AUTOMAKE_OPTIONS = subdir-objects
 ACLOCAL_AMFLAGS = --install -I m4
 
 SUBDIRS = \
-	traceevent \
 	src \
 	po \
 	doc
configure.ac +8 -1
index d6a15e1..e511f42 100644
@@ -14,7 +14,6 @@ AC_CONFIG_FILES([
 	Makefile
 	Doxyfile
 	src/Makefile
-	traceevent/Makefile
 	po/Makefile.in
 	doc/Makefile
 ])
@@ -137,6 +136,14 @@ AS_IF([test "$has_libnl_ver" -gt 1], [
 	AC_DEFINE([HAVE_LIBNL20], [1], [Define if you have libnl-2.0 or higher])
 ])
 
+has_libtraceevent_ver=0
+dnl check for tracevent library
+PKG_CHECK_MODULES([LIBTRACEEVENT], [libtraceevent], [has_libtraceevent_ver=1])
+
+AS_IF([test "$has_libtraceevent_ver" -eq 0], [
+	AC_MSG_ERROR([libtraceevent is required but were not found])
+])
+
 AS_IF([test "$has_libpci" -eq 0], [
 	AC_DEFINE([HAVE_NO_PCI], [1], [Define if pci is not supported])
         AC_MSG_WARN([
po/POTFILES.in +1 -3
index aa853f0..4a239ef 100644
@@ -36,6 +36,4 @@ src/tuning/tuning.cpp
 src/tuning/tuningi2c.cpp
 src/tuning/tuningsysfs.cpp
 src/tuning/tuningusb.cpp
-src/tuning/wifi.cpp
-traceevent/event-parse.h
-traceevent/parse-utils.c
+src/tuning/wifi.cpp
\ No newline at end of file
src/Makefile.am +6 -6
index 8357bae..defdfc3 100644
@@ -136,7 +136,8 @@ powertop_CXXFLAGS = \
 	$(LIBNL_CFLAGS) \
 	$(NCURSES_CFLAGS) \
 	$(PCIUTILS_CFLAGS) \
-	$(PTHREAD_CFLAGS)
+	$(PTHREAD_CFLAGS) \
+	$(LIBTRACEEVENT_CFLAGS)
 
 
 powertop_CPPFLAGS = \
@@ -146,10 +147,8 @@ powertop_CPPFLAGS = \
 	$(LIBZ_CFLAGS) \
 	$(NCURSES_CFLAGS) \
 	$(PCIUTILS_CFLAGS) \
-	$(PTHREAD_CFLAGS)
-
-powertop_LDADD = \
-	../traceevent/libtraceevnet.la
+	$(PTHREAD_CFLAGS) \
+	$(LIBTRACEEVENT_CFLAGS)
 
 AM_LDFLAGS = \
 	$(LIBNL_LIBS) \
@@ -158,7 +157,8 @@ AM_LDFLAGS = \
 	$(NCURSES_LIBS) \
 	$(PCIUTILS_LIBS) \
 	$(PTHREAD_LIBS) \
-	$(RESOLV_LIBS)
+	$(RESOLV_LIBS) \
+	$(LIBTRACEEVENT_LIBS)
 
 BUILT_SOURCES = css.h
 CLEANFILES = css.h
src/cpu/cpu.cpp +6 -6
index 28afc4f..f725b7f 100644
@@ -961,15 +961,15 @@ struct power_entry {
 
 void perf_power_bundle::handle_trace_point(void *trace, int cpunr, uint64_t time)
 {
-	struct event_format *event;
-        struct pevent_record rec; /* holder */
+	struct tep_event_format *event;
+        struct tep_record rec; /* holder */
 	class abstract_cpu *cpu;
 	int type;
 
 	rec.data = trace;
 
-	type = pevent_data_type(perf_event::pevent, &rec);
-	event = pevent_find_event(perf_event::pevent, type);
+	type = tep_data_type(perf_event::pevent, &rec);
+	event = tep_find_event(perf_event::pevent, type);
 
 	if (!event)
 		return;
@@ -992,7 +992,7 @@ void perf_power_bundle::handle_trace_point(void *trace, int cpunr, uint64_t time
 	int ret;
 	if (strcmp(event->name, "cpu_idle")==0) {
 
-		ret = pevent_get_field_val(NULL, event, "state", &rec, &val, 0);
+		ret = tep_get_field_val(NULL, event, "state", &rec, &val, 0);
                 if (ret < 0) {
                         fprintf(stderr, _("cpu_idle event returned no state?\n"));
                         exit(-1);
@@ -1007,7 +1007,7 @@ void perf_power_bundle::handle_trace_point(void *trace, int cpunr, uint64_t time
 	if (strcmp(event->name, "power_frequency") == 0
 	|| strcmp(event->name, "cpu_frequency") == 0){
 
-		ret = pevent_get_field_val(NULL, event, "state", &rec, &val, 0);
+		ret = tep_get_field_val(NULL, event, "state", &rec, &val, 0);
 		if (ret < 0) {
 			fprintf(stderr, _("power or cpu_frequency event returned no state?\n"));
 			exit(-1);
src/perf/perf.cpp +6 -6
index 9ed0ba8..8ea201d 100644
@@ -44,7 +44,7 @@
 #include "../lib.h"
 #include "../display.h"
 
-struct pevent *perf_event::pevent;
+struct tep_handle *perf_event::pevent;
 
 static int get_trace_type(const char *eventname)
 {
@@ -169,12 +169,12 @@ perf_event::~perf_event(void)
 {
 	free(name);
 
-	if (perf_event::pevent->ref_count == 1) {
-		pevent_free(perf_event::pevent);
+	if (tep_ref_get(perf_event::pevent) == 1) {
+		tep_free(perf_event::pevent);
 		perf_event::pevent = NULL;
 		clear();
 	} else
-		pevent_unref(perf_event::pevent);
+		tep_unref(perf_event::pevent);
 }
 
 void perf_event::set_cpu(int _cpu)
@@ -185,9 +185,9 @@ void perf_event::set_cpu(int _cpu)
 static void allocate_pevent(void)
 {
 	if (!perf_event::pevent)
-		perf_event::pevent = pevent_alloc();
+		perf_event::pevent = tep_alloc();
 	else
-		pevent_ref(perf_event::pevent);
+		tep_ref(perf_event::pevent);
 }
 
 perf_event::perf_event(const char *event_name, int _cpu, int buffer_size)
src/perf/perf.h +2 -2
index ee072ae..511e3e1 100644
@@ -29,7 +29,7 @@
 
 
 extern "C" {
-	#include "../traceevent/event-parse.h"
+	#include <event-parse.h>
 }
 
 
@@ -69,7 +69,7 @@ public:
 
 	virtual void handle_event(struct perf_event_header *header, void *cookie) { };
 
-	static struct pevent *pevent;
+	static struct tep_handle *pevent;
 
 };
 
src/perf/perf_bundle.cpp +6 -6
index 3d216ff..edd00a1 100644
@@ -148,7 +148,7 @@ static void parse_event_format(const char *event_name)
 		return;
 	}
 
-	pevent_parse_event(perf_event::pevent, buf, strlen(buf), sys);
+	tep_parse_event(perf_event::pevent, buf, strlen(buf), sys);
 	free(name);
 	free(buf);
 }
@@ -295,19 +295,19 @@ static bool event_sort_function (void *i, void *j)
  */
 static void fixup_sample_trace_cpu(struct perf_sample *sample)
 {
-	struct event_format *event;
-	struct pevent_record rec;
+	struct tep_event_format *event;
+	struct tep_record rec;
 	unsigned long long cpu_nr;
 	int type;
 	int ret;
 
 	rec.data = &sample->data;
-	type = pevent_data_type(perf_event::pevent, &rec);
-	event = pevent_find_event(perf_event::pevent, type);
+	type = tep_data_type(perf_event::pevent, &rec);
+	event = tep_find_event(perf_event::pevent, type);
 	if (!event)
 		return;
 	/** don't touch trace if event does not contain cpu_id field*/
-	ret = pevent_get_field_val(NULL, event, "cpu_id", &rec, &cpu_nr, 0);
+	ret = tep_get_field_val(NULL, event, "cpu_id", &rec, &cpu_nr, 0);
 	if (ret < 0)
 		return;
 	sample->trace.cpu = cpu_nr;
src/process/do_process.cpp +32 -32

203 lines not on this page · raw message

Signature · 1 line
2.17.1