Skip to content

Commit

Permalink
Move from json to protobuf (#41)
Browse files Browse the repository at this point in the history
* Move from json to protobuf

* Add tooling for protobuf trace generation.

* fix build system.

* Device as process

* Fix ze and header

* Implement bug workarround

* Fix version

Co-authored-by: Brice Videau <[email protected]>
  • Loading branch information
TApplencourt and Kerilk authored Jul 13, 2022
1 parent 2908501 commit 8096497
Show file tree
Hide file tree
Showing 8 changed files with 444 additions and 229 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
path: ~/babeltrace2/2.0.4
key: ${{ runner.os }}-build-${{ env.cache-name }}
- run: sudo apt update; sudo apt install -y gcc g++ lttng-tools liblttng-ust-dev ruby ruby-dev elfutils libelf-dev libdw-dev
- run: sudo apt update; sudo apt install -y gcc g++ lttng-tools liblttng-ust-dev ruby ruby-dev elfutils libelf-dev libdw-dev libprotobuf-dev protobuf-compiler
if: steps.babeltrace2.outputs.cache-hit != 'true'
- run: gem install --user-install cast-to-yaml nokogiri babeltrace2 opencl_ruby_ffi
if: steps.babeltrace2.outputs.cache-hit != 'true'
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
with:
path: ~/babeltrace2/2.0.4
key: ${{ runner.os }}-build-${{ env.cache-name }}
- run: sudo apt update; sudo apt install -y gcc g++ lttng-tools liblttng-ust-dev ruby ruby-dev elfutils libelf-dev libdw-dev
- run: sudo apt update; sudo apt install -y gcc g++ lttng-tools liblttng-ust-dev ruby ruby-dev elfutils libelf-dev libdw-dev libprotobuf-dev protobuf-compiler
- run: gem install --user-install cast-to-yaml nokogiri babeltrace2 opencl_ruby_ffi
- name: Load Babeltrace2
run: |
Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
with:
path: ~/babeltrace2/2.0.4
key: ${{ runner.os }}-build-${{ env.cache-name }}
- run: sudo apt update; sudo apt install -y gcc g++ lttng-tools liblttng-ust-dev ruby ruby-dev elfutils libelf-dev libdw-dev
- run: sudo apt update; sudo apt install -y gcc g++ lttng-tools liblttng-ust-dev ruby ruby-dev elfutils libelf-dev libdw-dev libprotobuf-dev protobuf-compiler
- run: gem install --user-install cast-to-yaml nokogiri babeltrace2 opencl_ruby_ffi
- name: Load Babeltrace2
run: |
Expand Down Expand Up @@ -129,7 +129,7 @@ jobs:
with:
path: ~/babeltrace2/2.0.4
key: ${{ runner.os }}-build-${{ env.cache-name }}
- run: sudo apt update; sudo apt install -y gcc g++ lttng-tools liblttng-ust-dev ruby ruby-dev elfutils libelf-dev libdw-dev
- run: sudo apt update; sudo apt install -y gcc g++ lttng-tools liblttng-ust-dev ruby ruby-dev elfutils libelf-dev libdw-dev libprotobuf-dev protobuf-compiler
- run: gem install --user-install cast-to-yaml nokogiri babeltrace2 opencl_ruby_ffi
- name: Load Babeltrace2
run: |
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
with:
path: ~/babeltrace2/2.0.4
key: ${{ runner.os }}-build-${{ env.cache-name }}
- run: sudo apt update; sudo apt install -y gcc g++ lttng-tools liblttng-ust-dev ruby ruby-dev elfutils libelf-dev libdw-dev
- run: sudo apt update; sudo apt install -y gcc g++ lttng-tools liblttng-ust-dev ruby ruby-dev elfutils libelf-dev libdw-dev libprotobuf-dev protobuf-compiler
- run: gem install --user-install cast-to-yaml nokogiri babeltrace2 opencl_ruby_ffi
- name: Load Babeltrace2
run: |
Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ if test -z "$PATCH"; then
AC_CHECK_PROG(PATCH,[patch],[patch],[no])
test "$PATCH" == "no" && AC_MSG_ERROR([Required program 'patch' not found.])
fi
if test -z "$PROTOC"; then
AC_CHECK_PROG(PROTOC,[protoc],[protoc],[no])
test "$PROTOC" == "no" && AC_MSG_ERROR([Required program 'protoc' not found.])
fi

# Checks for libraries.
AC_CHECK_LIB([dl], [dlopen])
Expand All @@ -56,6 +60,7 @@ AM_CONDITIONAL([STRICT], [test "x$enable_strict" = xyes])
PKG_CHECK_MODULES([LIBFFI], [libffi >= 3.2])
PKG_CHECK_MODULES([BABELTRACE2], [babeltrace2 >= 2.0])
PKG_CHECK_MODULES([LTTNG_UST], [lttng-ust >= 2.10])
PKG_CHECK_MODULES([PROTOBUF], [protobuf >= 3.0])

AX_RUBY_EXTENSION([cast-to-yaml], [yes])
AX_RUBY_EXTENSION([nokogiri], [yes])
Expand Down
13 changes: 13 additions & 0 deletions utils/xprof_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ namespace std{
}

};

template <typename ... TT>
struct hash<std::pair<TT...>>
{
size_t
operator()(std::pair<TT...> const& tt) const
{
size_t seed = 0;
HashValueImpl<std::pair<TT...> >::apply(seed, tt);
return seed;
}

};
}

const char* borrow_hostname(const bt_event*);
Expand Down
27 changes: 20 additions & 7 deletions xprof/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,22 @@ nodist_noinst_HEADERS = xprof.sh.erb
xprof_utils.hpp: $(top_srcdir)/utils/xprof_utils.hpp
cp $< $@

%.pb.h %.pb.cc: %.proto
$(PROTOC) -I=$(srcdir) --cpp_out=$(builddir) $<

BUILT_SOURCES = \
xprof_utils.hpp
xprof_utils.hpp \
perfetto_prunned.pb.h \
perfetto_prunned.pb.cc

# Library to be packaged
lib_LTLIBRARIES = libXProf.la

# File to compiled
nodist_libXProf_la_SOURCES = \
xprof_utils.hpp
xprof_utils.hpp \
perfetto_prunned.pb.h \
perfetto_prunned.pb.cc

# File to compiled
libXProf_la_SOURCES = \
Expand All @@ -40,13 +47,16 @@ libXProf_la_SOURCES = \
my_demangle.c \
my_demangle.h \
$(top_srcdir)/utils/include/json.hpp

# Right now we harcode it. We should use pkgtools at some point https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp

# -I/home/tapplencourt/tmp/proto/protobuf-3.20.1/ici/include/ -L/home/tapplencourt/tmp/proto/protobuf-3.20.1/ici/lib/ -lprotobuf

# Compiler flags
libXProf_la_CPPFLAGS = -I$(top_srcdir)/utils/include -I$(srcdir)/include -I./
libXProf_la_CPPFLAGS = -I$(top_srcdir)/utils/include -I$(srcdir)/include -I./ -I/home/tapplencourt/tmp/proto/protobuf-3.20.1/ici/include/
libXProf_la_CFLAGS = -Wall -Wextra -Wno-unused-parameter $(WERROR) $(BABELTRACE2_CFLAGS)
libXProf_la_CXXFLAGS = -std=c++17 -Wall -Wextra -Wno-unused-parameter $(WERROR) $(BABELTRACE2_CFLAGS)
libXProf_la_LDFLAGS = $(BABELTRACE2_LIBS) -avoid-version -module
libXProf_la_CXXFLAGS = -std=c++17 -Wall -Wextra -Wno-unused-parameter $(WERROR) $(BABELTRACE2_CFLAGS) $(PROTOBUF_CFLAGS)
libXProf_la_LDFLAGS = $(BABELTRACE2_LIBS) $(PROTOBUF_LIBS) -avoid-version -module

# Cannot use check_LTLIBRARIES because we need the shared version of those
# Thanks Vincent Danjean
Expand Down Expand Up @@ -83,9 +93,12 @@ EXTRA_DIST = \
interval.h.erb \
interval_model.yaml \
$(TRACE_FILES) \
tests/tally.dust.erb
tests/tally.dust.erb \
perfetto_prunned.proto

CLEANFILES = \
iprof \
xprof_utils.hpp \
$(TALLY_DUST_FILES)
$(TALLY_DUST_FILES) \
perfetto_prunned.pb.h \
perfetto_prunned.pb.cc
75 changes: 75 additions & 0 deletions xprof/perfetto_prunned.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
syntax = "proto2";
// "There Is a Light That Never Goes Out"
// https://android.googlesource.com/platform/external/perfetto/+/refs/heads/master/protos/perfetto/trace/
package perfetto_pruned;

enum BuiltinClock {
BUILTIN_CLOCK_UNKNOWN = 0;
BUILTIN_CLOCK_REALTIME = 1;
BUILTIN_CLOCK_REALTIME_COARSE = 2;
BUILTIN_CLOCK_MONOTONIC = 3;
BUILTIN_CLOCK_MONOTONIC_COARSE = 4;
BUILTIN_CLOCK_MONOTONIC_RAW = 5;
BUILTIN_CLOCK_BOOTTIME = 6;
BUILTIN_CLOCK_MAX_ID = 63;
reserved 7, 8, 9;
}

message ProcessDescriptor {
optional int32 pid = 1;
optional string process_name = 6;
}

message TracePacketDefaults {
optional uint32 timestamp_clock_id = 58;
}

message ThreadDescriptor {
optional int32 pid = 1;
optional int32 tid = 2;
}

message TrackDescriptor {
optional uint64 uuid = 1;
optional uint64 parent_uuid = 5;
optional string name = 2;
optional ProcessDescriptor process = 3;
optional ThreadDescriptor thread = 4;
}

message TrackEvent {

enum Type {
TYPE_SLICE_BEGIN = 1;
TYPE_SLICE_END = 2;
}

optional Type type = 9;
optional uint64 track_uuid = 11;

oneof name_field {
string name = 23;
}

}

message TracePacket {
optional uint64 timestamp = 8;

oneof data {
TrackEvent track_event = 11;
TrackDescriptor track_descriptor = 60;
}

oneof optional_trusted_packet_sequence_id {
uint32 trusted_packet_sequence_id = 10;
}

required TracePacketDefaults trace_packet_defaults = 59;
optional bool previous_packet_dropped = 42;
}

message Trace {
repeated TracePacket packet = 1;
}

Loading

0 comments on commit 8096497

Please sign in to comment.