X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lttv%2Fmodules%2Ftext%2FbatchAnalysis.c;h=0fbde4d2a9fd34df8188fef17c761647089ee586;hb=b9ce0bad7daf7c0a2333c91fdb1e35d602afe17f;hp=3ee4d021fc6539c4f804b086fd2bac7596a8f99e;hpb=2bd4b3e43e525da7b4c9738915ec847f7fe4906a;p=lttv.git diff --git a/lttv/modules/text/batchAnalysis.c b/lttv/modules/text/batchAnalysis.c index 3ee4d021..0fbde4d2 100644 --- a/lttv/modules/text/batchAnalysis.c +++ b/lttv/modules/text/batchAnalysis.c @@ -12,8 +12,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. */ /* This module inserts a hook in the program main loop. This hook processes @@ -24,17 +24,22 @@ #endif #include +#include #include #include #include #include #include -#include +#include #include +#ifdef BABEL_CLEANUP #include #include -#include -#include +#endif +#ifdef BABEL_CLEANUP_SYNC +#include +#endif +#include static LttvTraceset *traceset; @@ -48,37 +53,55 @@ static LttvHooks *event_hook, *main_hooks; -static char *a_trace; +static char *trace_path; static gboolean a_stats; +static gboolean a_live; +static int a_live_update_period; + +#define DEFAULT_LIVE_UPDATE_PERIOD 1 void lttv_trace_option(void *hook_data) { - LttTrace *trace; - - trace = ltt_trace_open(a_trace); + //LttTrace *trace; + //trace_collection *trace; + //format *fmt = bt_lookup_format(g_quark_from_static_string("ctf")); + /* + if(a_live) { + //trace = ltt_trace_open_live(a_trace); + } else { + bt_create_context(); + //trace = bt_add_trace(a_trace,"ctf"); + } if(trace == NULL) g_critical("cannot open trace %s", a_trace); - lttv_traceset_add(traceset, lttv_trace_new(trace)); + lttv_traceset_add(traceset, lttv_trace_new(trace));*/ + + if(lttv_traceset_add_path(traceset, trace_path) < 0) { + g_error("Cannot add trace %s", trace_path); + } } static gboolean process_traceset(void *hook_data, void *call_data) { +#ifdef BABEL_CLEANUP LttvAttributeValue value_expression, value_filter; LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes()); - LttvTracesetStats *tscs; + LttvTracesetStats *tscs = NULL; LttvTracesetState *tss; LttvTracesetContext *tc; - LttTime start, end; gboolean retval; +#endif + LttTime start, end; - g_info("BatchAnalysis begin process traceset"); + g_info("BatchAnalysis begin process traceset"); +#ifdef BABEL_CLEANUP if (a_stats) { tscs = g_object_new(LTTV_TRACESET_STATS_TYPE, NULL); tss = &tscs->parent; @@ -91,11 +114,13 @@ static gboolean process_traceset(void *hook_data, void *call_data) lttv_context_init(tc, traceset); + syncTraceset(tc); - lttv_state_add_event_hooks(tc); + lttv_state_add_event_hooks(tss); if(a_stats) lttv_stats_add_event_hooks(tscs); + retval= lttv_iattribute_find_by_path(attributes, "filter/expression", LTTV_POINTER, &value_expression); g_assert(retval); @@ -115,16 +140,16 @@ static gboolean process_traceset(void *hook_data, void *call_data) //g_debug("Filter string: %s",((GString*)*(value_expression.v_pointer))->str); lttv_filter_append_expression(*(value_filter.v_pointer),((GString*)*(value_expression.v_pointer))->str); - +#endif //lttv_traceset_context_add_hooks(tc, //before_traceset, after_traceset, NULL, before_trace, after_trace, //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); - lttv_process_traceset_begin(tc, + + lttv_state_add_event_hooks(traceset); + lttv_process_traceset_begin(traceset, before_traceset, before_trace, - before_tracefile, - event_hook, - NULL); + event_hook); start.tv_sec = 0; start.tv_nsec = 0; @@ -132,35 +157,52 @@ static gboolean process_traceset(void *hook_data, void *call_data) end.tv_nsec = G_MAXULONG; g_info("BatchAnalysis process traceset"); - - lttv_process_traceset_seek_time(tc, start); - lttv_process_traceset_middle(tc, - end, - G_MAXULONG, - NULL); + + lttv_process_traceset_seek_time(traceset, start); + /* Read as long a we do not reach the end (0) */ + unsigned int count; +#ifdef BABEL_CLEANUP + unsigned int updated_count; +#endif + do { + count = lttv_process_traceset_middle(traceset, + end, + G_MAXULONG, + NULL); + +#ifdef BABEL_CLEANUP + updated_count = lttv_process_traceset_update(tc); +#endif + + sleep(a_live_update_period); + } while(count != 0 +#ifdef BABEL_CLEANUP + || updated_count > 0 +#endif + ); //lttv_traceset_context_remove_hooks(tc, //before_traceset, after_traceset, NULL, before_trace, after_trace, //NULL, before_tracefile, after_tracefile, NULL, before_event, after_event); - lttv_process_traceset_end(tc, + lttv_process_traceset_end(traceset, after_traceset, after_trace, - after_tracefile, - event_hook, - NULL); + event_hook); g_info("BatchAnalysis destroy context"); - +#ifdef BABEL_CLEANUP lttv_filter_destroy(*(value_filter.v_pointer)); + lttv_state_remove_event_hooks(tss); if(a_stats) lttv_stats_remove_event_hooks(tscs); + lttv_context_fini(tc); if (a_stats) g_object_unref(tscs); else g_object_unref(tss); - +#endif g_info("BatchAnalysis end process traceset"); return FALSE; } @@ -178,7 +220,7 @@ static void init() lttv_option_add("trace", 't', "add a trace to the trace set to analyse", "pathname of the directory containing the trace", - LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL); + LTTV_OPT_STRING, &trace_path, lttv_trace_option, NULL); a_stats = FALSE; lttv_option_add("stats", 's', @@ -186,6 +228,20 @@ static void init() "", LTTV_OPT_NONE, &a_stats, NULL, NULL); + a_live = FALSE; + lttv_option_add("live", 0, + "define if the traceset is receiving live informations", + "", + LTTV_OPT_NONE, &a_live, NULL, NULL); + + a_live_update_period = DEFAULT_LIVE_UPDATE_PERIOD; + lttv_option_add("live-period", 0, + "period to update a live trace", + "in seconds", + LTTV_OPT_INT, + &a_live_update_period, + NULL, NULL); + traceset = lttv_traceset_new(); @@ -243,14 +299,18 @@ static void init() static void destroy() { +#ifdef BABEL_CLEANUP guint i, nb; LttvTrace *trace; +#endif g_info("Destroy batchAnalysis.c"); lttv_option_remove("trace"); lttv_option_remove("stats"); + lttv_option_remove("live"); + lttv_option_remove("live-period"); lttv_hooks_destroy(before_traceset); lttv_hooks_destroy(after_traceset); @@ -263,17 +323,18 @@ static void destroy() lttv_hooks_destroy(event_hook); lttv_hooks_remove_data(main_hooks, process_traceset, NULL); +#ifdef BABEL_CLEANUP nb = lttv_traceset_number(traceset); for(i = 0 ; i < nb ; i++) { trace = lttv_traceset_get(traceset, i); ltt_trace_close(lttv_trace(trace)); - /* This will be done by lttv_traceset_destroy */ - //lttv_trace_destroy(trace); + lttv_trace_destroy(trace); } - +#endif lttv_traceset_destroy(traceset); } LTTV_MODULE("batchAnalysis", "Batch processing of a trace", \ "Run through a trace calling all the registered hooks", \ - init, destroy, "state", "stats", "option","textFilter", "sync") + init, destroy, "state", "option") +//TODO ybrosseau 2012-05-15 reenable textFilter, stats, sync