3 * Copyright 2012 Samsung Electronics S.LSI Co. LTD
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * @file Exynos_OSAL_ETC.c
21 * @author SeungBeom Kim (sbcrux.kim@samsung.com)
32 #include "Exynos_OSAL_Memory.h"
33 #include "Exynos_OSAL_ETC.h"
34 #include "Exynos_OSAL_Log.h"
36 static struct timeval perfStart[PERF_ID_MAX+1], perfStop[PERF_ID_MAX+1];
37 static unsigned long perfTime[PERF_ID_MAX+1], totalPerfTime[PERF_ID_MAX+1];
38 static unsigned int perfFrameCount[PERF_ID_MAX+1], perfOver30ms[PERF_ID_MAX+1];
41 ssize_t getline(char **ppLine, size_t *pLen, FILE *pStream)
43 char *pCurrentPointer = NULL;
44 size_t const chunk = 512;
46 size_t defaultBufferSize = chunk + 1;
49 if (*ppLine == NULL) {
50 *ppLine = (char *)malloc(defaultBufferSize);
51 if (*ppLine == NULL) {
55 *pLen = defaultBufferSize;
58 if (*pLen < defaultBufferSize) {
59 *ppLine = (char *)realloc(*ppLine, defaultBufferSize);
60 if (*ppLine == NULL) {
64 *pLen = defaultBufferSize;
73 pCurrentPointer = *ppLine + readByte;
75 i = fread(pCurrentPointer, 1, chunk, pStream);
76 if (i < chunk && ferror(pStream)) {
82 if (*pCurrentPointer++ == (char)'\n') {
83 *pCurrentPointer = '\0';
85 if (fseek(pStream, j - i, SEEK_CUR)) {
110 i = ((readByte + (chunk * 2)) / chunk) * chunk;
112 *ppLine = (char *)realloc(*ppLine, i);
113 if (*ppLine == NULL) {
124 #endif /* HAVE_GETLINE */
126 OMX_PTR Exynos_OSAL_Strcpy(OMX_PTR dest, OMX_PTR src)
128 return strcpy(dest, src);
131 OMX_PTR Exynos_OSAL_Strncpy(OMX_PTR dest, OMX_PTR src, size_t num)
133 return strncpy(dest, src, num);
136 OMX_S32 Exynos_OSAL_Strcmp(OMX_PTR str1, OMX_PTR str2)
138 return strcmp(str1, str2);
141 OMX_S32 Exynos_OSAL_Strncmp(OMX_PTR str1, OMX_PTR str2, size_t num)
143 return strncmp(str1, str2, num);
146 OMX_PTR Exynos_OSAL_Strcat(OMX_PTR dest, OMX_PTR src)
148 return strcat(dest, src);
151 OMX_PTR Exynos_OSAL_Strncat(OMX_PTR dest, OMX_PTR src, size_t num)
153 return strncat(dest, src, num);
156 size_t Exynos_OSAL_Strlen(const char *str)
161 static OMX_U32 MeasureTime(struct timeval *start, struct timeval *stop)
163 unsigned long sec, usec, time;
165 sec = stop->tv_sec - start->tv_sec;
166 if (stop->tv_usec >= start->tv_usec) {
167 usec = stop->tv_usec - start->tv_usec;
169 usec = stop->tv_usec + 1000000 - start->tv_usec;
173 time = sec * 1000000 + (usec);
178 void Exynos_OSAL_PerfInit(PERF_ID_TYPE id)
180 memset(&perfStart[id], 0, sizeof(perfStart[id]));
181 memset(&perfStop[id], 0, sizeof(perfStop[id]));
183 totalPerfTime[id] = 0;
184 perfFrameCount[id] = 0;
185 perfOver30ms[id] = 0;
188 void Exynos_OSAL_PerfStart(PERF_ID_TYPE id)
190 gettimeofday(&perfStart[id], NULL);
193 void Exynos_OSAL_PerfStop(PERF_ID_TYPE id)
195 gettimeofday(&perfStop[id], NULL);
197 perfTime[id] = MeasureTime(&perfStart[id], &perfStop[id]);
198 totalPerfTime[id] += perfTime[id];
199 perfFrameCount[id]++;
201 if (perfTime[id] > 30000)
205 OMX_U32 Exynos_OSAL_PerfFrame(PERF_ID_TYPE id)
210 OMX_U32 Exynos_OSAL_PerfTotal(PERF_ID_TYPE id)
212 return totalPerfTime[id];
215 OMX_U32 Exynos_OSAL_PerfFrameCount(PERF_ID_TYPE id)
217 return perfFrameCount[id];
220 int Exynos_OSAL_PerfOver30ms(PERF_ID_TYPE id)
222 return perfOver30ms[id];
225 void Exynos_OSAL_PerfPrint(OMX_STRING prefix, PERF_ID_TYPE id)
230 frameCount = Exynos_OSAL_PerfFrameCount(id);
231 perfTotal = Exynos_OSAL_PerfTotal(id);
233 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "%s Frame Count: %d", prefix, frameCount);
234 Exynos_OSAL_Log(EXYNOS_LOG_INFO, "%s Avg Time: %.2f ms, Over 30ms: %d",
235 prefix, (float)perfTotal / (float)(frameCount * 1000),
236 Exynos_OSAL_PerfOver30ms(id));