From 77b28d638da411c1e5fa136495f2e055736c0aee Mon Sep 17 00:00:00 2001 From: Nikita Kalyazin Date: Wed, 3 Jul 2013 17:49:19 +0400 Subject: [PATCH] [FEATURE] add reconfigure --- daemon/da_protocol.c | 9 +++++-- daemon/da_protocol.h | 4 +-- daemon/daemon.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++----- daemon/daemon.h | 3 ++- daemon/threads.c | 13 +++++----- 5 files changed, 82 insertions(+), 17 deletions(-) diff --git a/daemon/da_protocol.c b/daemon/da_protocol.c index bd6036b..93e7577 100644 --- a/daemon/da_protocol.c +++ b/daemon/da_protocol.c @@ -887,6 +887,7 @@ int host_message_handler(struct msg_t *msg) struct app_info_t app_info; struct target_info_t target_info; struct msg_t *msg_reply; + struct conf_t conf; LOGI("MY HANDLE %s (%X)\n", msg_ID_str(msg->id), msg->id); @@ -912,7 +913,7 @@ int host_message_handler(struct msg_t *msg) return -1; } - if (startProfiling(prof_session.conf.use_features) < 0) { + if (start_profiling() < 0) { sendACKToHost(msg->id, ERR_CANNOT_START_PROFILING, 0, 0); return -1; } @@ -930,11 +931,15 @@ int host_message_handler(struct msg_t *msg) sendACKToHost(msg->id, ERR_NO, 0, 0); break; case NMSG_CONFIG: - if (!parse_msg_config(msg->payload, &prof_session.conf)) { + if (!parse_msg_config(msg->payload, &conf)) { LOGE("config parsing error\n"); sendACKToHost(msg->id, ERR_WRONG_MESSAGE_FORMAT, 0, 0); return -1; } + if (!reconfigure(conf)) { + LOGE("Cannot change configuration\n"); + return -1; + } sendACKToHost(msg->id,ERR_NO,0,0); break; case NMSG_BINARY_INFO: diff --git a/daemon/da_protocol.h b/daemon/da_protocol.h index 6640577..460d5da 100644 --- a/daemon/da_protocol.h +++ b/daemon/da_protocol.h @@ -96,7 +96,8 @@ enum feature_code{ FL_NETWORK_API_PROBING =0x20000,//network API (glibc, OSP, libsoap, openssl) FL_OPENGL_API_PROBING =0x40000 //openGL API }; -#define IS_OPT_SET(OPT) (prof_session.conf.use_features & (OPT)) +#define IS_OPT_SET_IN(OPT, reg) (reg & (OPT)) +#define IS_OPT_SET(OPT) IS_OPT_SET_IN((OPT), prof_session.conf.use_features) enum app_type{ AT_TIZEN =0x01, @@ -140,7 +141,6 @@ struct app_info_t { char *exe_path; }; -//typedef uint32_t conf_t; struct conf_t { uint64_t use_features; uint32_t system_trace_period; diff --git a/daemon/daemon.c b/daemon/daemon.c index 8409bfe..1748df5 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -304,7 +304,7 @@ static int exec_app(const struct app_info_t *app_info) static void epoll_add_input_events(); static void epoll_del_input_events(); -int startProfiling(long launchflag) +int start_profiling() { const struct app_info_t *app_info = &prof_session.app_info; int res = 0; @@ -315,7 +315,6 @@ int startProfiling(long launchflag) #ifndef LOCALTEST smack_lsetlabel(SCREENSHOT_DIR, "*", SMACK_LABEL_ACCESS); #endif - manager.config_flag = launchflag; if (IS_OPT_SET(FL_CPU | FL_MEMORY)) { if (samplingStart() < 0) { @@ -339,8 +338,6 @@ int startProfiling(long launchflag) recording_stop: if (IS_OPT_SET(FL_RECORDING)) epoll_del_input_events(); - -sampling_stop: if (IS_OPT_SET(FL_CPU | FL_MEMORY)) samplingStop(); @@ -356,6 +353,64 @@ void stop_profiling(void) samplingStop(); } +static void reconfigure_recording(struct conf_t conf) +{ + uint64_t old_features = prof_session.conf.use_features; + uint64_t new_features = conf.use_features; + uint64_t to_enable = (new_features ^ old_features) & new_features; + uint64_t to_disable = (new_features ^ old_features) & old_features; + + if (IS_OPT_SET_IN(FL_RECORDING, to_disable)) { + epoll_del_input_events(); + prof_session.conf.use_features &= ~FL_RECORDING; + } + + if (IS_OPT_SET_IN(FL_RECORDING, to_enable)) { + epoll_add_input_events(); + prof_session.conf.use_features |= FL_RECORDING; + } + +} + +static int reconfigure_cpu_and_memory(struct conf_t conf) +{ + uint64_t old_features = prof_session.conf.use_features; + uint64_t new_features = conf.use_features; + uint64_t to_enable = (new_features ^ old_features) & new_features; + uint64_t to_disable = (new_features ^ old_features) & old_features; + + prof_session.conf.system_trace_period = conf.system_trace_period; + + if (IS_OPT_SET(FL_CPU | FL_MEMORY)) + samplingStop(); + + if (IS_OPT_SET_IN(FL_CPU | FL_MEMORY, to_disable)) { + prof_session.conf.use_features &= ~(FL_CPU | FL_MEMORY); + return 0; + } + + if (IS_OPT_SET_IN(FL_CPU | FL_MEMORY, to_enable)) { + if (samplingStart() < 0) { + LOGE("Cannot start sampling\n"); + return -1; + } + prof_session.conf.use_features |= (FL_CPU | FL_MEMORY); + } + + return 0; +} + +int reconfigure(struct conf_t conf) +{ + reconfigure_recording(conf); + if (reconfigure_cpu_and_memory(conf)) { + LOGE("Cannot reconf cpu and memory\n"); + return -1; + } + + return 0; +} + // just send stop message to all target process static void terminate_all_target() { @@ -500,8 +555,11 @@ static int targetServerHandler(int efd) // send config message to target process log.type = MSG_OPTION; - log.length = sprintf(log.data, "%u", manager.config_flag); - send(manager.target[index].socket, &log, sizeof(log.type) + sizeof(log.length) + log.length, MSG_NOSIGNAL); + log.length = sprintf(log.data, "%u", + prof_session.conf.use_features); + send(manager.target[index].socket, &log, + sizeof(log.type) + sizeof(log.length) + log.length, + MSG_NOSIGNAL); // make event fd manager.target[index].event_fd = eventfd(0, EFD_NONBLOCK); diff --git a/daemon/daemon.h b/daemon/daemon.h index fd33b2a..65883b1 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -248,8 +248,9 @@ int samplingStop(); // TODO maybe need move to other file -int startProfiling(long launchflag); +int start_profiling(); void stop_profiling(); +int reconfigure(); int sendACKCodeToHost(enum HostMessageType resp, int msgcode); void terminate_all(); void _device_write(input_dev *dev, struct input_event* in_ev); diff --git a/daemon/threads.c b/daemon/threads.c index 402353f..bb5b08b 100644 --- a/daemon/threads.c +++ b/daemon/threads.c @@ -44,8 +44,6 @@ #include "da_data.h" //#define DEBUG_GSI -#define TIMER_INTERVAL_SEC 1 -#define TIMER_INTERVAL_USEC 0 static void* recvThread(void* data) { @@ -295,6 +293,9 @@ void* samplingThread(void* data) int samplingStart() { struct itimerval timerval; + time_t sec = prof_session.conf.system_trace_period / 1000; + suseconds_t usec = prof_session.conf.system_trace_period * 1000 % + 1000000; if(manager.sampling_thread != -1) // already started return 1; @@ -305,10 +306,10 @@ int samplingStart() return -1; } - timerval.it_interval.tv_sec = TIMER_INTERVAL_SEC; - timerval.it_interval.tv_usec = TIMER_INTERVAL_USEC; - timerval.it_value.tv_sec = TIMER_INTERVAL_SEC; - timerval.it_value.tv_usec = TIMER_INTERVAL_USEC; + timerval.it_interval.tv_sec = sec; + timerval.it_interval.tv_usec = usec; + timerval.it_value.tv_sec = sec; + timerval.it_value.tv_usec = usec; setitimer(ITIMER_REAL, &timerval, NULL); return 0; -- 2.7.4