X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=libust%2Fserialize.c;h=b1859ed9a8095f63bda857a72dd14ac1d492a52c;hb=c93858f1db9c8fedb9cb3dc751c95ce77083c7ee;hp=bef01780e6bfbdb70179ce30577e00bf863836b4;hpb=b4512257eb71d0432554047acf6278dc42a15a75;p=ust.git diff --git a/libust/serialize.c b/libust/serialize.c index bef0178..b1859ed 100644 --- a/libust/serialize.c +++ b/libust/serialize.c @@ -3,7 +3,20 @@ * * Copyright Mathieu Desnoyers, March 2007. * - * Licensed under the GPLv2. + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * * * See this discussion about weirdness about passing va_list and then va_list to * functions. (related to array argument passing). va_list seems to be @@ -18,10 +31,16 @@ //ust// #include #include #include -#include "kernelcompat.h" +#include + +#include +#define _LGPL_SOURCE +#include +#include + #include "relay.h" #include "tracer.h" -#include "list.h" +//#include "list.h" #include "usterr.h" enum ltt_type { @@ -482,6 +501,92 @@ copydone: return buf_offset; } +static notrace void skip_space(const char **ps) +{ + while(**ps == ' ') + (*ps)++; +} + +static notrace void copy_token(char **out, const char **in) +{ + while(**in != ' ' && **in != '\0') { + **out = **in; + (*out)++; + (*in)++; + } +} + +/* serialize_to_text + * + * Given a format string and a va_list of arguments, convert them to a + * human-readable string. + * + * @outbuf: the buffer to output the string to + * @bufsize: the max size that can be used in outbuf + * @fmt: the marker format string + * @ap: a va_list that contains the arguments corresponding to fmt + * + * Return value: the number of chars that have been put in outbuf, excluding + * the final \0, or, if the buffer was too small, the number of chars that + * would have been written in outbuf if it had been large enough. + * + * outbuf may be NULL. The return value may then be used be allocate an + * appropriate outbuf. + * + */ + +notrace +int serialize_to_text(char *outbuf, int bufsize, const char *fmt, va_list ap) +{ + int fmt_len = strlen(fmt); + char *new_fmt = alloca(fmt_len + 1); + const char *orig_fmt_p = fmt; + char *new_fmt_p = new_fmt; + char false_buf; + int result; + enum { none, cfmt, tracefmt, argname } prev_token = none; + + while(*orig_fmt_p != '\0') { + if(*orig_fmt_p == '%') { + prev_token = cfmt; + copy_token(&new_fmt_p, &orig_fmt_p); + } + else if(*orig_fmt_p == '#') { + prev_token = tracefmt; + do { + orig_fmt_p++; + } while(*orig_fmt_p != ' ' && *orig_fmt_p != '\0'); + } + else if(*orig_fmt_p == ' ') { + if(prev_token == argname) { + *new_fmt_p = '='; + new_fmt_p++; + } + else if(prev_token == cfmt) { + *new_fmt_p = ' '; + new_fmt_p++; + } + + skip_space(&orig_fmt_p); + } + else { + prev_token = argname; + copy_token(&new_fmt_p, &orig_fmt_p); + } + } + + *new_fmt_p = '\0'; + + if(outbuf == NULL) { + /* use this false_buffer for compatibility with pre-C99 */ + outbuf = &false_buf; + bufsize = 1; + } + result = vsnprintf(outbuf, bufsize, new_fmt, ap); + + return result; +} + notrace size_t ltt_serialize_data(struct rchan_buf *buf, size_t buf_offset, struct ltt_serialize_closure *closure, void *serialize_private, int *largest_align, @@ -536,7 +641,6 @@ notrace size_t ltt_serialize_data(struct rchan_buf *buf, size_t buf_offset, } return buf_offset; } -EXPORT_SYMBOL_GPL(ltt_serialize_data); /* * Calculate data size @@ -566,7 +670,8 @@ void ltt_write_event_data(struct rchan_buf *buf, size_t buf_offset, notrace void ltt_vtrace(const struct marker *mdata, void *probe_data, - void *call_data, const char *fmt, va_list *args) + struct registers *regs, void *call_data, + const char *fmt, va_list *args) { int largest_align, ret; struct ltt_active_marker *pdata; @@ -583,7 +688,7 @@ notrace void ltt_vtrace(const struct marker *mdata, void *probe_data, struct ltt_serialize_closure closure; struct ltt_probe_private_data *private_data = call_data; void *serialize_private = NULL; - int cpu; +//ust// int cpu; unsigned int rflags; /* @@ -593,8 +698,8 @@ notrace void ltt_vtrace(const struct marker *mdata, void *probe_data, if (unlikely(ltt_traces.num_active_traces == 0)) return; - rcu_read_lock_sched_notrace(); - cpu = smp_processor_id(); + rcu_read_lock(); //ust// rcu_read_lock_sched_notrace(); +//ust// cpu = smp_processor_id(); //ust// __get_cpu_var(ltt_nesting)++; ltt_nesting++; @@ -671,25 +776,24 @@ notrace void ltt_vtrace(const struct marker *mdata, void *probe_data, va_end(args_copy); /* Out-of-order commit */ ltt_commit_slot(channel, &transport_data, buf_offset, - slot_size); - printf("just commited event at offset %d and size %d\n", buf_offset, slot_size); + data_size, slot_size); + DBG("just commited event at offset %ld and size %zd", buf_offset, slot_size); } //ust// __get_cpu_var(ltt_nesting)--; ltt_nesting--; - rcu_read_unlock_sched_notrace(); + rcu_read_unlock(); //ust// rcu_read_unlock_sched_notrace(); } -EXPORT_SYMBOL_GPL(ltt_vtrace); notrace void ltt_trace(const struct marker *mdata, void *probe_data, - void *call_data, const char *fmt, ...) + struct registers *regs, void *call_data, + const char *fmt, ...) { va_list args; va_start(args, fmt); - ltt_vtrace(mdata, probe_data, call_data, fmt, &args); + ltt_vtrace(mdata, probe_data, regs, call_data, fmt, &args); va_end(args); } -EXPORT_SYMBOL_GPL(ltt_trace); //ust// MODULE_LICENSE("GPL"); //ust// MODULE_AUTHOR("Mathieu Desnoyers");