From: "Steven Rostedt (Google)" <rostedt@xxxxxxxxxxx> The kbuffer_alloc() is awkward to use as the size and endianess needs to be passed in by enum values. Add a kbuffer_create() that only takes a tep handle, and it determines these values via the handle instead. Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx> --- include/traceevent/kbuffer.h | 1 + src/parse-utils.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/traceevent/kbuffer.h b/include/traceevent/kbuffer.h index a2b522093cfd..66b095833b81 100644 --- a/include/traceevent/kbuffer.h +++ b/include/traceevent/kbuffer.h @@ -29,6 +29,7 @@ enum { struct kbuffer; struct kbuffer *kbuffer_alloc(enum kbuffer_long_size size, enum kbuffer_endian endian); +struct kbuffer *kbuffer_create(struct tep_handle *tep); void kbuffer_free(struct kbuffer *kbuf); int kbuffer_load_subbuffer(struct kbuffer *kbuf, void *subbuffer); void *kbuffer_read_event(struct kbuffer *kbuf, unsigned long long *ts); diff --git a/src/parse-utils.c b/src/parse-utils.c index 09059edf0159..ffa6c5871289 100644 --- a/src/parse-utils.c +++ b/src/parse-utils.c @@ -11,6 +11,7 @@ #include "event-utils.h" #include "event-parse.h" +#include "kbuffer.h" #define __weak __attribute__((weak)) @@ -122,3 +123,28 @@ void __weak __vpr_stat(const char *fmt, va_list ap) } void vpr_stat(const char *fmt, va_list ap) __attribute__((weak, alias("__vpr_stat"))); + +/** + * kbuffer_create - create and allocate a new kbuffer + * @tep: the data to get the long size and endianess from + * + * Allocates and returns a new kbuffer. + */ +struct kbuffer *kbuffer_create(struct tep_handle *tep) +{ + enum kbuffer_endian endian; + int long_size; + + long_size = tep_get_long_size(tep); + if (long_size == 8) + long_size = KBUFFER_LSIZE_8; + else + long_size = KBUFFER_LSIZE_4; + + if (tep_is_file_bigendian(tep)) + endian = KBUFFER_ENDIAN_BIG; + else + endian = KBUFFER_ENDIAN_LITTLE; + + return kbuffer_alloc(long_size, endian); +} -- 2.35.1