From 144ed6fc69976e825ed81170d7f47ff99af2bd24 Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Thu, 18 Apr 2024 00:54:07 +0200 Subject: [PATCH] - Continue LibLog implementation. --- lib/libshmem.c | 93 ++++++++++++++++++++++++++++---------------------- lib/libshmem.h | 19 +++++++---- util/Makefile | 10 +++--- 3 files changed, 70 insertions(+), 52 deletions(-) diff --git a/lib/libshmem.c b/lib/libshmem.c index e0e6700..c406e77 100644 --- a/lib/libshmem.c +++ b/lib/libshmem.c @@ -377,14 +377,22 @@ SMT_Status SM_Library_Close_I( SMT_Flags Close_Mode) SMT_Status SM_Library_Dump_I( FILE *Out) { /* Affichage des informations sur la base */ - +/* fprintf( Out, "Base: (%d):[%s]\tSize: (%d)\tCreator PId: (%ld)\tLast write access PId: (%ld)\nId Mem: (%d):(%d)\tId Sem: (%d)\tStatus: [%s]\n\n", SM_Instance, SM_Context, SM_Base->Size, SM_Base->Creator, SM_Base->Writer, SM_Base->SysMemId, SM_Base->DataMemId, SM_Base->SemId, SM_Lock_Status_Get( "base", SM_Base)); +*/ + LG_LOG_INFO_5( "Base: (%d):[%s]\tSize: (%d)\tCreator PId: (%ld)\tLast write access PId: (%ld)", + SM_Instance, SM_Context, SM_Base->Size, SM_Base->Creator, SM_Base->Writer); + LG_LOG_INFO_4( "Id Mem: (%d):(%d)\tId Sem: (%d)\tStatus: [%s]", + SM_Base->SysMemId, SM_Base->DataMemId, SM_Base->SemId, SM_Lock_Status_Get( "base", SM_Base)); + LG_LOG_INFO_0( ""); + /* Affichage des informations du MHR */ ND_DataStruct_Info_Print( Out, SM_Base->MHR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0); - fprintf( Out, "\n"); +// fprintf( Out, "\n"); + LG_LOG_INFO_0( ""); /* Affichage des informations de chaque heap */ @@ -961,10 +969,13 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) if( Lock_Mode == Heap->Lock_Mode) { /* Rien à faire : le heap est déjà verrouillé dans ce mode */ - +/* fprintf( stderr, "SM_Heap_Lock: heap [%s] already locked in mode: (%d)!\n", Heap->Name, Lock_Mode); fflush( stderr); - +*/ + LG_LOG_WARNING_2( "heap [%s] already locked in mode: (%d)", Heap->Name, Lock_Mode); + LG_STACK_TRACE( LGD_LOG_LEVEL_DEFAULT); + *Locked = FALSE; // *Locked = TRUE; } @@ -1138,6 +1149,8 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) *Locked = TRUE; } + LG_LOG_TRACE_2( LGD_LOG_LEVEL_DEFAULT, "Locked: heap [%s] lock_mode: (%d)", Heap->Name, Heap->Lock_Mode); + return( SMS_OK); } @@ -1156,9 +1169,6 @@ SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap) SMT_Status rc; - sprintf( SM_Error_Msg, "SM_Heap_UnLock: heap [%s] lock_mode: (%d)...", Heap->Name, Heap->Lock_Mode); - SM_Error_Print(); - rc = SM_Heap_Lock_Release (Heap->MHH, Heap->Lock_Mode); if( rc != SMS_OK) { @@ -1171,6 +1181,8 @@ SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap) Heap->Lock_Mode = SMD_NO_LOCK; + LG_LOG_TRACE_2( LGD_LOG_LEVEL_DEFAULT, "Unlocked: heap [%s] lock_mode: (%d)", Heap->Name, Heap->Lock_Mode); + return( SMS_OK); } @@ -3366,10 +3378,14 @@ NDT_Status SM_Opened_Heap_List_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Inde Command_Name = "NDD_CMD_VALUE_PRINT"; - +/* fprintf( Out, "Heap_Name: [%s]/[%s] Heap_Addr: (%p) MHH_Ptr: (%p) Lock_Mode: (%d) Seg_Nb: (%d)\n", SM_Context, Heap_Ptr->Name, Heap_Ptr, Heap_Ptr->MHH, Heap_Ptr->Lock_Mode, Heap_Ptr->Nb_Seg); +*/ + LG_LOG_INFO_6( "Heap_Name: [%s]/[%s] Heap_Addr: (%p) MHH_Ptr: (%p) Lock_Mode: (%d) Seg_Nb: (%d)", + SM_Context, Heap_Ptr->Name, Heap_Ptr, Heap_Ptr->MHH, Heap_Ptr->Lock_Mode, Heap_Ptr->Nb_Seg); + return( NDS_OK); } @@ -3964,9 +3980,13 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node if( MHH_Ptr->State == SMD_STATE_CORRUPTED) { +/* fprintf( Out, "Heap_Name: [%s]/[%s] Heap_Addr: (%lx) *** CORRUPTED *** Checker_PId: (%ld)\n", SM_Context, MHH_Ptr->Name, MHH_Ptr, MHH_Ptr->Writer); - +*/ + LG_LOG_INFO_4( "Heap_Name: [%s]/[%s] Heap_Addr: (%lx) *** CORRUPTED *** Checker_PId: (%ld)", + SM_Context, MHH_Ptr->Name, MHH_Ptr, MHH_Ptr->Writer); + return( NDS_OK); } @@ -3995,12 +4015,21 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node free_chunk_nb = MHH_Ptr->FCR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; ND_DataStruct_Traverse( MHH_Ptr->FCR, NDD_CMD_VALUE_SUM, (void *)&free_size); - +/* fprintf( Out, "Heap_Name: [%s]/[%s] Heap_Addr: (%p) Sem_Id: (%d) Lock_Status: [%s]\nWriter_PId: (%ld) Seg_Nb: (%d) Heap_Size: (%lu) Size_Limit: (%ld) Auto_Compress: (%d) Compress_Nb: (%ld)\nAlloc_Chunk_Nb: (%d) Alloc_Size: (%lu) Free_Chunk_Nb: (%d) Free_Size: (%lu)\n\n", SM_Context, heap_name, MHH_Ptr, MHH_Ptr->SemId, SM_Lock_Status_Get( "heap", MHH_Ptr), MHH_Ptr->Writer, segment_nb, segment_size, MHH_Ptr->Limit_Size, MHH_Ptr->Auto_Compress, MHH_Ptr->Compress_Nb, alloc_chunk_nb, alloc_size, free_chunk_nb, free_size); +*/ + LG_LOG_INFO_5( "Heap_Name: [%s]/[%s] Heap_Addr: (%p) Sem_Id: (%d) Lock_Status: [%s]", + SM_Context, heap_name, MHH_Ptr, MHH_Ptr->SemId, SM_Lock_Status_Get( "heap", MHH_Ptr)); + LG_LOG_INFO_6( "Writer_PId: (%ld) Seg_Nb: (%d) Heap_Size: (%lu) Size_Limit: (%ld) Auto_Compress: (%d) Compress_Nb: (%ld)", + MHH_Ptr->Writer, segment_nb, segment_size, MHH_Ptr->Limit_Size, MHH_Ptr->Auto_Compress, MHH_Ptr->Compress_Nb); + LG_LOG_INFO_4( "Alloc_Chunk_Nb: (%d) Alloc_Size: (%lu) Free_Chunk_Nb: (%d) Free_Size: (%lu)", + alloc_chunk_nb, alloc_size, free_chunk_nb, free_size); + LG_LOG_INFO_0( ""); + if( locked == TRUE) { SM_Heap_Unlock_I( heap_ptr); @@ -4580,10 +4609,14 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node Command_Name = "NDD_CMD_VALUE_PRINT"; - +/* fprintf( Out, "Data Segment Header: Mem_Id: (%d) Start: (%p) Size: (%ld)\n", DSH_Ptr->MemId, DSH_Ptr->Start, DSH_Ptr->Size); +*/ + LG_LOG_INFO_3( "Data Segment Header: Mem_Id: (%d) Start: (%p) Size: (%ld)", + DSH_Ptr->MemId, DSH_Ptr->Start, DSH_Ptr->Size); + return( NDS_OK); } @@ -5007,10 +5040,14 @@ NDT_Status SM_ACR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node Command_Name = "NDD_CMD_VALUE_PRINT"; - +/* fprintf( Out, "Allocated Chunk: Chunk_Addr: (%p) Data_Addr: (%p) Data_Size: (%ld)\n", Chunk_Ptr, Chunk_Ptr->Data, Chunk_Ptr->Size); +*/ + LG_LOG_INFO_3( "Allocated Chunk: Chunk_Addr: (%p) Data_Addr: (%p) Data_Size: (%ld)", + Chunk_Ptr, Chunk_Ptr->Data, Chunk_Ptr->Size); + return( NDS_OK); } @@ -5307,8 +5344,10 @@ NDT_Status SM_FCR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node Command_Name = "NDD_CMD_VALUE_PRINT"; - fprintf( Out, "Free Chunk: Chunk_Addr: (%p) Data_Ptr: (%p) Size: (%ld)\n", Chunk_Ptr, Chunk_Ptr->Data, Chunk_Ptr->Size); +// fprintf( Out, "Free Chunk: Chunk_Addr: (%p) Data_Ptr: (%p) Size: (%ld)\n", Chunk_Ptr, Chunk_Ptr->Data, Chunk_Ptr->Size); + LG_LOG_INFO_3( "Free Chunk: Chunk_Addr: (%p) Data_Ptr: (%p) Size: (%ld)", Chunk_Ptr, Chunk_Ptr->Data, Chunk_Ptr->Size); + return( NDS_OK); } @@ -5692,31 +5731,3 @@ SMT_Status SM_Name_Prefix( char *Prefixed, const char *Unprefixed) return( SMS_OK); } - - - - - -/*------------------------------------------------------------------------------*/ -/* Print stack trace */ -/*------------------------------------------------------------------------------*/ - -void SM_stack_trace_print( void) -{ - void *array[10]; - char **strings; - int size, i; - - - size = backtrace( array, 10); - strings = backtrace_symbols( array, size); - - if( strings != NULL) - { - printf( "Obtained %d stack frames.\n", size); - - for( i = 0; i < size; i++) printf( "%s\n", strings[i]); - } - - free( strings); -} diff --git a/lib/libshmem.h b/lib/libshmem.h index b2b8496..53ec662 100644 --- a/lib/libshmem.h +++ b/lib/libshmem.h @@ -22,7 +22,9 @@ - +/*----------------------------------------------------------------------------*/ +/* Includes */ +/*----------------------------------------------------------------------------*/ #include #include @@ -37,13 +39,18 @@ #include -#include +/*----------------------------------------------------------------------------*/ +/* Definitions */ +/*----------------------------------------------------------------------------*/ + +#define LGD_MODULE_NAME "sm" + /* Compteur d'ouverture de la librairie */ @@ -304,8 +311,8 @@ SMT_Status SM_Name_Prefix( char *, const char *); -/*------------------------------------------------------------------------------*/ -/* Print stack trace */ -/*------------------------------------------------------------------------------*/ -void SM_stack_trace_print( void); + + + +/*------------------------------------------------------------------------------*/ diff --git a/util/Makefile b/util/Makefile index 5e1254b..e7ec22a 100644 --- a/util/Makefile +++ b/util/Makefile @@ -9,11 +9,11 @@ include ../Makefile.rule -DEP_STATIC += ../lib/libshmem.a ../../liblog/lib/liblog.a ../../libnode/lib/libnode.a -DEP_DYNAMIC += ../lib/libshmem.so ../../liblog/lib/liblog.so ../../libnode/lib/libnode.so -INCLUDE += -I . -I ../include -I ../../liblog/include -I ../../libnode/include -LIBDIR += -L . -L ../lib -L ../../liblog/lib -L ../../libnode/lib -LIB_STATIC += ../lib/libshmem.a ../../liblog/lib/liblog.a ../../libnode/lib/libnode.a -ldl +DEP_STATIC += ../lib/libshmem.a ../../liblog/lib/liblog.a ../../libnode/lib/libnode.a +DEP_DYNAMIC += ../lib/libshmem.so ../../liblog/lib/liblog.so ../../libnode/lib/libnode.so +INCLUDE += -I . -I ../include -I ../../liblog/include -I ../../libnode/include +LIBDIR += -L . -L ../lib -L ../../liblog/lib -L ../../libnode/lib +LIB_STATIC += ../lib/libshmem.a ../../liblog/lib/liblog.a ../../libnode/lib/libnode.a -ldl LIB_DYNAMIC += -lshmem -llog -lnode -ldl CFLAGS += -rdynamic