Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 182b051a authored by Philippe SWARTVAGHER's avatar Philippe SWARTVAGHER
Browse files

Merge branch 'otf2' into 'master'

Improve the OTF2 parser

See merge request !109
parents 5903ff8e bae9f279
No related branches found
No related tags found
1 merge request!109Improve the OTF2 parser
Pipeline #1030528 passed
......@@ -13,6 +13,9 @@
###
set -ex
# To be removed when OTF2 will be "correctly" installed in the Docker image
PATH=$PATH:$OTF2_DIR/bin
#
# Build the project
#
......
#
# Find the OTF2 libraries and include dir
# Find the OTF2 library
#
# OTF2_INCLUDE_DIR - Directories to include to use OTF2
# OTF2_LIBRARY - Files to link against to use OTF2
# OTF2_FOUND - When false, don't try to use OTF2
#
# OTF2_DIR can be used to make it simpler to find the various include
# directories and compiled libraries when OTF2 was not installed in the
# usual/well-known directories (e.g. because you made an in tree-source
# compilation or because you installed it in an "unusual" directory).
# Just set OTF2_DIR it to your specific installation directory
#
FIND_LIBRARY(OTF2_LIBRARY otf2
PATHS
/usr/lib
/usr/local/lib
${OTF2_DIR}/lib
)
# OTF2_LIBRARY_PATH - Files to link against to use OTF2
# OTF2_CONFIG - Path to otf2-config
find_program(OTF2_CONFIG otf2-config REQUIRED)
find_program(OTF2_PRINT otf2-print REQUIRED)
IF(NOT OTF2_CONFIG OR NOT EXISTS ${OTF2_CONFIG})
MESSAGE(STATUS "Cannot find otf2-config")
SET(OTF2_VERSION ${OTF2_REQUIRED_VERSION})
ELSE()
message(STATUS "OTF2 installation found. (using ${OTF2_CONFIG})")
IF(OTF2_LIBRARY)
GET_FILENAME_COMPONENT(OTF2_GUESSED_INCLUDE_DIR_tmp "${OTF2_LIBRARY}" PATH)
STRING(REGEX REPLACE "lib$" "include" OTF2_GUESSED_INCLUDE_DIR "${OTF2_GUESSED_INCLUDE_DIR_tmp}")
ENDIF(OTF2_LIBRARY)
FIND_PATH( OTF2_INCLUDE_DIR otf2/otf2.h
PATHS
${OTF2_GUESSED_INCLUDE_DIR}
${OTF2_DIR}/include
/usr/include
/usr/local/include
${CMAKE_SOURCE_DIR}/externals/otf2/include/
execute_process(COMMAND ${OTF2_CONFIG} "--cppflags" OUTPUT_VARIABLE OTF2_INCLUDE_DIR)
STRING(REPLACE "\n" "" OTF2_INCLUDE_DIR ${OTF2_INCLUDE_DIR})
STRING(REPLACE "-I" "" OTF2_INCLUDE_DIR ${OTF2_INCLUDE_DIR})
execute_process(COMMAND ${OTF2_CONFIG} "--ldflags" OUTPUT_VARIABLE _LINK_LD_ARGS)
STRING( REPLACE " " ";" _LINK_LD_ARGS ${_LINK_LD_ARGS} )
FOREACH( _ARG ${_LINK_LD_ARGS} )
IF(${_ARG} MATCHES "^-L")
STRING(REGEX REPLACE "^-L" "" _ARG ${_ARG})
STRING(STRIP "${_ARG}" _ARG)
SET(OTF2_LINK_DIRS ${OTF2_LINK_DIRS} ${_ARG})
ENDIF(${_ARG} MATCHES "^-L")
ENDFOREACH(_ARG)
execute_process(COMMAND ${OTF2_CONFIG} "--libs" OUTPUT_VARIABLE _LINK_LD_ARGS)
STRING( REPLACE " " ";" _LINK_LD_ARGS ${_LINK_LD_ARGS} )
FOREACH( _ARG ${_LINK_LD_ARGS} )
IF(${_ARG} MATCHES "^-l")
STRING(REGEX REPLACE "^-l" "" _ARG "${_ARG}")
STRING(STRIP "${_ARG}" _ARG)
FIND_LIBRARY(_OTF2_LIB_FROM_ARG NAMES ${_ARG}
HINTS ${OTF2_LINK_DIRS} NO_DEFAULT_PATH
)
IF(${_ARG} STREQUAL "otf2" OR ${_ARG} STREQUAL "open-trace-format2")
SET(OTF2_LIBRARY ${_OTF2_LIB_FROM_ARG})
ELSE()
IF(_OTF2_LIB_FROM_ARG)
LIST(APPEND OTF2_LIBRARIES ${_OTF2_LIB_FROM_ARG})
ENDIF(_OTF2_LIB_FROM_ARG)
ENDIF()
UNSET(_OTF2_LIB_FROM_ARG CACHE)
ENDIF(${_ARG} MATCHES "^-l")
ENDFOREACH(_ARG)
execute_process(COMMAND ${OTF2_CONFIG} "--version" OUTPUT_VARIABLE OTF2_VERSION)
STRING( REPLACE "otf2-config: version " "" OTF2_VERSION ${OTF2_VERSION} )
STRING( REPLACE "\n" "" OTF2_VERSION ${OTF2_VERSION} )
STRING( REPLACE "." ";" _VERSION ${OTF2_VERSION} )
LIST( GET _VERSION 0 OTF2_MAJOR_VERSION)
LIST( GET _VERSION 1 OTF2_MINOR_VERSION)
ENDIF()
include (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OTF2
FOUND_VAR OTF2_FOUND
REQUIRED_VARS OTF2_CONFIG OTF2_LIBRARY OTF2_INCLUDE_DIR
VERSION_VAR OTF2_VERSION
)
IF( OTF2_INCLUDE_DIR )
IF( OTF2_LIBRARY )
SET( OTF2_FOUND "YES" )
MARK_AS_ADVANCED( OTF2_DIR )
MARK_AS_ADVANCED( OTF2_INCLUDE_DIR )
MARK_AS_ADVANCED( OTF2_LIBRARY )
ENDIF( OTF2_LIBRARY )
ENDIF( OTF2_INCLUDE_DIR )
IF( NOT OTF2_FOUND )
MESSAGE("OTF2 installation was not found. Please provide OTF2_DIR:")
MESSAGE(" - through the GUI when working with ccmake, ")
MESSAGE(" - as a command line argument when working with cmake e.g. ")
MESSAGE(" cmake .. -DOTF2_DIR:PATH=/usr/local/otf ")
MESSAGE("Note: the following message is triggered by cmake on the first ")
MESSAGE(" undefined necessary PATH variable (e.g. OTF2_INCLUDE_DIR).")
MESSAGE(" Providing OTF2_DIR (as above described) is probably the")
MESSAGE(" simplest solution unless you have a really customized/odd")
MESSAGE(" OTF2 installation...")
SET(OTF2_DIR "" CACHE PATH "Root of OTF2 install tree." )
ENDIF( NOT OTF2_FOUND )
if(NOT OTF2_FOUND)
unset(OTF2_CONFIG)
unset(OTF2_CONFIG CACHE)
unset(OTF2_LINK_DIRS)
unset(OTF2_LIBRARIES)
endif()
mark_as_advanced(OTF2_LIBRARY)
......@@ -413,10 +413,6 @@ include_directories(
${QTCOLORPICKERDIR}
)
if(VITE_ENABLE_OTF2)
link_directories(${OTF2_LIBRARY_DIR})
endif()
#resource
if(WIN32)
set(VITE_RES
......
......@@ -232,9 +232,12 @@ OTF2_CallbackCode ParserDefinitionOTF2::handler_DefLocation(void *userData,
uint64_t numberOfEvents,
OTF2_LocationGroupRef locationGroup) {
OTF2_Reader *reader = (OTF2_Reader *)userData;
OTF2_Reader_SelectLocation(reader, locationIdentifier);
OTF2_EvtReader *evt_reader = OTF2_Reader_GetEvtReader(reader, locationIdentifier);
OTF2_DefReader *def_reader = OTF2_Reader_GetDefReader(reader, locationIdentifier);
uint64_t definitions_read = 0;
OTF2_Reader_ReadAllLocalDefinitions(reader, def_reader, &definitions_read);
OTF2_Location *temp = new OTF2_Location();
......@@ -537,6 +540,11 @@ Color *ParserDefinitionOTF2::get_color(uint32_t func_id) {
return new Color(*_default_colors[func_id % NB_COLORS]);
}
Color *ParserDefinitionOTF2::get_color(String function_name) {
uint32_t func_id = std::hash<std::string> {}(function_name.to_string());
return get_color(func_id);
}
//
// Other public functions
//
......
......@@ -454,6 +454,7 @@ public:
static double get_timestamp(OTF2_TimeStamp ts);
static Color *get_color(uint32_t func_id);
static Color *get_color(String function_name);
static const char *get_string_by_id(uint32_t id);
};
......
......@@ -178,19 +178,12 @@ OTF2_CallbackCode ParserEventOTF2::callback_ProgramEnd(OTF2_LocationRef location
return OTF2_CALLBACK_SUCCESS;
}
//
// Start definition of handlers for OTF2 event records
//
OTF2_CallbackCode ParserEventOTF2::callback_Enter(OTF2_LocationRef locationID,
OTF2_TimeStamp time,
void *userData,
OTF2_AttributeList * /*attributes*/,
OTF2_RegionRef regionID) {
ENTER_CALLBACK(time, locationID);
Trace *t = (Trace *)userData;
static OTF2_CallbackCode pushState(OTF2_LocationRef locationID,
OTF2_TimeStamp time,
Trace *t,
String function_name) {
Date d = ParserDefinitionOTF2::get_timestamp(time);
OTF2_Function temp_function = ParserDefinitionOTF2::get_function_by_id(regionID);
const String function_name = String(ParserDefinitionOTF2::get_string_by_id(temp_function._name_id));
map<string, Value *> extra_fields;
// get the container
......@@ -199,7 +192,7 @@ OTF2_CallbackCode ParserEventOTF2::callback_Enter(OTF2_LocationRef locationID,
Container *temp_container = temp_location->container;
#if defined(OTF2_DEBUG)
cout << d.to_string() << " Enter_print(location=" << proc_name.to_string() << ", region=" << regionID << ", fname=" << function_name.to_string() << ")\n";
cout << d.to_string() << " Enter_print(location=" << proc_name.to_string() << ", fname=" << function_name.to_string() << ")\n";
#endif // defined(OTF2_DEBUG)
// get the state type
......@@ -219,7 +212,7 @@ OTF2_CallbackCode ParserEventOTF2::callback_Enter(OTF2_LocationRef locationID,
if (temp_value == NULL) {
map<string, Value *> opt;
Name entity_name(function_name);
opt["Color"] = ParserDefinitionOTF2::get_color(regionID);
opt["Color"] = ParserDefinitionOTF2::get_color(function_name);
t->define_entity_value(entity_name, temp_state_type, opt);
temp_value = t->search_entity_value(function_name, temp_state_type);
}
......@@ -230,6 +223,53 @@ OTF2_CallbackCode ParserEventOTF2::callback_Enter(OTF2_LocationRef locationID,
return OTF2_CALLBACK_SUCCESS;
}
static OTF2_CallbackCode popState(OTF2_LocationRef locationID,
OTF2_TimeStamp time,
Trace *t,
String function_name) {
Date d = ParserDefinitionOTF2::get_timestamp(time);
map<string, Value *> extra_fields;
// get the container
OTF2_Location *temp_location = ParserDefinitionOTF2::get_location_by_id(locationID);
const String proc_name = String(ParserDefinitionOTF2::get_string_id(temp_location));
Container *temp_container = temp_location->container;
#if defined(OTF2_DEBUG)
cout << d.to_string() << " Leave_print(location=" << proc_name.to_string() << ", fname=" << function_name.to_string() << ")\n";
#endif // defined(OTF2_DEBUG)
// get the state type
String state_type_string("Function");
StateType *temp_state_type = t->search_state_type(state_type_string);
if (temp_state_type == 0) {
Name name_temp(state_type_string);
ContainerType cont_type = *temp_container->get_type();
t->define_state_type(name_temp, &cont_type, extra_fields);
temp_state_type = t->search_state_type(state_type_string);
assert(temp_state_type != 0);
}
t->pop_state(d, temp_state_type, temp_container, extra_fields);
return OTF2_CALLBACK_SUCCESS;
}
//
// Start definition of handlers for OTF2 event records
//
OTF2_CallbackCode ParserEventOTF2::callback_Enter(OTF2_LocationRef locationID,
OTF2_TimeStamp time,
void *userData,
OTF2_AttributeList * /*attributes*/,
OTF2_RegionRef regionID) {
ENTER_CALLBACK(time, locationID);
Trace *t = (Trace *)userData;
OTF2_Function temp_function = ParserDefinitionOTF2::get_function_by_id(regionID);
const String function_name = String(ParserDefinitionOTF2::get_string_by_id(temp_function._name_id));
return pushState(locationID, time, t, function_name);
}
OTF2_CallbackCode ParserEventOTF2::callback_Leave(OTF2_LocationRef locationID,
OTF2_TimeStamp time,
void *userData,
......@@ -1025,14 +1065,15 @@ OTF2_CallbackCode ParserEventOTF2::callback_ThreadCreate(OTF2_LocationRef locati
OTF2_CallbackCode ParserEventOTF2::callback_ThreadBegin(OTF2_LocationRef locationID,
OTF2_TimeStamp time,
void * /*userData*/,
void *userData,
OTF2_AttributeList * /*attributeList*/,
OTF2_CommRef /*threadContingent*/,
uint64_t /*sequenceCount*/) {
ENTER_CALLBACK(time, locationID);
// Nothing to do here
return OTF2_CALLBACK_SUCCESS;
Trace *t = (Trace *)userData;
const String function_name("");
return pushState(locationID, time, t, function_name);
}
OTF2_CallbackCode ParserEventOTF2::callback_ThreadWait(OTF2_LocationRef locationID,
......@@ -1048,13 +1089,15 @@ OTF2_CallbackCode ParserEventOTF2::callback_ThreadWait(OTF2_LocationRef location
OTF2_CallbackCode ParserEventOTF2::callback_ThreadEnd(OTF2_LocationRef locationID,
OTF2_TimeStamp time,
void * /*userData*/,
void *userData,
OTF2_AttributeList * /*attributeList*/,
OTF2_CommRef /*threadContingent*/,
uint64_t /*sequenceCount*/) {
ENTER_CALLBACK(time, locationID);
// Nothing to do here
return OTF2_CALLBACK_SUCCESS;
Trace *t = (Trace *)userData;
const String function_name("");
return popState(locationID, time, t, function_name);
}
OTF2_CallbackCode ParserEventOTF2::callback_CallingContextEnter(OTF2_LocationRef locationID,
......
......@@ -75,7 +75,7 @@ void ParserOTF2::parse(Trace &trace,
parserdefinition->create_container_types(&trace);
parserdefinition->initialize_types(&trace);
#if DEBUG
#ifdef DEBUG
parserdefinition->print_definitions();
#endif // DEBUG
......@@ -86,16 +86,15 @@ void ParserOTF2::parse(Trace &trace,
// parserevent->read_markers(reader);
finish();
if (finish_trace_after_parse) { // true by default
trace.finish();
}
delete parserevent;
delete parserdefinition;
OTF2_Reader_Close(reader);
if (finish_trace_after_parse) {
finish();
trace.finish();
}
}
float ParserOTF2::get_percent_loaded() const {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment