Exemplo n.º 1
0
static void EsifDataLogFire(int isHeader)
{
	int i = 0;
	char outLine[MAX_LOG_LINE] = { 0 };
	EsifLogType logtype = ESIF_LOG_UI;
	time_t now = time(NULL);
	struct tm time = { 0 };
	esif_ccb_time_t msec = 0;

	esif_ccb_system_time(&msec);

	if (isHeader > 0) {
		esif_ccb_sprintf(MAX_LOG_LINE, outLine, "Time,Server Msec,");
	}
	else {
		if (esif_ccb_localtime(&time, &now) == 0) {
				esif_ccb_sprintf(MAX_LOG_LINE, outLine, "%04d-%02d-%02d %02d:%02d:%02d,%llu,",
					time.tm_year + 1900, time.tm_mon + 1, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec, msec);
		}
	}
	for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
		eEsifError rc = ESIF_OK;
		DataLogParticipant currentParticipant = g_dataLogParticipants[i];

		if (currentParticipant.participantNumFields > 0) {
			rc = EsifDataLogAddParticipant(outLine, i, isHeader);
		}
	}
	EsifLogFile_Write(logtype, "%s\n", outLine);
}
Exemplo n.º 2
0
/* Allocate Event IPC */
struct esif_ipc *esif_ipc_alloc_event(
	struct esif_ipc_event **event_ptr_ptr,
	u32 data_len
	)
{
	struct esif_ipc *ipc_ptr = NULL;

	ESIF_ASSERT(event_ptr_ptr != NULL);

	ipc_ptr = esif_ipc_alloc(ESIF_IPC_TYPE_EVENT,
		data_len + sizeof(**event_ptr_ptr));

	if (NULL == ipc_ptr) {
		*event_ptr_ptr = NULL;
	} else {
		esif_ccb_time_t timestamp = {0};
		struct esif_ipc_event *event_ptr = NULL;
		event_ptr = (struct esif_ipc_event *)(ipc_ptr + 1);

		event_ptr->version  = ESIF_EVENT_VERSION;
		event_ptr->priority = ESIF_EVENT_PRIORITY_NORMAL;
		event_ptr->data_len = data_len;

		esif_ccb_system_time(&timestamp);
		event_ptr->timestamp = (u64)timestamp;

		*event_ptr_ptr          = event_ptr;
	}
	return ipc_ptr;
}
Exemplo n.º 3
0
static void *ESIF_CALLCONV EsifDataLogWorkerThread(void *ptr)
{
	eEsifError rc = ESIF_OK;

	UNREFERENCED_PARAMETER(ptr);

	ESIF_TRACE_ENTRY_INFO();

	while (!g_dataLogQuit) {
		esif_ccb_time_t msecStart = 0;
		esif_ccb_time_t msecStop = 0;
		esif_ccb_time_t msecDif = 0;
		UInt32 sleepMs = 0;

		esif_ccb_system_time(&msecStart);
		EsifDataLogFire(0);
		esif_ccb_system_time(&msecStop);

		/* Determine how long processing actually took */
		msecDif = msecStop - msecStart;

		/* Determine next sleep time based on previous processing time*/
		sleepMs = g_dataLogInterval - ((int) msecDif);
		if ((sleepMs < MIN_STATUS_LOG_INTERVAL_ADJUSTED) || (msecDif > g_dataLogInterval)){
			sleepMs = MIN_STATUS_LOG_INTERVAL_ADJUSTED;
		}

		rc = EsifTimedEventWait(&g_dataLogQuitEvent, sleepMs);
		if (rc != ESIF_OK) {
			ESIF_TRACE_ERROR("Error waiting on data log event\n");
			goto exit;
		}
	}
exit:
	ESIF_TRACE_EXIT_INFO();
	return 0;
}
Exemplo n.º 4
0
void EsifEvent_SignalIpcEvent(struct esif_ipc_event *eventHdrPtr)
{
#ifdef ESIF_FEAT_OPT_ACTION_SYSFS
	UNREFERENCED_PARAMETER(domainStr);
#else
	eEsifError rc = ESIF_OK;
	EsifData binaryData = {ESIF_DATA_BINARY, NULL, 0, 0};
	EsifData voidData = {ESIF_DATA_VOID, NULL, 0};
	EsifDataPtr dataPtr = NULL;
	UInt8 participantId;
	char domainStr[8] = "";
	esif_ccb_time_t now;

	UNREFERENCED_PARAMETER(domainStr);

	esif_ccb_system_time(&now);

	ESIF_TRACE_DEBUG(
		"\n"
		"===================================================\n"
		"ESIF IPC EVENT HEADER: Timestamp: %llu\n"
		"                         Latency: %u msec\n"
		"===================================================\n"
		"Version:     %d\n"
		"Type:        %s(%d)\n"
		"ID:          %llu\n"
		"Timestamp:   %llu\n"
		"Priority:    %s(%d)\n"
		"Source:      %d\n"
		"Dest:        %d\n"
		"Dest Domain: %s(%04X)\n"
		"Data Size:   %u\n\n",
		(u64)now,
		(int)(now - eventHdrPtr->timestamp),
		eventHdrPtr->version,
		esif_event_type_str(eventHdrPtr->type),
		eventHdrPtr->type,
		eventHdrPtr->id,
		eventHdrPtr->timestamp,
		esif_event_priority_str(eventHdrPtr->priority),
		eventHdrPtr->priority,
		eventHdrPtr->src_id,
		eventHdrPtr->dst_id,
		esif_primitive_domain_str(eventHdrPtr->dst_domain_id, domainStr, 8),
		eventHdrPtr->dst_domain_id,
		eventHdrPtr->data_len);

	dataPtr = &voidData;
	if (eventHdrPtr->data_len > 0) {
		binaryData.buf_ptr = eventHdrPtr + 1;
		binaryData.buf_len = eventHdrPtr->data_len;
		binaryData.data_len = eventHdrPtr->data_len;
		dataPtr = &binaryData;
	}

	/*
	* If the mapping function fails, we assume that the participant hasn't been created
	* In that case, we use 0 for the participant as the real ID will be gathered from
	* the creation data.
	*/
	participantId = eventHdrPtr->dst_id;
	if (eventHdrPtr->dst_id == ESIF_INSTANCE_UF) {
		rc = EsifUpPm_MapLpidToParticipantInstance(eventHdrPtr->src_id, &participantId);
		if (rc != ESIF_OK) {
			participantId = 0;
		}
	}

	// Best Effort Delivery
	EsifEventMgr_SignalEvent(participantId, eventHdrPtr->dst_domain_id, eventHdrPtr->type, dataPtr);

	return;
#endif
}
Exemplo n.º 5
0
TimeSpan EsifTime::getCurrentTime(void)
{
    esif_ccb_time_t currentTimeInMilliSeconds;
    esif_ccb_system_time(&currentTimeInMilliSeconds);
    return TimeSpan::createFromMilliseconds(currentTimeInMilliSeconds);
}
Exemplo n.º 6
0
/* Documented In Header */
struct esif_event *esif_event_allocate(
	const enum esif_event_type type,
	const u16 size,
	const enum esif_event_priority priority,
	const u8 src,
	const u8 dst,
	const u16 dst_domain_id,
	const void *data_ptr
	)
{
	u16 new_size = size + sizeof(struct esif_event);
	struct esif_event *event_ptr = NULL;
	event_ptr = esif_ccb_memtype_zalloc(ESIF_MEMTYPE_TYPE_EVENT, new_size);

	if (event_ptr) {
		event_ptr->version       = ESIF_EVENT_VERSION;
		event_ptr->size          = new_size;
		event_ptr->type          = type;
		event_ptr->priority      = priority;
		event_ptr->src           = src;
		event_ptr->dst           = dst;
		event_ptr->dst_domain_id = dst_domain_id;
		event_ptr->data_size     = size;

		/*
		 *  Assign Function Pointers If Any
		 */
#ifdef ESIF_EVENT_DEBUG
		event_ptr->get_type_str     = esif_event_type_str;
		event_ptr->get_priority_str = esif_event_priority_str;
		event_ptr->dump = esif_dump_event;
#endif

		/*
		** Transaction ID
		*/
		esif_ccb_write_lock(&g_event_lock);
		event_ptr->id = g_event_transaction_id++;
		esif_ccb_write_unlock(&g_event_lock);

		/*
		** Time Stamp
		*/
		esif_ccb_system_time(&event_ptr->timestamp);

		/*
		** Make A Copy Of The Data To Make Sure It Is Contigous
		** In The Buffer
		*/
		if (NULL != data_ptr)
			esif_ccb_memcpy((event_ptr + 1), data_ptr, size);

		ESIF_TRACE_DYN_EVENT("%s: buf %p bytes %d\n",
				     ESIF_FUNC,
				     event_ptr,
				     new_size);
		ESIF_TRACE_DYN_DECODE("Version:     %d\n"
				      "Type:        %s(%d)\n"
				      "ID:          %llu\n"
				      "Timestamp:   %llu\n"
				      "Priority:    %s(%d)\n"
				      "Source:      %d\n"
				      "Destination: %d\n"
				      "Data Size: %d\n",
				      event_ptr->version,
				      esif_event_type_str(event_ptr->type),
				      event_ptr->type,
				      event_ptr->id,
				      (u64)event_ptr->timestamp,
				      esif_event_priority_str(
					event_ptr->priority),
				      event_ptr->priority,
				      event_ptr->src,
				      event_ptr->dst,
				      event_ptr->data_size);
	}
	return event_ptr;
}
Exemplo n.º 7
0
int EsifTraceMessage(
	esif_tracemask_t module, 
	int level, 
	const char *func, 
	const char *file, 
	int line, 
	const char *msg, 
	...)
{
	int rc=0;
	char *appname  = "";
	char *fmtDetail= "%s%s:[<%s>%s@%s#%d]<%llu ms>: ";
	char *fmtInfo  = "%s%s:[<%s>]<%llu ms>: ";
	const char *sep=NULL;
	size_t fmtlen=esif_ccb_strlen(msg, 0x7FFFFFFF);
	int  detailed_message = (level >= DETAILED_TRACELEVEL ? ESIF_TRUE : ESIF_FALSE);
	va_list args;
	esif_ccb_time_t msec = 0;
	enum esif_tracemodule moduleid = ESIF_TRACEMODULE_DEFAULT;
	const char *module_name = NULL;

	esif_ccb_system_time(&msec);

	while (module >>= 1)
		moduleid++;
	module_name = EsifTraceModule_ToString(moduleid);

	level = esif_ccb_min(level, ESIF_TRACELEVEL_MAX);
	level = esif_ccb_max(level, ESIF_TRACELEVEL_FATAL);
	if ((sep = strrchr(file, *ESIF_PATH_SEP)) != NULL)
		file = sep+1;

	// Do not log function/file/line information for DPTF app interface messages logged from EsifSvcWriteLog
	if (moduleid == ESIF_TRACEMODULE_DPTF) {
		detailed_message = ESIF_FALSE;
	}

	if (g_traceinfo[level].routes & ESIF_TRACEROUTE_CONSOLE) {
		if (detailed_message)
			rc =  CMD_CONSOLE(fmtDetail, appname, g_traceinfo[level].label, module_name, func, file, line, msec);
		else
			rc =  CMD_CONSOLE(fmtInfo, appname, g_traceinfo[level].label, module_name, msec);
		va_start(args, msg);
		rc += EsifConsole_WriteConsole(msg, args);
		va_end(args);

		if (fmtlen && msg[fmtlen-1]!='\n')
			CMD_CONSOLE("\n");
	}

	if (g_traceinfo[level].routes & ESIF_TRACEROUTE_LOGFILE && EsifLogFile_IsOpen(ESIF_LOG_TRACE)) {
		time_t now=0;
		char timestamp[MAX_CTIME_LEN]={0};

		time(&now);
		esif_ccb_ctime(timestamp, sizeof(timestamp), &now);
		timestamp[20] = 0; // truncate year

		if (detailed_message)
			rc = EsifLogFile_Write(ESIF_LOG_TRACE, fmtDetail, timestamp + 4, g_traceinfo[level].label, module_name, func, file, line, msec);
		else
			rc =  EsifLogFile_Write(ESIF_LOG_TRACE, fmtInfo, timestamp+4, g_traceinfo[level].label, module_name, msec);
		va_start(args, msg);
		rc += EsifLogFile_WriteArgsAppend(ESIF_LOG_TRACE, "\n", msg, args);
		va_end(args);
	}

#ifdef ESIF_ATTR_OS_WINDOWS
	if (g_traceinfo[level].routes & (ESIF_TRACEROUTE_DEBUGGER)) {
		size_t  msglen=0;
		char *buffer=0;
		int  offset=0;

		va_start(args, msg);
		msglen = esif_ccb_vscprintf(msg, args) + esif_ccb_strlen(g_traceinfo[level].label, MAX_PATH) + esif_ccb_strlen(appname, MAX_PATH) + esif_ccb_strlen(func, MAX_PATH) + esif_ccb_strlen(file, MAX_PATH) + esif_ccb_strlen(module_name, MAX_PATH) + 22;
		va_end(args);
		msglen += (detailed_message ? esif_ccb_strlen(fmtDetail, MAX_PATH) : esif_ccb_strlen(fmtInfo, MAX_PATH));
		buffer = (char *)esif_ccb_malloc(msglen);

		if (NULL != buffer) {
			if (detailed_message)
				rc =  esif_ccb_sprintf(msglen, buffer, fmtDetail, appname, g_traceinfo[level].label, module_name, func, file, line, msec);
			else
				rc =  esif_ccb_sprintf(msglen, buffer, fmtInfo, appname, g_traceinfo[level].label, module_name, msec);

			offset = rc;
			va_start(args, msg);
			rc += esif_ccb_vsprintf(msglen-offset, buffer+offset, msg, args);
			va_end(args);
			if (rc && buffer[rc-1]!='\n')
				esif_ccb_strcat(buffer, "\n", msglen);

			OutputDebugStringA(buffer); 
			esif_ccb_free(buffer);
		}
	}
	if (g_traceinfo[level].routes & (ESIF_TRACEROUTE_EVENTLOG)) {
		size_t  msglen=0;
		char *buffer=0;
		char *replaced=0;
		int  offset=0;
		int  backset=0;
		WORD eventType;

		appname  = "";
		fmtInfo  = "%sESIF(%s) TYPE: %s MODULE: %s TIME %llu ms\n\n";
		fmtDetail= "%sESIF(%s) TYPE: %s MODULE: %s FUNC: %s FILE: %s LINE: %d TIME: %llu ms\n\n";
		backset  = 0;

		va_start(args, msg);
		msglen = esif_ccb_vscprintf(msg,args) + esif_ccb_strlen(g_traceinfo[level].label, MAX_PATH) + esif_ccb_strlen(appname, MAX_PATH) + esif_ccb_strlen(func, MAX_PATH) + esif_ccb_strlen(file, MAX_PATH) + esif_ccb_strlen(module_name, MAX_PATH) + 32;
		va_end(args);
		msglen += (detailed_message ? esif_ccb_strlen(fmtDetail, MAX_PATH) : esif_ccb_strlen(fmtInfo, MAX_PATH));
		buffer = (char *)esif_ccb_malloc(msglen);

		if (NULL != buffer) {
			if (detailed_message)
				rc = esif_ccb_sprintf(msglen, buffer, fmtDetail, appname, ESIF_UF_VERSION, g_traceinfo[level].label, module_name, func, file, line, msec);
			else
				rc = esif_ccb_sprintf(msglen, buffer, fmtInfo, appname, ESIF_UF_VERSION, g_traceinfo[level].label, module_name, msec);

			if (backset && backset < rc)
				buffer[rc-backset-1] = 0;
			offset = rc-backset;
			va_start(args, msg);
			rc += esif_ccb_vsprintf(msglen-(offset+backset), buffer+offset+backset, msg, args);
			va_end(args);
			if (rc && buffer[rc-1]=='\n')
				buffer[--rc] = 0;

			switch (g_traceinfo[level].level) {
			case ESIF_TRACELEVEL_FATAL:
			case ESIF_TRACELEVEL_ERROR:
				eventType = EVENTLOG_ERROR_TYPE;
				break;
			case ESIF_TRACELEVEL_WARN:
				eventType = EVENTLOG_WARNING_TYPE;
				break;
			case ESIF_TRACELEVEL_INFO:
			case ESIF_TRACELEVEL_DEBUG:
			default:
				eventType = EVENTLOG_INFORMATION_TYPE;
				break;
			}
			// Escape any "%" in message before writing to EventLog
			if ((replaced = esif_str_replace(buffer, "%", "%%")) != NULL) {
				esif_ccb_free(buffer);
				buffer = replaced;
				replaced = NULL;
			}
			report_event_to_event_log(CATEGORY_GENERAL, eventType, buffer);
			esif_ccb_free(buffer);
		}
	}
#endif
#ifdef ESIF_ATTR_OS_LINUX
	if (g_traceinfo[level].routes & (ESIF_TRACEROUTE_EVENTLOG|ESIF_TRACEROUTE_DEBUGGER)) {
		size_t  msglen=0;
		char *buffer=0;
		int  offset=0;
		int priority;

		fmtDetail= "%s:[<%s>%s@%s#%d]<%llu ms>: ";
		fmtInfo  = "%s:[<%s>]<%llu ms>: ";

		va_start(args, msg);
		msglen = esif_ccb_vscprintf(msg,args) + esif_ccb_strlen(g_traceinfo[level].label, MAX_PATH) + esif_ccb_strlen(func, MAX_PATH) + esif_ccb_strlen(file, MAX_PATH) + esif_ccb_strlen(module_name, MAX_PATH) + 22;
		va_end(args);
		msglen += (detailed_message ? esif_ccb_strlen(fmtDetail, MAX_PATH) : esif_ccb_strlen(fmtInfo, MAX_PATH));
		buffer = (char *)esif_ccb_malloc(msglen);

		if (NULL != buffer) {
			char *lf;
			if (detailed_message)
				rc =  esif_ccb_sprintf(msglen, buffer, fmtDetail, g_traceinfo[level].label, module_name, func, file, line, msec);
			else
				rc =  esif_ccb_sprintf(msglen, buffer, fmtInfo, g_traceinfo[level].label, module_name, msec);

			offset = rc;
			va_start(args, msg);
			rc += esif_ccb_vsprintf(msglen-offset, buffer+offset, msg, args);
			va_end(args);
			if (rc && buffer[rc-1]=='\n')
				buffer[--rc] = 0;

			while ((lf = esif_ccb_strchr(buffer, '\n')) != NULL)
				*lf = '\t';

			switch (g_traceinfo[level].level) {
			case ESIF_TRACELEVEL_FATAL:
				priority = ESIF_PRIORITY_FATAL;
				break;
			case ESIF_TRACELEVEL_ERROR:
				priority = ESIF_PRIORITY_ERROR;
				break;
			case ESIF_TRACELEVEL_WARN:
				priority = ESIF_PRIORITY_WARNING;
				break;
			case ESIF_TRACELEVEL_INFO:
				priority = ESIF_PRIORITY_INFO;
				break;
			case ESIF_TRACELEVEL_DEBUG:
			default:
				priority = ESIF_PRIORITY_DEBUG;
				break;
			}
		#ifdef ESIF_ATTR_OS_ANDROID
			__android_log_write(priority, IDENT, buffer);
		#else
			openlog(IDENT, OPTION, FACILITY);
			syslog(priority, "%s", buffer);
			closelog();
		#endif
			esif_ccb_free(buffer);
		}
	}
#endif
	return rc;
}