/* <copyright> This file is provided under a dual BSD/GPLv2 license. When using or redistributing this file, you may do so under either license.
GPL LICENSE SUMMARY
Copyright (c) 2005-2014 Intel Corporation. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. The full GNU General Public License is included in this distribution in the file called LICENSE.GPL.
Copyright (c) 2005-2014 Intel Corporation. All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</copyright> */
/* this define used to control initialization function name. */ #ifndef __itt_init_ittlib_name
ITT_EXTERN_C int _N_(init_ittlib)(constchar*, __itt_group_id); static __itt_init_ittlib_t* __itt_init_ittlib_ptr = _N_(init_ittlib); #define __itt_init_ittlib_name __itt_init_ittlib_ptr #endif/* __itt_init_ittlib_name */
typedefvoid (__itt_fini_ittlib_t)(void);
/* this define used to control finalization function name. */ #ifndef __itt_fini_ittlib_name
ITT_EXTERN_C void _N_(fini_ittlib)(void); static __itt_fini_ittlib_t* __itt_fini_ittlib_ptr = _N_(fini_ittlib); #define __itt_fini_ittlib_name __itt_fini_ittlib_ptr #endif/* __itt_fini_ittlib_name */
/* building pointers to imported funcs */ #undef ITT_STUBV #undef ITT_STUB #define ITT_STUB(api,type,name,args,params,ptr,group,format) \ static type api ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)) args;\ typedef type api ITT_JOIN(_N_(name),_t) args; \
ITT_EXTERN_C_BEGIN ITT_JOIN(_N_(name),_t)* ITTNOTIFY_NAME(name) = ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)); ITT_EXTERN_C_END \ static type api ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)) args \
{ \
__itt_init_ittlib_name(NULL, __itt_group_all); \ if (ITTNOTIFY_NAME(name) && ITTNOTIFY_NAME(name) != ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init))) \ return ITTNOTIFY_NAME(name) params; \ else \ return (type)0; \
}
#define ITT_STUBV(api,type,name,args,params,ptr,group,format) \ static type api ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)) args;\ typedef type api ITT_JOIN(_N_(name),_t) args; \
ITT_EXTERN_C_BEGIN ITT_JOIN(_N_(name),_t)* ITTNOTIFY_NAME(name) = ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)); ITT_EXTERN_C_END \ static type api ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)) args \
{ \
__itt_init_ittlib_name(NULL, __itt_group_all); \ if (ITTNOTIFY_NAME(name) && ITTNOTIFY_NAME(name) != ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init))) \
ITTNOTIFY_NAME(name) params; \ else \ return; \
}
#undef ITT_STUB #undef ITT_STUBV #define ITT_STUB(api,type,name,args,params,ptr,group,format) \ static type api ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)) args;\ typedef type api ITT_JOIN(_N_(name),_t) args; \
ITT_EXTERN_C_BEGIN ITT_JOIN(_N_(name),_t)* ITTNOTIFY_NAME(name) = ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)); ITT_EXTERN_C_END
#define ITT_STUBV(api,type,name,args,params,ptr,group,format) \ static type api ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)) args;\ typedef type api ITT_JOIN(_N_(name),_t) args; \
ITT_EXTERN_C_BEGIN ITT_JOIN(_N_(name),_t)* ITTNOTIFY_NAME(name) = ITT_VERSIONIZE(ITT_JOIN(_N_(name),_init)); ITT_EXTERN_C_END
staticvoid ITTAPI ITT_VERSIONIZE(ITT_JOIN(_N_(enable_attach),_init))(void)
{ #ifdef __ANDROID__ /* * if LIB_VAR_NAME env variable were set before then stay previous value * else set default path
*/
setenv(ITT_TO_STR(LIB_VAR_NAME), ANDROID_ITTNOTIFY_DEFAULT_PATH, 0); #endif
}
staticconstchar* __itt_fsplit(constchar* s, constchar* sep, constchar** out, int* len)
{ int i; int j;
if (!s || !sep || !out || !len) return NULL;
for (i = 0; s[i]; i++)
{ int b = 0; for (j = 0; sep[j]; j++) if (s[i] == sep[j])
{
b = 1; break;
} if (!b) break;
}
if (!s[i]) return NULL;
*len = 0;
*out = &s[i];
for (; s[i]; i++, (*len)++)
{ int b = 0; for (j = 0; sep[j]; j++) if (s[i] == sep[j])
{
b = 1; break;
} if (b) break;
}
for (; s[i]; i++)
{ int b = 0; for (j = 0; sep[j]; j++) if (s[i] == sep[j])
{
b = 1; break;
} if (!b) break;
}
return &s[i];
}
/* This function return value of env variable that placed into static buffer. * !!! The same static buffer is used for subsequent calls. !!! * This was done to aviod dynamic allocation for few calls. * Actually we need this function only four times.
*/ staticconstchar* __itt_get_env_var(constchar* name)
{ #define MAX_ENV_VALUE_SIZE 4086 staticchar env_buff[MAX_ENV_VALUE_SIZE]; staticchar* env_value = (char*)env_buff;
if (name != NULL)
{ #if ITT_PLATFORM==ITT_PLATFORM_WIN
size_t max_len = MAX_ENV_VALUE_SIZE - (size_t)(env_value - env_buff);
DWORD rc = GetEnvironmentVariableA(name, env_value, (DWORD)max_len); if (rc >= max_len)
__itt_report_error(__itt_error_env_too_long, name, (size_t)rc - 1, (size_t)(max_len - 1)); elseif (rc > 0)
{ constchar* ret = (constchar*)env_value;
env_value += rc + 1; return ret;
} else
{ /* If environment variable is empty, GetEnvirornmentVariables() * returns zero (number of characters (not including terminating null),
* and GetLastError() returns ERROR_SUCCESS. */
DWORD err = GetLastError(); if (err == ERROR_SUCCESS) return env_value;
ITT_ANDROID_LOGI("Unable to open system-wide marker file.");
res = snprintf(cmdline_path, PATH_MAX - 1, "/proc/%d/cmdline", my_pid); if (res < 0)
{
ITT_ANDROID_LOGE("Unable to get cmdline path string."); return lib_name;
}
ITT_ANDROID_LOGI("CMD file: %s\n", cmdline_path);
cmdline_fd = open(cmdline_path, O_RDONLY); if (cmdline_fd == -1)
{
ITT_ANDROID_LOGE("Unable to open %s file!", cmdline_path); return lib_name;
}
res = read(cmdline_fd, package_name, PATH_MAX - 1); if (res == -1)
{
ITT_ANDROID_LOGE("Unable to read %s file!", cmdline_path);
res = close(cmdline_fd); if (res == -1)
{
ITT_ANDROID_LOGE("Unable to close %s file!", cmdline_path);
} return lib_name;
}
res = close(cmdline_fd); if (res == -1)
{
ITT_ANDROID_LOGE("Unable to close %s file!", cmdline_path); return lib_name;
}
ITT_ANDROID_LOGI("Package name: %s\n", package_name);
res = snprintf(app_sandbox_file, PATH_MAX - 1, "/data/data/%s/%s", package_name, marker_filename); if (res < 0)
{
ITT_ANDROID_LOGE("Unable to concatenate marker file string."); return lib_name;
}
ITT_ANDROID_LOGI("Lib marker file name: %s\n", app_sandbox_file);
itt_marker_file_fd = open(app_sandbox_file, O_RDONLY); if (itt_marker_file_fd == -1)
{
ITT_ANDROID_LOGE("Unable to open app marker file!"); return lib_name;
}
}
{ char itt_lib_name[PATH_MAX] = {0};
res = read(itt_marker_file_fd, itt_lib_name, PATH_MAX - 1); if (res == -1)
{
ITT_ANDROID_LOGE("Unable to read %s file!", itt_marker_file_fd);
res = close(itt_marker_file_fd); if (res == -1)
{
ITT_ANDROID_LOGE("Unable to close %s file!", itt_marker_file_fd);
} return lib_name;
}
ITT_ANDROID_LOGI("ITT Lib path: %s", itt_lib_name);
res = close(itt_marker_file_fd); if (res == -1)
{
ITT_ANDROID_LOGE("Unable to close %s file!", itt_marker_file_fd); return lib_name;
}
ITT_ANDROID_LOGI("Set env %s to %s", ITT_TO_STR(LIB_VAR_NAME), itt_lib_name);
res = setenv(ITT_TO_STR(LIB_VAR_NAME), itt_lib_name, 0); if (res == -1)
{
ITT_ANDROID_LOGE("Unable to set env var!"); return lib_name;
}
lib_name = __itt_get_env_var(ITT_TO_STR(LIB_VAR_NAME));
ITT_ANDROID_LOGI("ITT Lib path from env: %s", lib_name);
}
} #endif
return lib_name;
}
/* Avoid clashes with std::min, reported by tbb team */ #define __itt_min(a,b) (a) < (b) ? (a) : (b)
if (group_str != NULL)
{ int len; char gr[255]; constchar* chunk; while ((group_str = __itt_fsplit(group_str, ",; ", &chunk, &len)) != NULL)
{ int min_len = __itt_min(len, (int)(sizeof(gr) - 1));
__itt_fstrcpyn(gr, sizeof(gr) - 1, chunk, min_len);
gr[min_len] = 0;
for (i = 0; group_list[i].name != NULL; i++)
{ if (!__itt_fstrcmp(gr, group_list[i].name))
{
res = (__itt_group_id)(res | group_list[i].id); break;
}
}
} /* TODO: !!! Workaround for bug with warning for unknown group !!! * Should be fixed in new initialization scheme.
* Now the following groups should be set always. */ for (i = 0; group_list[i].id != __itt_group_none; i++) if (group_list[i].id != __itt_group_all &&
group_list[i].id > __itt_group_splitter_min &&
group_list[i].id < __itt_group_splitter_max)
res = (__itt_group_id)(res | group_list[i].id); return res;
} else
{ for (i = 0; group_alias[i].env_var != NULL; i++) if (__itt_get_env_var(group_alias[i].env_var) != NULL) return group_alias[i].groups;
}
return res;
}
#undef __itt_min
staticint __itt_lib_version(lib_t lib)
{ if (lib == NULL) return 0; if (__itt_get_proc(lib, "__itt_api_init")) return 2; if (__itt_get_proc(lib, "__itt_api_version")) return 1; return 0;
}
/* It's not used right now! Comment it out to avoid warnings. static void __itt_reinit_all_pointers(void) { register int i; // Fill all pointers with initial stubs for (i = 0; _N_(_ittapi_global).api_list_ptr[i].name != NULL; i++) *_N_(_ittapi_global).api_list_ptr[i].func_ptr = _N_(_ittapi_global).api_list_ptr[i].init_func; }
*/
staticvoid __itt_nullify_all_pointers(void)
{ registerint i; /* Nulify all pointers except domain_create, string_handle_create and counter_create */ for (i = 0; _N_(_ittapi_global).api_list_ptr[i].name != NULL; i++)
*_N_(_ittapi_global).api_list_ptr[i].func_ptr = _N_(_ittapi_global).api_list_ptr[i].null_func;
}
#if ITT_PLATFORM==ITT_PLATFORM_WIN #pragma warning(push) #pragma warning(disable: 4054) /* warning C4054: 'type cast' : from function pointer 'XXX' to data pointer 'void *' */ #pragma warning(disable: 4055) /* warning C4055: 'type cast' : from data pointer 'void *' to function pointer 'XXX' */ #endif/* ITT_PLATFORM==ITT_PLATFORM_WIN */
#ifndef ITT_SIMPLE_INIT if (PTHREAD_SYMBOLS) __itt_mutex_unlock(&_N_(_ittapi_global).mutex); #endif/* ITT_SIMPLE_INIT */
}
/* Evaluating if any function ptr is non empty and it's in init_groups */ for (i = 0; _N_(_ittapi_global).api_list_ptr[i].name != NULL; i++)
{ if (*_N_(_ittapi_global).api_list_ptr[i].func_ptr != _N_(_ittapi_global).api_list_ptr[i].null_func &&
_N_(_ittapi_global).api_list_ptr[i].group & init_groups)
{ return 1;
}
} return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.