X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=custom_chart%2Fda_chart.c;h=801e0fc6f9dcccd7d9310f382a77b57aa6254434;hb=2c4cec1c55350b55a967601b68507e73a097df8e;hp=bbff71671e0dc8338dcb066972a4e8bf33e2809d;hpb=7a51a35b815806db0272c4176286cd8185d32eae;p=platform%2Fcore%2Fsystem%2Fswap-probe.git diff --git a/custom_chart/da_chart.c b/custom_chart/da_chart.c index bbff716..801e0fc 100755 --- a/custom_chart/da_chart.c +++ b/custom_chart/da_chart.c @@ -1,19 +1,20 @@ /* * DA probe * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * - * Contact: + * Contact: * * Jaewon Lim * Woojin Jung * Juyoung Kim - * + * Anastasia Lyupa + * * 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 @@ -25,7 +26,8 @@ * * Contributors: * - S-Core Co., Ltd - * + * - Samsung RnD Institute Russia + * */ #include @@ -132,8 +134,10 @@ void* _chart_timerThread(void* data) setProbePoint(&probeInfo); PREPARE_LOCAL_BUF(); - PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM, LC_CUSTOM, "", 0); - PACK_COMMON_END(0, 0, 2); + PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM, + API_ID__chart_timerThread, + "", 0); + PACK_COMMON_END('p', 0, 0, 2); PACK_CUSTOM(cur->series_handle, 0, "", 0, value); FLUSH_LOCAL_BUF(); @@ -192,17 +196,21 @@ static int start_callback_thread(chart_interval interval) return ERR_WRONG_PARAMETER; } - if(*timerfd != -1 || *thread_handle != -1) + /** + * FIXME: Type of pthread_t is undefined. + * Comparing it with -1 is *very* bad + */ + if (*timerfd != -1 || *thread_handle != (pthread_t) -1) return 0; // already thread exist *timerfd = timerfd_create(CLOCK_REALTIME, 0); - if(*timerfd == -1) + if (*timerfd == -1) return errno; - if(timerfd_settime(*timerfd, 0, &timevalue, NULL) == -1) + if (timerfd_settime(*timerfd, 0, &timevalue, NULL) == -1) return errno; - if(pthread_create(thread_handle, NULL, _chart_timerThread, pman) < 0) + if (pthread_create(thread_handle, NULL, _chart_timerThread, pman) < 0) return ERR_THREAD_CREATE_FAIL; return 0; @@ -217,7 +225,7 @@ static void add_to_callback_list(chart_interval interval, da_handle charthandle, da_user_data_2_chart_data callback, void* user_data) { chart_interval_callback* newelem; - + newelem = (chart_interval_callback*)malloc(sizeof(chart_interval_callback)); newelem->chart_handle = charthandle; newelem->series_handle = series_handle; @@ -225,7 +233,7 @@ static void add_to_callback_list(chart_interval interval, da_handle charthandle, newelem->user_data = user_data; chm.interval_for_series[charthandle][series_handle % 10] = interval; - + switch(interval) { case CHART_INTERVAL_10MSEC: @@ -258,7 +266,7 @@ static void add_to_callback_list(chart_interval interval, da_handle charthandle, static void remove_all_callback_list() { chart_interval_callback* cur; - + pthread_mutex_lock(&chm.interval_10ms.list_mutex); while(chm.interval_10ms.callback_list != NULL) { @@ -385,9 +393,6 @@ static void remove_from_callback_list(da_handle charthandle, da_handle series_ha // constructor and destructor functions // ===================================================================== -void memory_initialize_hook(void); -void (*__malloc_initialize_hook) (void) = memory_initialize_hook; - void __attribute__((constructor)) _init_lib() { probeBlockStart(); @@ -411,25 +416,19 @@ void __attribute__((destructor)) _fini_lib() probeBlockStart(); remove_all_callback_list(); - if(chm.interval_10ms.timerfd != -1) + if (chm.interval_10ms.timerfd != -1) close(chm.interval_10ms.timerfd); - if(chm.interval_100ms.timerfd != -1) + if (chm.interval_100ms.timerfd != -1) close(chm.interval_100ms.timerfd); - if(chm.interval_1s.timerfd != -1) + if (chm.interval_1s.timerfd != -1) close(chm.interval_1s.timerfd); - - if(chm.interval_10ms.thread_handle != -1) - { + /*! Bad. Ugly. Unportable */ + if (chm.interval_10ms.thread_handle != (pthread_t) -1) pthread_join(chm.interval_10ms.thread_handle, NULL); - } - if(chm.interval_100ms.thread_handle != -1) - { + if (chm.interval_100ms.thread_handle != (pthread_t) -1) pthread_join(chm.interval_100ms.thread_handle, NULL); - } - if(chm.interval_1s.thread_handle != -1) - { + if (chm.interval_1s.thread_handle != (pthread_t) -1) pthread_join(chm.interval_1s.thread_handle, NULL); - } probeBlockEnd(); } @@ -442,14 +441,16 @@ void __attribute__((destructor)) _fini_lib() void da_mark(chart_color color, char* mark_text) { DECLARE_CHART_VARIABLE; - + probeBlockStart(); - + setProbePoint(&probeInfo); PREPARE_LOCAL_BUF(); - PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM, LC_CUSTOM, "dp", color, mark_text); - PACK_COMMON_END(0, 0, 2); + PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM, + API_ID_da_mark, + "dp", color, voidp_to_uint64(mark_text)); + PACK_COMMON_END('v', 0, 0, 2); PACK_CUSTOM(0, 0, mark_text, color, 0.0f); FLUSH_LOCAL_BUF(); @@ -463,24 +464,26 @@ da_handle da_create_chart(char* chart_name) // check if there is available chart handle slot if(chm.chart_handle_index + 1 >= MAX_CHART_HANDLE) return ERR_MAX_CHART_NUMBER; - + // check if chart_name is null if(chart_name == NULL) return ERR_WRONG_PARAMETER; - + probeBlockStart(); ret = ++(chm.chart_handle_index); setProbePoint(&probeInfo); PREPARE_LOCAL_BUF(); - PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM, LC_CUSTOM, "p", chart_name); - PACK_COMMON_END(ret, 0, 2); + PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM, + API_ID_da_create_chart, + "p", voidp_to_uint64(chart_name)); + PACK_COMMON_END('d', ret, 0, 2); PACK_CUSTOM(0, 0, chart_name, 0, 0.0f); FLUSH_LOCAL_BUF(); - + probeBlockEnd(); - + return ret; } @@ -488,11 +491,11 @@ da_handle da_create_series(da_handle charthandle, char* seriesname, series_type type, chart_color color) { DECLARE_CHART_VARIABLE; - + // check if charthandle is valid handle or not if(charthandle <= 0 || charthandle > chm.chart_handle_index) return ERR_WRONG_HANDLE; - + // chech if extra parameter is valid if(seriesname == NULL) return ERR_WRONG_PARAMETER; @@ -500,24 +503,27 @@ da_handle da_create_series(da_handle charthandle, char* seriesname, // check if there is available series spot if(chm.series_handle_index[(int)charthandle] + 1 >= MAX_SERIES_PER_CHART) return ERR_MAX_CHART_NUMBER; - + probeBlockStart(); ret = ++(chm.series_handle_index[charthandle]); ret += (10 * charthandle); - + setProbePoint(&probeInfo); PREPARE_LOCAL_BUF(); - PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM, LC_CUSTOM, "dpdd", charthandle, seriesname, type, color); - PACK_COMMON_END(ret, 0, 2); + PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM, + API_ID_da_create_series, + "dpdd", charthandle, voidp_to_uint64(seriesname), + type, color); + PACK_COMMON_END('d', ret, 0, 2); PACK_CUSTOM(charthandle, type, seriesname, color, 0.0f); FLUSH_LOCAL_BUF(); probeBlockEnd(); - + return ret; } - + da_handle da_create_default_series(da_handle charthandle, char* seriesname) { return da_create_series(charthandle, seriesname, @@ -530,14 +536,14 @@ int da_set_callback(da_handle series_handle, da_user_data_2_chart_data callback, int cindex, sindex; cindex = (int)(series_handle / 10); sindex = series_handle % 10; - + // check series handle if(cindex <= 0 || cindex > chm.chart_handle_index) return ERR_WRONG_HANDLE; - + if(sindex > chm.series_handle_index[(int)cindex]) return ERR_WRONG_HANDLE; - + // check rest parameters if(interval == CHART_NO_CYCLE && callback != NULL) return ERR_WRONG_PARAMETER; @@ -550,8 +556,10 @@ int da_set_callback(da_handle series_handle, da_user_data_2_chart_data callback, // register new callback if(callback != NULL) { + int re; add_to_callback_list(interval, cindex, series_handle, callback, data_addr); - start_callback_thread(interval); + re = start_callback_thread(interval); + LOG("start callback thread return %d\n", re); } probeBlockEnd(); @@ -561,27 +569,29 @@ int da_set_callback(da_handle series_handle, da_user_data_2_chart_data callback, void da_log(da_handle series_handle, float uservalue) { DECLARE_CHART_VARIABLE; - + // chech if series handle is valid int cindex, sindex; cindex = (int)(series_handle / 10); sindex = series_handle % 10; - + if(cindex <= 0 || cindex > chm.chart_handle_index) return; - + if(sindex > chm.series_handle_index[(int)cindex]) return; - + probeBlockStart(); - + setProbePoint(&probeInfo); PREPARE_LOCAL_BUF(); - PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM, LC_CUSTOM, "dw", series_handle, uservalue); - PACK_COMMON_END(0, 0, 2); + PACK_COMMON_BEGIN(MSG_PROBE_CUSTOM, + API_ID_da_log, + "df", series_handle, uservalue); + PACK_COMMON_END('v', 0, 0, 2); PACK_CUSTOM(series_handle, 0, "", 0, uservalue); FLUSH_LOCAL_BUF(); - + probeBlockEnd(); }