INC := -I/usr/include \
-I/usr/include/system \
-I/usr/include/telephony \
- -I/usr/include/vconf
+ -I/usr/include/vconf \
+ -I.
DAEMON_SRCS := \
main.c \
daemon.c \
+ da_protocol.c \
threads.c \
da_debug.c \
+ da_data.c \
utils.c \
sys_stat.c
+DAEMON_SRCS_HOST := \
+ main.c \
+ daemon.c \
+ da_protocol.c \
+ threads.c \
+ da_debug.c \
+ da_data.c \
+ utils.c \
+ sys_stat.c
+
+
LDLIBS_PATH := -L/usr/lib -L./lib/
LIBS_TIZEN :=# -lcapi-system-runtime-info \
-lcapi-telephony-network-info \
-lsmack \
-lcapi-system-info
+LIBS_COMMON_HOST := -lglib-2.0
+HOST_BUILD := -DHOST_BUILD=1 -DLOCALTEST=1
DEBUG_ON := -DDEBUG=1
-FLAGS = -pthread -Wall
+FLAGS = -pthread -Wall -O0
TARGET = da_manager
DASCRIPT = da_command
all: $(TARGET)
+host: $(DAEMON_SRCS_HOST)
+ $(CC) $(INC) $(FLAGS) $(DEBUG_ON) $(HOST_BUILD) $(DEVICE) -o $(TARGET) $(DAEMON_SRCS_HOST) $(LDLIBS_PATH) $(LIBS_COMMON_HOST) $(LIBS_TIZEN)
+
$(TARGET): $(DAEMON_SRCS)
$(CC) $(INC) $(FLAGS) $(DEBUG_ON) $(DEVICE) -o $@ $(DAEMON_SRCS) $(LDLIBS_PATH) $(LIBS_COMMON) $(LIBS_TIZEN)
localtest:
- $(CC) -DLOCALTEST $(INC) $(FLAGS) -o $(TARGET) $(DEBUG_ON) $(DEVICE) $(LDLIBS_PATH) $(LIBS_COMMON) $(DAEMON_SRCS)
+ $(CC) -DLOCALTEST -DHOST_BUILD $(INC) $(FLAGS) -o $(TARGET) $(DEBUG_ON) $(DEVICE) $(LDLIBS_PATH) $(LIBS_COMMON) $(DAEMON_SRCS)
install:
[ -d "$(DESTDIR)/$(INSTALLDIR)" ] || mkdir -p $(DESTDIR)/$(INSTALLDIR)
+++ /dev/null
-#!/bin/bash
-
-KILL=/usr/bin/killall
-MANAGER=/usr/bin/da_manager
-EVENT=/usr/bin/da_event
-FIND=/usr/bin/find
-GETAPPINSTALLPATH="/usr/bin/pkgcmd -a"
-PORTFILE=/tmp/port.da
-
-print_usage()
-{
- echo "usage: da_command [options]"
- echo "Options:"
- echo "killmanager terminate da_manager"
-# echo "killapp apppath terminate application"
- echo "runmanager execute da_manager"
- echo "runevent record|play execute da_event"
- echo "findunittest find unittest project"
-}
-
-kill_manager()
-{
- $KILL $MANAGER
- rm -f $PORTFILE
-}
-
-kill_app()
-{
- $KILL $APPPATH
-}
-
-run_manager()
-{
- kill_manager
- $MANAGER
-}
-
-run_event()
-{
- case "$EVENTOPTION" in
- record)
- EVENTMODE="-r"
- ;;
- play)
- EVENTMODE="-s"
- ;;
- *)
- echo "Invalid event option!"
- print_usage
- exit 1
- ;;
- esac
-
- $EVENT $EVENTMODE
-}
-
-find_unittest()
-{
- $FIND `$GETAPPINSTALLPATH | awk '{if (FNR==1) printf $NF}'` -name *.unittest
-}
-
-process_list()
-{
- ps -eo pid,cmd
-}
-
-
-if test $# -gt 2 -o $# -lt 1; then
- print_usage
- exit 1
-fi
-
-if test -n "$2"; then
- case "$1" in
- runevent)
- EVENTOPTION=$2
- ;;
-# killapp)
-# APPPATH=$2
-# ;;
- *)
- print_usage
- exit 1
- ;;
- esac
-fi
-
-case "$1" in
- killmanager)
- kill_manager
- ;;
-# killapp)
-# kill_app
-# ;;
- runmanager)
- run_manager
- ;;
- runevent)
- run_event
- ;;
- findunittest)
- find_unittest
- ;;
- process)
- process_list
- ;;
- *)
- echo "Unknown option!"
- print_usage
- ;;
-esac
-
--- /dev/null
+#include "da_protocol.h"
+#include "da_data.h"
+/*
+struct msg_system_t msg_system;
+
+int fill_message_system(struct msg_system_t ** sys){
+
+ struct msg_system_t * psys = *sys;
+ psys->energy = 0;
+ psys->WiFi_status = get_wifi_status();
+ psys->BT_status = get_bt_status();
+ psys->GPS_status = get_gps_status();
+ psys->brightness_status = get_brightness_status();
+ psys->camera_status = get_camera_status();
+ psys->sound_status = get_sound_status();
+ psys->audio_status = get_audio_status();
+ psys->vibration_status = get_vibration_status();
+ psys->voltage_status = get_voltage_status();
+ psys->RSSI_status = get_rssi_status();
+ psys->video_status = get_video_status();
+ psys->call_status = get_call_status();
+ psys->DNet_status = get_dnet_status();
+// psys->CPU_frequency = get_cpu_frequency(), freqbuf in get_resource_info()
+// psys->app_CPU_usage = app_cpu_usage in get_resource_info()
+// psys->CPU_load cpuload in get_resource_info()
+// psys->virtual_memory = virtual in get_resource_info()
+// psys->resident_memory = resident in get_resource_info()
+// psys->shared_memory = shared in get_resource_info()
+// psys->PSS_memory = pss in get_resource_info()
+// psys->total_alloc_size = get_total_alloc_size();
+// psys->system_memory_total = get_system_total_memory(), sysmemtotal in get_resource_info();
+// psys->system_memory_used = update_system_memory_data(), sysmemused in get_resource_info();
+ psys->total_used_drive = get_total_used_drive();
+// psys->count_of_threads = thread in get_resource_info()
+// psys->thread_load = thread_load in get_resource_info()
+// psys->count_of_processes = procNode* proc in get_resource_info() but no count
+
+ return 0;
+};
+*/
+
+
+int fill_data_msg_head (struct msg_data_t *data, uint32_t msgid, uint32_t seq, uint32_t len)
+{
+ data->id = msgid;
+ data->sequence = seq; // TODO fill good value
+ gettimeofday(&data->time, NULL);
+ data->len = len;
+ return 0;
+}
+
+
+//allocate memory, need free!!!
+int gen_message_terminate(struct msg_data_t *data, uint32_t id)
+{
+ char *p;
+ fill_data_msg_head(data,NMSG_TERMINATE, 0, sizeof(uint32_t) );
+ // TODO fill good value
+ data->payload = malloc(data->len);
+
+ p = data->payload;
+ pack_int(p,id);
+}
+
+//allocate memory, need free!!!
+int gen_message_error(struct msg_data_t *data, const char * err_msg)
+{
+ char *p;
+ fill_data_msg_head(data, NMSG_ERROR, 0, strlen(err_msg)+1 );
+ data->payload = malloc(strlen(err_msg)+1);
+
+ p = data->payload;
+ pack_str(p,err_msg);
+ return 0;
+}
+
+//allocatr memory, need free!!!
+int gen_message_event(struct msg_data_t *data, struct input_event *events,
+ uint32_t events_count, uint32_t id)
+{
+ uint32_t i = 0;
+ uint32_t payload_len =
+ events_count * sizeof(*events)+
+ sizeof(payload_len);
+ char *p;
+
+
+
+ fill_data_msg_head(data, NMSG_RECORD, 0, payload_len );
+
+ data->payload = malloc(payload_len);
+
+ p = data->payload;
+ pack_int(p,events_count);
+ for (i=0; i<events_count; i++){
+ pack_int32(p,id);
+ pack_int32(p,events[i].type);
+ pack_int32(p,events[i].code);
+ pack_int32(p,events[i].value);
+ }
+
+ return 0;
+}
+
+int reset_data_msg(struct msg_data_t *data)
+{
+
+ free(data->payload);
+ memset(data,0,sizeof(*data));
+
+ return 0;
+}
+
--- /dev/null
+#ifndef _DA_DATA_H_
+#define _DA_DATA_H_
+int fill_data_msg_head (struct msg_data_t *data, uint32_t msgid, uint32_t seq, uint32_t len);
+
+//allocate memory, need free!!!
+int gen_message_terminate(struct msg_data_t *data, uint32_t id);
+
+//allocate memory, need free!!!
+
+int reset_data_msg(struct msg_data_t *data);
+
+int gen_message_error(struct msg_data_t *data, const char * err_msg);
+#endif //#ifndef _DA_DATA_H_
--- /dev/null
+
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <sys/sysinfo.h>
+
+#include "da_protocol.h"
+#include "daemon.h"
+#include "sys_stat.h"
+#define parce_deb_on
+
+/*
+struct msg_t msg;
+struct app_info_t app_info;
+struct probe_t probe;
+struct us_inst_t us_inst;
+struct app_inst_t app_inst;
+struct prof_session_t prof_session;
+*/
+
+static struct prof_session_t prof_session;
+
+static void print_app_info( struct app_info_t *app_info);
+static void print_conf(struct conf_t * conf);
+static void print_us_func_inst(struct us_func_inst_t * func_inst, int count,char * tab);
+static void print_us_lib_inst(struct us_lib_inst_t * lib_inst,int num,char * tab);
+static void print_user_space_app_inst(struct app_inst_t * app_inst, int num, char * tab);
+static void print_user_space_inst(struct user_space_inst_t * user_space_inst);
+static void print_log_interval(log_interval_t log_interval);
+static void print_probe(struct probe_t *probe);
+static void print_us_inst(struct us_inst_t *us_inst);
+static void print_prof_session(struct prof_session_t *prof_session);
+
+//DEBUG FUNCTIONS
+#define dstr(x) #x
+/*
+char* MSG_to_str_arr[ 2 * MSG_MAX_NUM + 1 ] = {
+"MSG_???",
+"MSG_KEEP_ALIVE",
+"MSG_START",
+"MSG_STOP",
+"MSG_CONFIG",
+"MSG_BINARY_INFO",
+"MSG_SWAP_INST",
+"MSG_GET_TARGET_INFO",
+"MSG_SWAP_INST_ADD",
+"MSG_SWAP_INST_REMOVE",
+
+"MSG_KEEP_ALIVE_ACK",
+"MSG_START_ACK",
+"MSG_STOP_ACK",
+"MSG_CONFIG_ACK",
+"MSG_BINARY_INFO_ACK",
+"MSG_SWAP_INST_ACK",
+"MSG_GET_TARGET_INFO_ACK",
+"MSG_SWAP_INST_ADD_ACK",
+"MSG_SWAP_INST_REMOVE_ACK",
+
+};*/
+#define check_and_return(par,check) if ( par == check ) {return dstr(check);}
+#define check_2(a1,a2) check_and_return(ID,a1) else check_and_return(ID,a2)
+#define check_4(a1,a2,a3,a4) check_2(a1,a2) else check_2(a3,a4)
+#define check_8(a1,a2,a3,a4,a5,a6,a7,a8) check_4(a1,a2,a3,a4) else check_4(a5,a6,a7,a8)
+
+#define check_all(a1, ...) check_and_return(ID,a1) //#else check_all(__VA_ARGS__)
+char* msg_ID_str ( enum HostMessageT ID)
+{
+ check_8(
+ NMSG_KEEP_ALIVE,
+ NMSG_START,
+ NMSG_STOP,
+ NMSG_CONFIG,
+
+ NMSG_BINARY_INFO,
+ NMSG_SWAP_INST,
+ NMSG_GET_TARGET_INFO,
+ NMSG_SWAP_INST_ADD
+ )
+ else
+ check_8(
+ NMSG_SWAP_INST_REMOVE,
+ NMSG_KEEP_ALIVE_ACK,
+ NMSG_START_ACK,
+ NMSG_STOP_ACK,
+
+ NMSG_CONFIG_ACK,
+ NMSG_BINARY_INFO_ACK,
+ NMSG_SWAP_INST_ACK,
+ NMSG_GET_TARGET_INFO_ACK
+ )
+ else
+ check_8(
+ NMSG_SWAP_INST_ADD_ACK,
+ NMSG_SWAP_INST_REMOVE_ACK,
+ NMSG_PROCESS_INFO,
+ NMSG_TERMINATE,
+
+ NMSG_ERROR,
+ NMSG_SAMPLE,
+ NMSG_SYSTEM,
+ NMSG_IMAGE
+ )
+ else
+ check_8(
+ NMSG_RECORD,
+ NMSG_FUNCTION_ENTRY,
+ NMSG_FUNCTION_EXIT,
+ NMSG_CONTEXT_SWITCH_ENTRY,
+
+ NMSG_CONTEXT_SWITCH_EXIT,
+ NMSG_PROBE,
+ NMSG_PROBE_MEMORY,
+ NMSG_PROBE_UICONTROL
+ )
+ else
+ check_8(
+ NMSG_PROBE_UIEVENT,
+ NMSG_PROBE_RESOURCE,
+ NMSG_PROBE_LIFECYCLE,
+ NMSG_PROBE_SCREENSHOT,
+
+ NMSG_PROBE_SCENE,
+ NMSG_PROBE_THREAD,
+ NMSG_PROBE_CUSTOM,
+ NMSG_PROBE_SYNC
+ ) else
+ return "HZ";
+/*
+ *
+ if (
+ ( (ID >= NMSG_KEEP_ALIVE) && ( ID <= NMSG_GET_TARGET_INFO) )
+ ||
+ ( (ID >= NMSG_KEEP_ALIVE_ACK) && ( ID <= NMSG_GET_TARGET_INFO_ACK) )
+ )
+ {
+ if (ID & NMSG_ACK_FLAG){
+ ID &= ~ NMSG_ACK_FLAG;
+ ID+=9;
+ }
+ }
+ else
+ {
+ ID = 0;
+ }
+
+ return MSG_to_str_arr[ID];
+ */
+}
+
+
+static char *msgErrStr(enum ErrorCode err)
+{
+ switch (err) {
+ case ERR_NO:
+ return "success";
+ case ERR_LOCKFILE_CREATE_FAILED:
+ return "lock file create failed";
+ case ERR_ALREADY_RUNNING:
+ return "already running";
+ case ERR_INITIALIZE_SYSTEM_INFO_FAILED:
+ return "initialize system info failed";
+ case ERR_HOST_SERVER_SOCKET_CREATE_FAILED:
+ return "host server socket create failed";
+ case ERR_TARGET_SERVER_SOCKET_CREATE_FAILED:
+ return "target server socket create failed";
+ case ERR_SIGNAL_MASK_SETTING_FAILED: //TODO del (old parametr)
+ return "ERR SIGNAL MASK SETTING FAILED";
+ case ERR_WRONG_MESSAGE_FORMAT:
+ return "wrong message format";
+ case ERR_WRONG_MESSAGE_TYPE:
+ return "wrong message type";
+ case ERR_WRONG_MESSAGE_DATA:
+ return "wrong message data";
+ case ERR_CANNOT_START_PROFILING:
+ return "cannot start profiling";
+ case ERR_SERV_SOCK_CREATE:
+ return "server socket creation failed (written in /tmp/da.port file)";
+ case ERR_SERV_SOCK_BIND:
+ return "server socket bind failed (written in /tmp/da.port file)";
+ case ERR_SERV_SOCK_LISTEN:
+ return "server socket listen failed (written in /tmp/da.port file)";
+ case ERR_UNCKNOWN:
+ default:
+ return "unknown error";
+ }
+ return "unknown error";
+}
+
+
+#define print_feature(f,in,to,delim) if (f & in)\
+ {\
+ sprintf(to, dstr(f) delim );\
+ to+=strlen( dstr(f) delim );\
+ }
+#define print_feature_a(f) print_feature(f,feature,to,", ")
+void feature_code_str(uint32_t feature, char * to)
+{
+ print_feature_a(FL_CPU);
+ print_feature_a(FL_MEMORY);
+ print_feature_a(FL_FUNCTION_PROFILING);
+ print_feature_a(FL_MEMORY_ALLCATION_PROBING);
+ print_feature_a(FL_FILE_API_PROBING);
+ print_feature_a(FL_THREAD_API_PROBING);
+ print_feature_a(FL_OSP_UI_API_PROBING);
+ print_feature_a(FL_SCREENSHOT);
+ print_feature_a(FL_USER_EVENT);
+ print_feature_a(FL_RECORDING);
+ print_feature_a(FL_SYSTCALL_FILE);
+ print_feature_a(FL_SYSTCALL_IPC);
+ print_feature_a(FL_SYSTCALL_PROCESS);
+ print_feature_a(FL_SYSTCALL_SIGNAL);
+ print_feature_a(FL_SYSTCALL_NETWORK);
+ print_feature_a(FL_SYSTCALL_DESC);
+ print_feature_a(FL_CONTEXT_SWITCH);
+ print_feature_a(FL_NETWORK_API_PROBING);
+ print_feature_a(FL_OPENGL_API_PROBING);
+
+}
+#ifdef parce_deb_on
+#define parse_deb(...) do{\
+ LOGI("%s->\t",__FUNCTION__);\
+ LOGI(__VA_ARGS__);\
+ }while(0)
+#else
+#define parse_deb(...) do{}while(0)
+#endif /*parce_on*/
+
+//PARSE FUNCTIONS
+static int receive_msg_header(struct msg_t *msg)
+{
+ // TODO: cycle until m_id and m_len
+ return 0;
+}
+
+static int receive_msg_payload(struct msg_t *msg)
+{
+ msg->payload = (char *)malloc(msg->len);
+ if (!msg->payload) {
+ // TODO: report error
+ return 1;
+ }
+ // TODO: cycle until
+ return 0;
+}
+
+static char * parse_string(char *buf, char **str)
+{
+ int len = strlen(buf);
+ *str = strdup(buf);
+ parse_deb("<%s>\n",*str);
+ return buf + (len + 1);
+}
+
+static char *parse_chars(char *buf, uint32_t count, char **str)
+{
+ *str = (char *) malloc( (count+1) * (sizeof(char) ));
+ memcpy(*str, buf, count);
+ (*str)[count] = 0;
+ parse_deb("<%s>\n",*str);
+ return buf + (count);
+}
+
+static char *parse_int32(char *buf, uint32_t *val)
+{
+ *val = *(uint32_t *)buf;
+
+ parse_deb("<%d><0x%08X>\n",*val,*val);
+ return buf + sizeof(uint32_t);
+}
+
+static char *parse_int64(char *buf, uint64_t *val)
+{
+ *val = *(uint64_t *)buf;
+
+ parse_deb("<%d><0x%016X>\n",*val,*val);
+ return buf + sizeof(uint64_t);
+}
+
+static char *parse_app_info(char *buf,
+ struct app_info_t *app_info)
+{
+ char *p = buf;
+
+ p = parse_int32(p, &app_info->app_type);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_string(p, &app_info->app_id);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+ p = parse_string(p, &app_info->exe_path);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+// print_app_info(app_info);
+
+ return p;
+}
+
+static char * parse_conf(char *buf, struct conf_t *conf)
+{
+ char *p = buf;
+
+ p = parse_int64( p, &conf->use_features);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_int32( p, &conf->system_trace_period);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_int32( p, &conf->data_message_period);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+ //print_conf(conf);
+ return buf + sizeof(*conf);
+}
+
+
+static char *parse_log_interval(char *buf, log_interval_t *log_interval)
+{
+ *log_interval = *(log_interval_t *)buf;
+
+ return buf + sizeof(*log_interval);
+}
+
+static char *parse_probe(char *buf, struct probe_t *probe)
+{
+ char *p = buf;
+
+ p = parse_int64(p, &probe->addr);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_int32(p, &probe->arg_num);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ probe->arg_fmt = (char *)malloc(probe->arg_num);
+ if (!probe->arg_fmt) {
+ // TODO: report error
+ return 0;
+ }
+
+ memcpy(probe->arg_fmt, p, probe->arg_num);
+ p += probe->arg_num;
+
+ return p;
+}
+
+static char *parse_us_inst(char *buf, struct us_inst_t *us_inst)
+{
+ char *p = buf;
+ int i = 0;
+
+ p = parse_string(p, &us_inst->path);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+ p = parse_int32(p, &us_inst->probe_num);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ us_inst->probes = (struct probe_t *)malloc(us_inst->probe_num *
+ sizeof(*us_inst->probes));
+
+ if (!us_inst->probes) {
+ // TODO: report error
+ return 0;
+ }
+ for (i = 0; i < us_inst->probe_num; i++) {
+ p = parse_probe(p, &us_inst->probes[i]);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+ }
+
+ return p;
+}
+
+static char *parse_us_inst_func( char * buf, struct us_func_inst_t * dest)
+{
+ char *p = buf;
+
+ p = parse_int64( p, &(dest->func_addr));
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_int32( p, &(dest->args_num));
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_chars( p, dest->args_num, &(dest->args));
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+ return p;
+
+}
+
+static char * parse_func_inst_list(char *buf,
+ uint32_t *num,
+ struct us_func_inst_t ** us_func_inst_list)
+{
+ uint32_t i = 0;
+ char * p = buf;
+ p = parse_int32( p, num);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+ //parce user space function list
+
+ LOGI("us_func_inst_list size = %d * %d\n",(*num) , (int)sizeof(**us_func_inst_list) );
+ *us_func_inst_list =
+ (struct us_func_inst_t *)
+ malloc( (*num) * sizeof(**us_func_inst_list) );
+ if (!*us_func_inst_list){
+ // TODO: report error
+ return 0;
+ };
+
+ for ( i = 0; i < *num; i++){
+ p = parse_us_inst_func( p, &((* us_func_inst_list)[i]));
+ }
+ return p;
+}
+
+static char *parse_us_inst_lib( char * buf, struct us_lib_inst_t * dest)
+{
+ char *p = buf;
+
+ p = parse_string( p, &(dest)->bin_path);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_func_inst_list( p, &dest->func_num, &dest->us_func_inst_list);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+ return p;
+
+}
+
+static char * parse_lib_inst_list(char *buf,
+ uint32_t *num,
+ struct us_lib_inst_t ** us_lib_inst_list)
+{
+ uint32_t i = 0;
+ char * p = buf;
+ p = parse_int32( p, num);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ //parce user space lib list
+ LOGI("lib_list size = %d\n", (*num) * (int)sizeof(**us_lib_inst_list) );
+ *us_lib_inst_list =
+ (struct us_lib_inst_t *)
+ malloc( (*num) * sizeof(**us_lib_inst_list) );
+ if (!*us_lib_inst_list){
+ // TODO: report error
+ return 0;
+ };
+ for ( i = 0; i < *num; i++){
+ p = parse_us_inst_lib( p, &( (*us_lib_inst_list)[i] ) );
+ }
+ return p;
+}
+
+static char * parse_app_inst(char *buf,
+ struct app_inst_t *app_inst)
+{
+ char *p = buf;
+ uint32_t num = 0;
+
+ p = parse_int32( p, &app_inst->app_type);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+ p = parse_string( p, &app_inst->app_id);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+ p = parse_string( p, &app_inst->exec_path);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+ p = parse_func_inst_list( p, &app_inst->func_num , &(app_inst->us_func_inst_list));
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+ //parce user space function list
+
+ LOGI(">=%04X : %s, %s, %d\n", app_inst->app_type, app_inst->app_id, app_inst->exec_path , num);
+
+ p = parse_lib_inst_list( p, &app_inst->lib_num , &app_inst->us_lib_inst_list);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ return p;
+}
+
+char * parse_user_space_inst(char * buf, struct user_space_inst_t * user_space_inst)
+{
+ char *p = buf;
+ uint32_t num = 0 , i = 0;
+ struct app_inst_t * list = 0;
+
+ p = parse_int32 ( p, &num );
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ LOGI("%d * %d\n ",(int) sizeof(*(user_space_inst->app_inst_list)), num);
+ //parse app list
+ if ( num != 0 ) {
+ list = (struct app_inst_t *) malloc (
+ sizeof(*(user_space_inst->app_inst_list))
+ *
+ num
+ );
+ if ( !list ){
+ return 0;
+ //TODO report error
+ };
+
+ for ( i = 0; i < num; i++){
+ p = parse_app_inst( p, &(list[i]) );
+ };
+
+ user_space_inst->app_num = num;
+ user_space_inst->app_inst_list = list;
+ }
+ return p;
+}
+
+//REPLAY EVENTS PARSE
+static char *parse_timeval(char *buf, struct timeval *tv)
+{
+ char *p = buf;
+
+ parse_deb("time\n");
+
+ // FIXME: is sec/usec order correct?
+ p = parse_int32(p, (uint32_t *)&tv->tv_usec);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_int32(p, (uint32_t *)&tv->tv_sec);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ return p;
+}
+
+static char *parse_replay_event(char *buf,
+ struct replay_event_t *re)
+{
+ char *p = buf;
+
+ p = parse_timeval(p, &re->ev.time);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_int32(p, &re->id);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_int32(p, (uint32_t *)&re->ev.type);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_int32(p, (uint32_t *)&re->ev.code);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_int32(p, (uint32_t *)&re->ev.value);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ return p;
+}
+
+static char *parse_replay_event_seq(char *buf,
+ struct replay_event_seq_t *res)
+{
+ char *p = buf;
+ int i = 0;
+ parse_deb("REPLAY\n");
+ parse_deb("enable\n");
+ p = parse_int32(p, &res->enabled);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ parse_deb("time main\n");
+ p = parse_timeval(p, &res->tv);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ parse_deb("count\n");
+ p = parse_int32(p, &res->event_num);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ res->events = (struct replay_event_t *)malloc(res->event_num *
+ sizeof(*res->events));
+ if (!res->events) {
+ // TODO: report error
+ return 0;
+ }
+
+ for (i = 0; i < res->event_num; i++) {
+ parse_deb("sub_rep\n");
+ p = parse_replay_event(p, &res->events[i]);
+ if (!p) {
+ // TODO: report error
+ goto free_events;
+ }
+ }
+
+ goto end;
+
+free_events:
+ free(res->events);
+ res->event_num = 0;
+
+end:
+ return p;
+}
+
+//*REPLAY EVENT PARSE
+
+static int parse_prof_session(char *msg_payload,
+ struct prof_session_t *prof_session)
+{
+ char *p = msg_payload;
+
+ p = parse_app_info(p, &prof_session->app_info);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+ p = parse_conf(p, &prof_session->conf);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_user_space_inst(p, &prof_session->user_space_inst);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ p = parse_replay_event_seq(p, &prof_session->replay_event_seq);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+/* p = parse_log_interval(p, &prof_session->log_interval);
+ if (!p) {
+ // TODO: report error
+ return 1;
+ }
+ p = parse_app_inst(p, &prof_session->app_inst);
+ if (!p) {
+ // TODO: report error
+ return 1;
+ }
+*/
+ print_prof_session(prof_session);
+ return 1;
+}
+
+int get_sys_mem_size(uint32_t *sys_mem_size){
+ struct sysinfo info;
+ sysinfo(&info);
+ *sys_mem_size = info.totalram;
+ return 0;
+}
+//int sysinfo(struct sysinfo *info);
+
+
+//warning allocate memory
+//need free after call
+static char *parse_target_info(char *msg_payload,char ** buf, uint32_t *len)
+{
+ struct target_info_t *target_info;
+ char *p = msg_payload;
+ *len = sizeof(*target_info);
+
+ *buf = malloc(*len);
+ target_info = (struct target_info_t *) *buf;
+ fill_target_info(target_info);
+
+ return p;
+}
+
+static char *parse_msg_config(char * msg_payload,
+ struct conf_t * conf)
+{
+ char *p = msg_payload;
+
+ p = parse_conf(p, conf);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ print_conf(conf);
+ return p;
+}
+
+static char *parse_msg_binary_info(char * msg_payload,
+ struct app_info_t *app_info)
+{
+ char *p = msg_payload;
+
+ p = parse_app_info(p, app_info);
+ if (!p) {
+ // TODO: report error
+ return 0;
+ }
+
+ print_app_info(app_info);
+ return p;
+}
+
+
+static void reset_app_info(struct app_info_t *app_info)
+{
+ app_info->app_id[0] = '\0';
+ app_info->exe_path[0] = '\0';
+}
+
+static void reset_conf(struct conf_t *conf)
+{
+ memset(conf, 0, sizeof(*conf));
+}
+
+static void reset_log_interval(log_interval_t *log_interval)
+{
+ memset(log_interval, 0, sizeof(*log_interval));
+}
+
+static void reset_probe(struct probe_t *probe)
+{
+ probe->addr = 0;
+ probe->arg_num = 0;
+ free(probe->arg_fmt);
+}
+
+static void reset_us_inst(struct us_inst_t *us_inst)
+{
+ int i = 0;
+
+ us_inst->path[0] = '\0';
+ for (i = 0; i < us_inst->probe_num; i++) {
+ reset_probe(&us_inst->probes[i]);
+ }
+ free(us_inst->probes);
+ us_inst->probe_num = 0;
+}
+
+static void reset_app_inst(struct app_inst_t *app_inst)
+{
+ /*
+ int i = 0;
+
+ reset_us_inst(&app_inst->app);
+
+ for (i = 0; i < app_inst->lib_num; i++) {
+ reset_us_inst(&app_inst->libs[i]);
+ }
+ free(app_inst->libs);
+ app_inst->lib_num = 0;
+ */
+}
+
+static void reset_prof_session(struct prof_session_t *prof_session)
+{
+ reset_app_info(&prof_session->app_info);
+ reset_conf(&prof_session->conf);
+ //reset_log_interval(&prof_session->log_interval);
+ //reset_app_inst(&prof_session->app_inst);
+}
+
+// return 0 for normal case
+// return negative value for error case
+int parseHostMessage(struct msg_t* log, char* msg)
+{
+ int ret = 0; // parsing success
+ memcpy( log, msg, 8);//message ID, length
+ log->payload = malloc( log->len);
+ if ( log->payload != 0 )
+ {
+ memcpy( log->payload, msg+8, log->len);
+ }
+ else
+ {
+ LOGE("cannot malloc\n");
+ ret = -1;
+ }
+ return ret;
+}
+
+// msgstr can be NULL
+static int sendACKToHost(enum HostMessageT resp, enum ErrorCode err_code,
+ char *payload, int payload_size)
+{
+ if (manager.host.control_socket != -1)
+ {
+ struct msg_t *msg;
+ uint32_t err = err_code;
+ int loglen = sizeof(*msg) - sizeof(msg->payload) +
+ sizeof(err) + //return ID
+ payload_size;
+ char *logstr = malloc(loglen);
+ msg = (struct msg_t *)logstr;
+ char *p = &(msg->payload);
+
+ resp |= NMSG_ACK_FLAG;
+
+ //set message id
+ msg->id = resp;
+ //set payload lenth
+ msg->len = payload_size + sizeof(err);
+ //set return id
+ *(uint32_t *)p = err; p+=sizeof(err);
+ //copy payload data
+ memcpy(p, payload, payload_size);
+
+ LOGI("ACK (%s) payload=%d; size=%d\n",msg_ID_str(resp),payload,payload_size);
+ printBuf(logstr, loglen);
+
+ send(manager.host.control_socket, logstr, loglen, MSG_NOSIGNAL);
+ free(logstr);
+ return 0;
+ }
+ else
+ return 1;
+}
+
+int hostMessageHandle(struct msg_t *msg)
+{
+ char * answer = 0;
+ uint32_t answer_len = 0;
+ uint32_t ID = msg->id;
+ struct user_space_inst_t user_space_inst;
+
+ LOGI("MY HANDLE %s (%X)\n",msg_ID_str(msg->id),msg->id);
+ switch (ID) {
+ case NMSG_KEEP_ALIVE:
+ sendACKToHost(ID,ERR_NO,0,0);
+ break;
+ case NMSG_START:
+ if (!parse_prof_session(msg->payload, &prof_session)) {
+ // TODO: report error
+ sendACKToHost(ID,ERR_WRONG_MESSAGE_FORMAT,0,0);
+ return 1;
+ }
+ remove("/tmp/daemon_events");
+ event_fd = open("/tmp/daemon_events",O_RDWR | O_CREAT , S_IRUSR | S_IRGRP | S_IROTH);
+ LOGI("open = %d\n", event_fd);
+ // TODO: apply_prof_session()
+ sendACKToHost(ID,ERR_NO,0,0);
+ break;
+ case NMSG_STOP:
+ sendACKToHost(ID,ERR_NO,0,0);
+ // TODO: remove_prof_session()
+ if (event_fd>0){
+ close(event_fd);
+ }
+ reset_prof_session(&prof_session);
+ break;
+ case NMSG_CONFIG:
+ if (!parse_msg_config(msg->payload, &prof_session.conf)) {
+ // TODO: report error
+ LOGE("parce error <%s>\n",msg_ID_str(msg->id));
+ sendACKToHost(ID,ERR_WRONG_MESSAGE_FORMAT,0,0);
+ return 1;
+ }
+
+ sendACKToHost(ID,ERR_NO,0,0);
+ break;
+ case NMSG_BINARY_INFO:
+ if (!parse_msg_binary_info(msg->payload, &prof_session.app_info)) {
+ // TODO: report error
+ return 1;
+ }
+
+ sendACKToHost(ID,ERR_NO,0,0);
+
+ break;
+ case NMSG_SWAP_INST:
+ sendACKToHost(ID,ERR_NO,0,0);
+ break;
+ case NMSG_SWAP_INST_ADD:
+ if (!parse_user_space_inst(msg->payload, &prof_session.user_space_inst)){
+ // TODO: report error
+ return 0;
+ }
+ sendACKToHost(ID,ERR_NO,0,0);
+ break;
+ case NMSG_SWAP_INST_REMOVE:
+ if (!parse_user_space_inst(msg->payload, &prof_session.user_space_inst)){
+ // TODO: report error
+ return 0;
+ }
+ sendACKToHost(ID,ERR_NO,0,0);
+ break;
+ case NMSG_GET_TARGET_INFO:
+ LOGI("GET_TARGET_INFO case\n");
+ if (!parse_target_info(msg->payload, &answer, &answer_len)) {
+ // TODO: report error
+ sendACKToHost(ID,ERR_WRONG_MESSAGE_FORMAT,
+ answer,answer_len);
+ return 1;
+ }
+ // TODO: apply_prof_session()
+ sendACKToHost(ID,ERR_NO,answer,answer_len);
+ break;
+
+ default:
+ LOGE("unknown message %d <0x%08X>\n",ID,ID);
+ }
+
+ //
+ // TODO free memory in profsession_data after use
+ //
+
+ //free allocated memory
+ if (!answer)
+ free(answer);
+ return 0;
+}
+
+static void dispose_payload(struct msg_t *msg)
+{
+ free(msg->payload);
+}
+
+
+// use sequence:
+/* receive_msg_header */
+/* receive_msg_payload */
+/* handle_msg */
+/* dispose_payload */
+
+// testing
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+static void print_app_info( struct app_info_t *app_info)
+{
+ LOGI("application info=\n");
+ LOGI("\tapp_type=<%d><0x%04X>\n"
+ "\tapp_id=<%s>\n"
+ "\texe_path=<%s>\n",
+ app_info->app_type,
+ app_info->app_type,
+ app_info->app_id,
+ app_info->exe_path
+ );
+}
+
+static void print_conf(struct conf_t * conf)
+{
+ char buf[1024];
+ memset(&buf[0],0,1024);
+ feature_code_str(conf->use_features,buf);
+ LOGI("conf = \n");
+ LOGI("\tuse_features = 0x%016LX (%s)\n",
+ conf->use_features,buf);
+ LOGI(
+ "\tsystem_trace_period = %d ms\n"
+ "\tdata message period = %d ms\n",
+ conf->system_trace_period,
+ conf->data_message_period
+ );
+}
+
+static void print_us_func_inst(struct us_func_inst_t * func_inst, int count,char * tab)
+{
+ LOGI("%s#%02d "
+ "func_addr = <%Lu>/<0x%08LX>\t"
+ "args_num = %d\t"
+ "args = <%s>\n",
+ tab,count,
+ func_inst->func_addr,func_inst->func_addr,
+ func_inst->args_num,
+ func_inst->args
+ );
+}
+
+static void print_us_lib_inst(struct us_lib_inst_t * lib_inst,int num,char * tab)
+{
+ uint32_t i = 0;
+
+// LOGI("lib_inst = %08x\n",lib_inst);
+// LOGI("lib_inst->us_func_inst_lis = %08x\n",lib_inst->us_func_inst_list);
+
+ LOGI("%s#%02d path = <%s>\n"
+ "%s\tfunc_count = %d\n",
+ tab,num,
+ lib_inst->bin_path,
+ tab,lib_inst->func_num
+ );
+
+ for ( i = 0; i < lib_inst->func_num; i++) {
+ print_us_func_inst(&(lib_inst->us_func_inst_list[i]),i+1,"\t\t\t\t\t\t");
+ }
+
+}
+
+static void print_user_space_app_inst(struct app_inst_t * app_inst, int num, char * tab)
+{
+ uint32_t i = 0;
+
+ LOGI("%s#%02d app_inst : \n"
+ "%s\tapp_type = 0x%04X\n"
+ "%s\tapp_id=<%s>\n"
+ "%s\texec_path=<%s>\n",
+ tab,num,
+ tab,app_inst->app_type,
+ tab,app_inst->app_id,
+ tab,app_inst->exec_path
+ );
+ LOGI("\t%sfunc_num = %d\n", tab, app_inst->func_num);
+ for ( i = 0; i < app_inst->func_num; i++) {
+ print_us_func_inst(&app_inst->us_func_inst_list[i],i+1,"\t\t\t\t");
+ }
+
+ LOGI("\t%slib_num = %d\n", tab, app_inst->lib_num);
+ for ( i = 0; i < app_inst->lib_num; i++) {
+ print_us_lib_inst(&app_inst->us_lib_inst_list[i],i+1,"\t\t\t\t");
+ }
+
+
+}
+
+static void print_user_space_inst(struct user_space_inst_t * user_space_inst)
+{
+ uint32_t i = 0;
+ LOGI("user_space_inst = \n"
+ "\tapp_num = %d\n",
+ user_space_inst->app_num
+ );
+ for ( i = 0; i < user_space_inst->app_num; i ++){
+ print_user_space_app_inst(&(user_space_inst->app_inst_list[i]),i+1,"\t\t");
+ }
+}
+
+static void print_log_interval(log_interval_t log_interval)
+{
+ printf("log_interval = %x\n", log_interval);
+}
+
+static void print_probe(struct probe_t *probe)
+{
+ printf("probe:\n");
+ printf("addr = %lx\n", probe->addr);
+ printf("arg_num = %d\n", probe->arg_num);
+ int i;
+ for (i = 0; i < probe->arg_num; i++) {
+ printf("%c", probe->arg_fmt[i]);
+ }
+ printf("\n");
+}
+
+static void print_us_inst(struct us_inst_t *us_inst)
+{
+ printf("us inst:\n");
+ printf("path = %s\n", us_inst->path);
+ printf("probe num = %d\n", us_inst->probe_num);
+ int i;
+ for (i = 0; i < us_inst->probe_num; i++) {
+ print_probe(&us_inst->probes[i]);
+ }
+}
+
+static void print_replay_event( struct replay_event_seq_t *event_seq)
+{
+ uint32_t i = 0;
+ struct replay_event_t *ev;
+ char *tab="\t";
+
+ LOGI( "%senabled=0x%08X; "\
+ "time_start=0x%08X %08X; "\
+ "count=0x%08X\n",
+ tab,event_seq->enabled,
+ event_seq->tv.tv_sec,event_seq->tv.tv_usec,
+ event_seq->event_num);
+ for (i=0;i<event_seq->event_num;i++)
+ {
+ ev=&event_seq->events[i];
+ LOGI("%s\t#%04d:time=0x%08X %08X, "
+ " id=0x%08X,"
+ " type=0x%08X,"
+ " code=0x%08X,"
+ " value=0x%08X\n",
+ tab,i+1,
+ ev->ev.time.tv_sec,//timeval
+ ev->ev.time.tv_usec,//timeval
+ ev->id,
+ ev->ev.type,//u16
+ ev->ev.code,//u16
+ ev->ev.value//s32
+ );
+ }
+
+}
+
+static void print_prof_session(struct prof_session_t *prof_session)
+{
+ printf("prof session\n");
+ print_app_info(&prof_session->app_info);
+ print_conf(&prof_session->conf);
+ print_user_space_inst(&prof_session->user_space_inst);
+ print_replay_event(&prof_session->replay_event_seq);
+
+// print_log_interval(prof_session->log_interval);
+// print_app_inst(&prof_session->app_inst);
+}
+
+
--- /dev/null
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+#include <linux/input.h>
+
+enum HostMessageT {
+NMSG_KEEP_ALIVE =0x0001,
+NMSG_START =0x0002,
+NMSG_STOP =0x0003,
+NMSG_CONFIG =0x0004,
+NMSG_BINARY_INFO =0x0005,
+NMSG_SWAP_INST =0x0006,
+NMSG_GET_TARGET_INFO =0x0007,
+NMSG_SWAP_INST_ADD =0x0008,
+NMSG_SWAP_INST_REMOVE =0x0009,
+
+NMSG_KEEP_ALIVE_ACK =0x1001,
+NMSG_START_ACK =0x1002,
+NMSG_STOP_ACK =0x1003,
+NMSG_CONFIG_ACK =0x1004,
+NMSG_BINARY_INFO_ACK =0x1005,
+NMSG_SWAP_INST_ACK =0x1006,
+NMSG_GET_TARGET_INFO_ACK =0x1007,
+NMSG_SWAP_INST_ADD_ACK =0x1008,
+NMSG_SWAP_INST_REMOVE_ACK =0x1009,
+
+NMSG_PROCESS_INFO =0x2002, // target process info
+NMSG_TERMINATE =0x2004, //terminate
+NMSG_ERROR =0x2005, //error message
+NMSG_SAMPLE =0x2006, //N 10ms
+NMSG_SYSTEM =0x2007, //N 10~1000ms DaData, start sending immediately after start message from host, first system message time is tracing start time
+NMSG_IMAGE =0x2008, //N irregular image
+NMSG_RECORD =0x2009, //N irregular replay event
+NMSG_FUNCTION_ENTRY =0x2010, //N irregular swap instrumentation, Instrumented functions by AppInst and LibInst
+NMSG_FUNCTION_EXIT =0x2011, //N irregular swap instrumentation, Instrumented functions by AppInst and LibInst
+NMSG_CONTEXT_SWITCH_ENTRY =0x2012, //N irregular swap instrumentation for kernel
+NMSG_CONTEXT_SWITCH_EXIT =0x2013, //N irregular swap instrumentation for kernel
+
+NMSG_PROBE =0x3100, //N irregular resource log
+NMSG_PROBE_MEMORY =0X3001, //N irregular resource log
+NMSG_PROBE_UICONTROL =0X3002, //N irregular resource log
+NMSG_PROBE_UIEVENT =0X3003, //N irregular resource log
+NMSG_PROBE_RESOURCE =0X3004, //N irregular resource log
+NMSG_PROBE_LIFECYCLE =0X3005, //N irregular resource log
+NMSG_PROBE_SCREENSHOT =0X3006, //N irregular resource log
+NMSG_PROBE_SCENE =0X3007, //N irregular resource log
+NMSG_PROBE_THREAD =0X3008, //N irregular resource log
+NMSG_PROBE_CUSTOM =0X3009, //N irregular resource log
+NMSG_PROBE_SYNC =0X3010 //N irregular resource log
+
+
+};
+#define MSG_MAX_NUM NMSG_SWAP_INST_REMOVE
+
+#define NMSG_ACK_FLAG 0x1000
+enum ErrorCode{
+ ERR_NO =0, //success
+ ERR_LOCKFILE_CREATE_FAILED =-101, //lock file create failed
+ ERR_ALREADY_RUNNING =-102, //already running
+ ERR_INITIALIZE_SYSTEM_INFO_FAILED =-103, //initialize system info failed
+ ERR_HOST_SERVER_SOCKET_CREATE_FAILED =-104, //host server socket create failed
+ ERR_TARGET_SERVER_SOCKET_CREATE_FAILED =-105, //target server socket create failed
+
+ ERR_SIGNAL_MASK_SETTING_FAILED =-106, //TODO del (old parametr)
+
+ ERR_WRONG_MESSAGE_FORMAT =-201, //wrong message format
+ ERR_WRONG_MESSAGE_TYPE =-202, //wrong message type
+ ERR_WRONG_MESSAGE_DATA =-203, //wrong message data
+ ERR_CANNOT_START_PROFILING =-204, //cannot start profiling
+ ERR_SERV_SOCK_CREATE =-900, //server socket creation failed (written in /tmp/da.port file)
+ ERR_SERV_SOCK_BIND =-901, //server socket bind failed (written in /tmp/da.port file)
+ ERR_SERV_SOCK_LISTEN =-902, //server socket listen failed (written in /tmp/da.port file)
+ ERR_UNCKNOWN =-999 //unknown error
+};
+
+enum feature_code{
+ FL_CPU =0x0001, //CPU core load, frequency, process load
+ FL_MEMORY =0x0002, //Process size(VSS, PSS. RSS), heap usage(application, library), physical memory in use
+ FL_FUNCTION_PROFILING =0x0004, //On/Off the UserSpaceInst
+ FL_MEMORY_ALLCATION_PROBING =0x0008, //memory allocation API (glibc)
+ FL_FILE_API_PROBING =0x0010, //file API (glibc, OSP)
+ FL_THREAD_API_PROBING =0x0020, //thread API (glibc, OSP)
+ FL_OSP_UI_API_PROBING =0x0040, //UI API (OSP)
+ FL_SCREENSHOT =0x0080, //Screenshot
+ FL_USER_EVENT =0x0100, //events of Touch, Gesture, Orientation, Key
+ FL_RECORDING =0x0200, //recording the user event
+ FL_SYSTCALL_FILE =0x0400, //File operation syscalls tracing
+ FL_SYSTCALL_IPC =0x0800, //IPC syscall tracing
+ FL_SYSTCALL_PROCESS =0x1000, //Process syscalls tracing
+ FL_SYSTCALL_SIGNAL =0x2000, //Signal syscalls tracing
+ FL_SYSTCALL_NETWORK =0x4000, //Network syscalls tracing
+ FL_SYSTCALL_DESC =0x8000, //Descriptor syscalls tracing
+ FL_CONTEXT_SWITCH =0x10000,//Context switch tracing
+ FL_NETWORK_API_PROBING =0x20000,//network API (glibc, OSP, libsoap, openssl)
+ FL_OPENGL_API_PROBING =0x40000 //openGL API
+};
+#define MAX_FILENAME 128
+
+struct msg_data_t {
+ uint32_t id;
+ uint32_t sequence;
+ struct timeval time;
+ uint32_t len;
+ char *payload;
+};
+
+struct msg_t {
+ uint32_t id;
+ uint32_t len;
+ char *payload;
+};
+
+struct app_info_t {
+ uint32_t app_type;
+ char *app_id;//[MAX_FILENAME];
+ char *exe_path;//[MAX_FILENAME];
+};
+
+//typedef uint32_t conf_t;
+struct conf_t {
+ uint64_t use_features;
+ uint32_t system_trace_period;
+ uint32_t data_message_period;
+};
+
+typedef uint32_t log_interval_t;
+
+struct probe_t {
+ uint64_t addr;
+ uint32_t arg_num;
+ char *arg_fmt;
+};
+
+
+struct us_inst_t {
+ char * path;
+ uint32_t probe_num;
+ struct probe_t *probes;
+};
+
+struct us_func_inst_t {
+ uint64_t func_addr;
+ uint32_t args_num;
+ char * args;
+};
+
+struct us_lib_inst_t {
+ char * bin_path;
+ uint32_t func_num;
+ struct us_func_inst_t *us_func_inst_list;
+};
+
+struct app_inst_t {
+ uint32_t app_type;
+ char * app_id;
+ char * exec_path;
+ uint32_t func_num;
+ struct us_func_inst_t *us_func_inst_list;
+ uint32_t lib_num;
+ struct us_lib_inst_t *us_lib_inst_list;
+};
+
+struct user_space_inst_t {
+ uint32_t app_num;
+ struct app_inst_t * app_inst_list;
+};
+
+struct replay_event_t {
+ uint32_t id;
+ struct input_event ev;
+};
+
+struct replay_event_seq_t {
+ uint32_t enabled;
+ struct timeval tv;
+ uint32_t event_num;
+ struct replay_event_t *events;
+};
+
+struct prof_session_t {
+ struct app_info_t app_info;
+ struct conf_t conf;
+// log_interval_t log_interval;
+// struct app_inst_t app_inst;
+ struct user_space_inst_t user_space_inst;
+ struct replay_event_seq_t replay_event_seq;
+};
+
+
+//int hostMessageHandle(struct msg_t *msg);
+int parseHostMessage(struct msg_t *log, char* msg);
+
+//static void dispose_payload(struct msg_t *msg);
+
+
+char* msg_ID_str ( enum HostMessageT ID);
+//static char* msgErrStr (enum ErrorCode err);
+// use sequence:
+/* receive_msg_header */
+/* receive_msg_payload */
+/* handle_msg */
+/* dispose_payload */
+
+// testing
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+/*
+static void print_app_info(struct app_info_t *app_info);
+static void print_conf(struct conf_t *conf);
+static void print_log_interval(log_interval_t log_interval);
+static void print_probe(struct probe_t *probe);
+static void print_us_inst(struct us_inst_t *us_inst);
+static void print_app_inst(struct app_inst_t *app_inst);
+static void print_prof_session(struct prof_session_t *prof_session);
+*/
+
+
+//data protocol
+struct thread_info_t{
+ uint32_t id;
+ float load;
+};
+
+struct process_info_t{
+ uint32_t id;
+ float load;
+};
+
+struct msg_system_t{
+ uint32_t energy;
+ uint32_t WiFi_status;
+ uint32_t BT_status;
+ uint32_t GPS_status;
+ uint32_t brightness_status;
+ uint32_t camera_status;
+ uint32_t sound_status;
+ uint32_t audio_status;
+ uint32_t vibration_status;
+ uint32_t voltage_status;
+ uint32_t RSSI_status;
+ uint32_t video_status;
+ uint32_t call_status;
+ uint32_t DNet_status;
+
+
+ uint32_t CPU_count;
+ float *CPU_frequency;
+
+ uint32_t app_CPU_usage;
+
+ float *CPU_load;
+
+ uint32_t virtual_memory;
+ uint32_t resident_memory;
+ uint32_t shared_memory;
+ uint32_t PSS_memory;
+ uint32_t total_alloc_size;
+ uint32_t system_memory_total;
+ uint32_t system_memory_used;
+ uint32_t total_used_drive;
+
+ uint32_t count_of_threads;
+ struct thread_info_t *thread_load;
+
+ uint32_t count_of_processes;
+ struct process_info_t *process_load;
+
+ uint32_t DISK_read_size;
+ uint32_t DISK_write_size;
+ uint32_t network_send_size;
+ uint32_t network_receive_size;
+
+};
+
+struct recorded_event_t{
+ uint32_t id;
+ uint32_t type;
+ uint32_t code;
+ uint32_t value;
+};
+#define pack_int(to,n) { *(typeof(n) *) to = n; to += sizeof(typeof(n));}
+#define pack_int64(to,n) { *(uint64_t *) to = n; to += sizeof(uint64_t);}
+#define pack_int32(to,n) { *(uint32_t *) to = n; to += sizeof(uint32_t);}
+#define pack_time(to,n) {pack_int32(to,n.tv_sec); pack_int32(to,n.tv_usec);}
+//#define pack_float(to,n) { *(float *) to = n; to += sizeof(float);}
+//#define pack_float(to,n) pack_int32(to,n)
+#define pack_float(to,n) { memcpy(to,&n,sizeof(float)); to += sizeof(float);}
+#define pack_str(to,n) { memcpy(to,n,strlen(n)+1); to += strlen(n)+1;}
+/*
+static char *pack_int32(char *to, uint32_t val)
+{
+ *(uint32_t *)to = val;
+ return to + sizeof(uint32_t);
+}
+
+static char *pack_int64(char *to, uint64_t val)
+{
+ *(uint64_t *)to = val;
+ return to + sizeof(uint64_t);
+}
+
+static char *pack_string(char *to, const char *str)
+{
+ size_t len = strlen(str) + 1;
+ strncpy(to, str, len);
+ return to + len;
+}
+
+static char *pack_timestamp(char *to)
+{
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ to = pack_int32(to, tv.tv_sec);
+ to = pack_int32(to, tv.tv_usec * 1000);
+
+ return to;
+}
+
+*/
+
+
+//event file descriptor
+int event_fd;
#include <sys/epoll.h> // for epoll apis
#include <sys/timerfd.h> // for timerfd
#include <unistd.h> // for access, sleep
+#ifndef HOST_BUILD
#include <attr/xattr.h> // for fsetxattr
+#endif
#include <linux/input.h>
#include <dirent.h>
#include <fcntl.h>
+#ifndef HOST_BUILD
#include <sys/smack.h>
-
+#endif
#include "daemon.h"
#include "sys_stat.h"
#include "utils.h"
-
+#include "da_protocol.h"
#define DA_WORK_DIR "/home/developer/sdk_tools/da/"
#define DA_READELF_PATH "/home/developer/sdk_tools/da/readelf"
#define SCREENSHOT_DIR "/tmp/da"
if(input_id == get_input_id(d->d_name))
{
sprintf(dev[count].fileName, "/dev/input/%s", d->d_name);
- dev[count].fd = open(dev[count].fileName, O_RDWR);
+ dev[count].fd = open(dev[count].fileName, O_RDWR | O_NONBLOCK);
count++;
}
}
// send functions to host
// ======================================================================================
+int pseudoSendDataToHost(struct msg_data_t* log)
+{
+ uint32_t total_len =
+ sizeof(log->id) +
+ sizeof(log->sequence) +
+ sizeof(uint64_t) + //time
+ sizeof(log->len);
+
+ char *buf = malloc(total_len+log->len);
+ char *p = buf;
+ memset(p,0,total_len);
+
+ pack_int(p,log->id);
+ pack_int(p,log->sequence);
+ pack_time(p,log->time);
+ pack_int(p,log->len);
+
+ memcpy(p,log->payload,log->len);
+ printBuf(buf,total_len+log->len);
+ if (event_fd >0){
+ write(event_fd, buf, total_len+log->len);
+ }
+ free(buf);
+
+ return 0;
+}
+
int sendDataToHost(msg_t* log)
{
if (manager.host.data_socket != -1)
return 1;
}
+
+
static int sendACKCodeToHost(enum HostMessageType resp, int msgcode)
{
+ // FIXME:
+ //disabled string protocol
+ return 0;
if (manager.host.control_socket != -1)
{
char codestr[16];
// remove previous screen capture files
remove_indir(SCREENSHOT_DIR);
mkdir(SCREENSHOT_DIR, 0777);
+#ifndef HOST_BUILD
smack_lsetlabel(SCREENSHOT_DIR, "*", SMACK_LABEL_ACCESS);
-
+#endif
manager.config_flag = launchflag;
#ifdef RUN_APP_LOADER
return 0;
}
-// return 0 for normal case
-// return negative value for error case
-static int parseHostMessage(msg_t* log, char* msg)
-{
- int i;
- int bfind = 0;
- int ret = 0; // parsing success
-
- if(log == NULL || msg == NULL)
- return -1;
-
- // Host message looks like this
- // MSG_TYPE|MSG_LENGTH|MSG_STRING
- // MSG_TYPE is always 3 digits number
- if(msg[3] == '|')
- {
- msg[3] = '\0';
- log->type = atoi(msg);
-
- msg = msg + 4;
- for(i = 0; msg[i] != '\0'; i++)
- {
- if(msg[i] == '|')
- {
- bfind = 1;
- msg[i] = '\0';
- break;
- }
- }
- log->length = atoi(msg);
-
- if(log->length == 0)
- {
- log->data[0] = '\0';
- }
- else
- {
- if(bfind != 0)
- {
- int msglen;
- msg = msg + i + 1;
- msglen = strlen(msg);
-
- if(msglen == log->length)
- {
- strcpy(log->data, msg);
- log->data[log->length] = '\0';
- }
-// else if(msglen > log->length)
-// {
-// strncpy(log->data, msg, log->length);
-// log->data[log->length] = '\0';
-// }
- else
- {
- ret = -1; // parsing error
- }
- }
- else
- {
- ret = -1; // parsing error
- }
- }
- }
- else
- {
- ret = -1; // parsing error
- }
-
- return ret;
-}
-
// return 0 if normal case
// return plus value if non critical error occur
// return minus value if critical error occur
-static int hostMessageHandler(int efd, msg_t* log)
+static int _hostMessageHandler(int efd,struct msg_t* log)
{
int ret = 0;
+ /*
long flag = 0;
char *barloc, *tmploc;
char execPath[PATH_MAX];
ret = 1;
break;
}
-
+*/
return ret;
}
return ret;
}
+#define MAX_EVENTS_NUM 10
+static int deviceEventHandlerNew(input_dev* dev, int input_type)
+{
+ int ret = 0;
+ ssize_t size = 0;
+ int count = 0;
+ struct input_event in_ev[MAX_EVENTS_NUM];
+ struct msg_data_t log;
+
+ if(input_type == INPUT_ID_TOUCH || input_type == INPUT_ID_KEY)
+ {
+ do {
+// LOGI(">read %s events\n,", input_type==INPUT_ID_KEY?STR_KEY:STR_TOUCH);
+ size = read(dev->fd, &in_ev[count], sizeof(*in_ev) );
+// LOGI("<read %s events : size = %d\n,", input_type==INPUT_ID_KEY?STR_KEY:STR_TOUCH,size);
+ if (size >0)
+ count++;
+ } while (count < MAX_EVENTS_NUM && size > 0);
+
+ if(count != 0){
+ LOGI("readed %d %s events\n,", count, input_type==INPUT_ID_KEY?STR_KEY:STR_TOUCH);
+ gen_message_event(&log,&in_ev[0],count,input_type);
+ pseudoSendDataToHost(&log);
+ reset_data_msg(&log);
+ }
+ }
+ else
+ {
+ LOGW("unknown input_type\n");
+ ret = 1;
+ }
+/*
+ if(input_type == INPUT_ID_TOUCH || input_type == INPUT_ID_KEY)
+ {
+
+ if (size = read(dev->fd, &in_ev, sizeof(in_ev) ) !=0 )
+ {
+ LOGI("readed %d touch events\n,", 1);
+ gen_message_event(&log,&in_ev,1,input_type);
+ pseudoSendDataToHost(&log);
+ }
+ }
+ else
+ {
+ LOGW("unknown input_type\n");
+ ret = 1;
+ }
+*/
+ return ret;
+}
+
// return 0 if normal case
// return plus value if non critical error occur
// return minus value if critical error occur
tempPath[0] = '\0';
get_app_install_path(tempPath, PATH_MAX);
+
+#ifndef HOST_BUILD
get_device_info(tempBuff, DA_MSG_MAX);
+#endif
+
log.type = MSG_DEVICE;
if (strlen(tempPath) > 0)
{
}
}
+
+//TODO del it or move to debug section
+void printBuf (char * buf, int len)
+{
+ int i,j;
+ char local_buf[3*16 + 2*16 + 1];
+ char * p1, * p2;
+ LOGI("BUFFER:\n");
+ for ( i = 0; i < len/16 + 1; i++)
+ {
+ memset(local_buf, ' ', 5*16);
+ p1 = local_buf;
+ p2 = local_buf + 3*17;
+ for ( j = 0; j < 16; j++)
+ if (i*16+j < len )
+ {
+ sprintf(p1, "%02X ",(unsigned char) *buf);
+ p1+=3;
+ if (isprint( *buf)){
+ sprintf(p2, "%c ",(int)*buf);
+ }else{
+ sprintf(p2,". ");
+ }
+ p2+=2;
+ buf++;
+ }
+ *p1 = ' ';
+ *p2 = '\0';
+ LOGI("%s\n",local_buf);
+ }
+}
+
// return 0 if normal case
// return plus value if non critical error occur
// return minus value if critical error occur
// return -11 if socket closed
+
static int controlSocketHandler(int efd)
{
ssize_t recvLen;
if (recvLen > 0)
{
recvBuf[recvLen] = '\0';
+ printBuf(recvBuf,recvLen);
LOGI("host sent control msg str(%s)\n", recvBuf);
-
if(parseHostMessage(&log, recvBuf) < 0)
{
// error to parse host message
}
// host msg command handling
- return hostMessageHandler(efd, &log);
+ return hostMessageHandle(&log);
}
else // close request from HOST
{
if(g_touch_dev[k].fd >= 0 &&
events[i].data.fd == g_touch_dev[k].fd)
{
- if(deviceEventHandler(&g_touch_dev[k], INPUT_ID_TOUCH) < 0)
+ if(deviceEventHandlerNew(&g_touch_dev[k], INPUT_ID_TOUCH) < 0)
{
terminate_error("Internal DA framework error, Please re-run the profiling.", 1);
ret = -1;
if(g_key_dev[k].fd >= 0 &&
events[i].data.fd == g_key_dev[k].fd)
{
- if(deviceEventHandler(&g_key_dev[k], INPUT_ID_KEY) < 0)
+ if(deviceEventHandlerNew(&g_key_dev[k], INPUT_ID_KEY) < 0)
{
terminate_error("Internal DA framework error, Please re-run the profiling.", 1);
ret = -1;
*
*/
-#include <stdint.h> // for uint64_t, int64_t
-#include <pthread.h> // for pthread_mutex_t
#ifndef _DAEMON_H_
#define _DAEMON_H_
+#include <stdint.h> // for uint64_t, int64_t
+#include <pthread.h> // for pthread_mutex_t
+
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_TARGET_COUNT 8
#define DA_MSG_MAX 4096
#define RECV_BUF_MAX 4104 // = sizeof(msg_t)
-
+/*
enum ErrorCode
{
ERR_LOCKFILE_CREATE_FAILED = -101,
ERR_WRONG_MESSAGE_DATA = -203,
ERR_CANNOT_START_PROFILING = -204,
ERR_WRONG_PROTOCOL_VERSION = -205
-};
+};*/
enum TargetMessageType
{
#include <signal.h> // for signal
#include <unistd.h> // for unlink
#include <fcntl.h> // for open, fcntl
+#ifndef HOST_BUILD
#include <attr/xattr.h> // for fsetxattr
-
+#endif
#include "daemon.h"
+#include "da_protocol.h"
#include "sys_stat.h"
#define SINGLETON_LOCKFILE "/tmp/lockfile.da"
#define INIT_PORT 8001
#define LIMIT_PORT 8100
+
// initialize global variable
__da_manager manager =
{
sigset_t newsigmask;
atexit(_close_server_socket);
-
+#ifndef HOST_BUILD
if(initialize_system_info() < 0)
{
writeToPortfile(ERR_INITIALIZE_SYSTEM_INFO_FAILED);
return -1;
}
+#endif
// make server socket
if(makeTargetServerSocket() != 0)
static int finalizeManager()
{
+#ifndef HOST_BUILD
finalize_system_info();
-
+#endif
LOGI("Finalize daemon\n");
// close host client socket
int result;
initialize_log();
+ LOGE("da_started\n");
atexit(_unlink_file);
manager.portfile = fopen(PORTFILE, "w");
if(result == 0)
{
//daemon work
+ //FIX ME remove samplingThread it is only for debug
+ //samplingThread(NULL);
daemonLoop();
finalizeManager();
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
+#include <errno.h>
#ifndef LOCALTEST
+#ifndef HOST_BUILD
#include <system_info.h>
#include <runtime_info.h>
#include <telephony_network.h>
#include <call.h>
#endif
+#endif
+
+#include "da_protocol.h"
+#include "da_data.h"
+struct msg_system_t msg_system;
#define USE_VCONF
#ifdef USE_VCONF
+#ifndef HOST_BUILD
#include "vconf.h"
#endif
+#endif
#include "sys_stat.h"
#include "daemon.h"
// return 0 for error case
// return system total memory in MB
-static unsigned long get_system_total_memory()
+//static
+unsigned long get_system_total_memory()
{
int meminfo_fd = -1;
char *head, *tail;
return 0;
}
+//CMD SOCKET FUNCTIONS
+int fill_target_info(struct target_info_t *target_info)
+{
+ //get sys_mem_size
+ target_info->sys_mem_size = get_system_total_memory();
+// target_info->sys_mem_size=1;
+
+
+ target_info->storage_size = 2;//get_fsinfo("/", int type)
+ target_info->bluetooth_supp = get_bt_status();
+ target_info->gps_supp = get_gps_status();
+ target_info->wifi_supp = get_wifi_status();
+ target_info->camera_count = get_camera_status();
+ target_info->network_type = 7;
+ target_info->max_brightness = get_max_brightness();
+ target_info->CPU_core_count = sysconf(_SC_NPROCESSORS_CONF);
+ return 0;
+}
+
+//DATA SOCKET FUNCTIONS
+float freq[4] = {1.1, 2.2, 3.3, 4.4};
+struct thread_info_t th_load[1] = {{0x111, 10.6}};
+struct process_info_t pr_load[1] = {{0x222, 20.7}};
+int fill_message_system(struct msg_system_t * sys)
+{
+
+// struct msg_system_t * psys = sys;
+
+ memset(sys,0,sizeof(*sys)); //del for speed up
+/*
+ psys->energy = 0;
+ psys->WiFi_status = get_wifi_status();
+ psys->BT_status = get_bt_status();
+ psys->GPS_status = get_gps_status();
+ psys->brightness_status = get_brightness_status();
+ psys->camera_status = get_camera_status();
+ psys->sound_status = get_sound_status();
+ psys->audio_status = get_audio_status();
+ psys->vibration_status = get_vibration_status();
+ psys->voltage_status = get_voltage_status();
+ psys->RSSI_status = get_rssi_status();
+ psys->video_status = get_video_status();
+ psys->call_status = get_call_status();
+ psys->DNet_status = get_dnet_status();
+// psys->CPU_frequency = get_cpu_frequency(), freqbuf in get_resource_info()
+// psys->app_CPU_usage = app_cpu_usage in get_resource_info()
+// psys->CPU_load cpuload in get_resource_info()
+// psys->virtual_memory = virtual in get_resource_info()
+// psys->resident_memory = resident in get_resource_info()
+// psys->shared_memory = shared in get_resource_info()
+// psys->PSS_memory = pss in get_resource_info()
+// psys->total_alloc_size = get_total_alloc_size();
+// psys->system_memory_total = get_system_total_memory(), sysmemtotal in get_resource_info();
+// psys->system_memory_used = update_system_memory_data(), sysmemused in get_resource_info();
+ psys->total_used_drive = get_total_used_drive();
+// psys->count_of_threads = thread in get_resource_info()
+// psys->thread_load = thread_load in get_resource_info()
+// psys->count_of_processes = procNode* proc in get_resource_info() but no count
+/*/
+ sys->energy = 1;
+ sys->WiFi_status = 2;
+ sys->BT_status = 3;
+ sys->GPS_status = 4;
+ sys->brightness_status = 5;
+ sys->camera_status = 6;
+ sys->sound_status = 7;
+ sys->audio_status = 8;
+ sys->vibration_status = 9;
+ sys->voltage_status = 0xa;
+ sys->RSSI_status = 0xb;
+ sys->video_status = 0xc;
+ sys->call_status = 0xd;
+ sys->DNet_status = 0xe;
+
+ sys->CPU_count = 4; //FIXME HARDCODE CPU count
+ sys->CPU_frequency = freq;
+
+ sys->app_CPU_usage = 10.0;
+ sys->CPU_load = freq;
+
+ sys->virtual_memory = 0x12;
+ sys->resident_memory = 0x13;
+ sys->shared_memory = 0x14;
+ sys->PSS_memory = 0x15;
+ sys->total_alloc_size = 0x16;
+ sys->system_memory_total = 0x17;
+ sys->system_memory_used = 0x18;
+ sys->total_used_drive = 0x19;
+
+ sys->count_of_threads = 0x1;
+ sys->thread_load = th_load;
+
+ sys->count_of_processes = 0x1;
+ sys->process_load = pr_load;
+
+ sys->DISK_read_size = 0x20;
+ sys->DISK_write_size = 0x21;
+ sys->network_send_size = 0x22;
+ sys->network_receive_size = 0x23;
+
+
+//*/
+ return 0;
+};
+
+//uint32_t get_resource_info_new(char** buf, int buffer_len, int* pidarray, int pidcount)
+uint32_t gen_message_sytem_info(struct msg_data_t *msg, int buffer_len, int* pidarray, int pidcount)
+{
+ char *p = 0;
+ uint32_t len,total_len = 0;
+ int i = 0;
+ struct msg_system_t sys;
+
+ fill_message_system(&sys);
+
+ total_len =
+ sizeof(sys)
+ - sizeof(sys.thread_load)
+ - sizeof(sys.process_load) +
+ 2*sys.CPU_count*sizeof(float) + //CPU
+ sys.count_of_threads * sizeof(*(sys.thread_load)) + //treads
+ sys.count_of_processes * sizeof(*(sys.process_load)) //process
+ ;
+ msg->payload = malloc(total_len);
+ memset(msg->payload,0,total_len);
+ p = msg->payload;
+
+ pack_int(p,sys.energy);
+ pack_int(p,sys.WiFi_status);
+ pack_int(p,sys.BT_status);
+ pack_int(p,sys.GPS_status);
+ pack_int(p,sys.brightness_status);
+ pack_int(p,sys.camera_status);
+ pack_int(p,sys.sound_status);
+ pack_int(p,sys.audio_status);
+ pack_int(p,sys.vibration_status);
+ pack_int(p,sys.voltage_status);
+ pack_int(p,sys.RSSI_status);
+ pack_int(p,sys.video_status);
+ pack_int(p,sys.call_status);
+ pack_int(p,sys.DNet_status);
+
+ //CPU
+ for (i=0; i<sys.CPU_count; i++)
+ pack_float(p,sys.CPU_frequency[i]); //FIXME wrong pack float define
+
+ pack_int(p,sys.app_CPU_usage);
+
+ for (i=0; i<sys.CPU_count; i++)
+ pack_float(p,sys.CPU_load[i]); //FIXME wrong pack float define
+
+ pack_int(p,sys.app_CPU_usage);
+ pack_int(p,sys.CPU_load);
+ pack_int(p,sys.virtual_memory);
+ pack_int(p,sys.resident_memory);
+ pack_int(p,sys.shared_memory);
+ pack_int(p,sys.PSS_memory);
+ pack_int(p,sys.total_alloc_size);
+ pack_int(p,sys.system_memory_total);
+ pack_int(p,sys.system_memory_used);
+ pack_int(p,sys.total_used_drive);
+
+ //thread
+ pack_int(p,sys.count_of_threads);
+ for (i=0; i<sys.count_of_threads; i++)
+ {
+ pack_int(p,sys.thread_load[i].id); //FIXME wrong pack float define
+ pack_float(p,sys.thread_load[i].load); //FIXME wrong pack float define
+ }
+
+ //process
+ pack_int(p,sys.count_of_processes)
+ for (i=0; i<sys.count_of_processes; i++)
+ {
+ pack_int(p,sys.process_load[i].id); //FIXME wrong pack float define
+ pack_float(p,sys.process_load[i].load); //FIXME wrong pack float define
+ }
+
+
+ pack_int(p,sys.DISK_read_size);
+ pack_int(p,sys.DISK_write_size);
+ pack_int(p,sys.network_send_size);
+ pack_int(p,sys.network_receive_size);
+
+ total_len = p - msg->payload;
+ fill_data_msg_head(msg,NMSG_SYSTEM,0,total_len);
+
+ return total_len;
+
+}
+
+
#define MAXNAMESIZE 16
+#include <stdint.h>
+
typedef unsigned long long tic_t;
typedef struct {
unsigned long* slot; // memory value slot
} mem_t;
+struct target_info_t {
+ uint32_t sys_mem_size;
+ uint32_t storage_size;
+ uint32_t bluetooth_supp;
+ uint32_t gps_supp;
+ uint32_t wifi_supp;
+ uint32_t camera_count;
+ uint32_t network_type;
+ uint32_t max_brightness;
+ uint32_t CPU_core_count;
+};
+
int get_device_info(char* buffer, int buffer_len);
int get_resource_info(char* buffer, int buffer_len, int* pidarray, int pidcount);
int finalize_system_info();
+int fill_target_info(struct target_info_t *target_info);
+
#ifdef __cplusplus
}
#endif
#include "utils.h"
#include "sys_stat.h"
+#include "da_protocol.h"
+#include "da_data.h"
+
#define TIMER_INTERVAL_SEC 1
#define TIMER_INTERVAL_USEC 0
return 0;
}
-static void* samplingThread(void* data)
+//static
+void* samplingThread(void* data)
{
- int err, signo, i, res;
- int pidarray[MAX_TARGET_COUNT];
+ int err, signo, i;
+ uint32_t res;
+ int pidarr[MAX_TARGET_COUNT];
int pidcount;
sigset_t waitsigmask;
- msg_t log;
+ struct msg_data_t log;
LOGI("sampling thread started\n");
for(i = 0; i < MAX_TARGET_COUNT; i++)
{
if(manager.target[i].socket != -1 && manager.target[i].pid != -1)
- pidarray[pidcount++] = manager.target[i].pid;
+ pidarr[pidcount++] = manager.target[i].pid;
}
- res = get_resource_info(log.data, DA_MSG_MAX, pidarray, pidcount);
- if(res >= 0)
+//#ifndef HOST_BUILD
+ //res = get_resource_info_new(&log.payload, DA_MSG_MAX, pidarr, pidcount);
+ res = gen_message_sytem_info(&log, DA_MSG_MAX, pidarr, pidcount);
+ if(res > 0)
{
- log.type = MSG_RESOURCE;
- log.length = res;
- sendDataToHost(&log);
+ LOGI("payload_len=%d\n",log.len);
+ LOGI("sizeof(float) = %d\n", sizeof(float));
+ //sendDataToHost(&log);
+ pseudoSendDataToHost(&log);
}
+ break;
+//#endif
}
else if(signo == SIGUSR1)
{
#include <sys/stat.h> // for open
#include <fcntl.h> // for open
#include <grp.h> // for setgroups
+#ifndef HOST_BUILD
#include <sys/smack.h>
-
+#endif
#include "daemon.h"
#include "utils.h"
#define APP_GROUPS_MAX 100
#define APP_GROUP_LIST "/usr/share/privilege-control/app_group_list"
#define SELF_LABEL_FILE "/proc/self/attr/current"
+#ifndef HOST_BUILD
#define SMACK_LABEL_LEN 255
+#endif
#define SID_APP 5000
#define MANIFEST_PATH "/info/manifest.xml"
return -1; // no space
}
+#ifndef HOST_BUILD
int smack_set_label_for_self(const char *label)
{
int len;
return (ret < 0) ? -1 : 0;
}
+#endif
void set_appuser_groups(void)
{
close(fd);
}
+#ifndef HOST_BUILD
int get_smack_label(const char* execpath, char* buffer, int buflen)
{
char* appid = NULL;
else
return -1;
}
+#endif
int get_appid(const char* execpath, char* buffer, int buflen)
{
int isHwAcc = 0;
char manifest[PATH_MAX];
char command[PATH_MAX];
+#ifndef HOST_BUILDl
char appid[SMACK_LABEL_LEN];
-
+#endif
if (exec_path == NULL || strlen(exec_path) <= 0)
{
LOGE("Executable path is not correct\n");
}
}
+#ifndef HOST_BUILDl
if(get_smack_label(exec_path, appid, SMACK_LABEL_LEN - 1) < 0)
{
LOGE("failed to get smack label\n");
return 0;
}
else
+#endif
{
+#ifndef HOST_BUILD
LOGI("smack lable is %s\n", appid);
if(smack_set_label_for_self(appid) < 0)
{
LOGE("failed to set label for self\n");
}
-
+#endif
set_appuser_groups();
if(setgid(SID_APP) < 0)
{