hpc / mpifileutils

File utilities designed for scalability and performance.
https://hpc.github.io/mpifileutils
BSD 3-Clause "New" or "Revised" License
168 stars 66 forks source link

Short source code path vs Absolute source code path, returned by MFU_LOG function in mfu_util.h #525

Open FR-Montreuil opened 2 years ago

FR-Montreuil commented 2 years ago

The MFU_LOG function gives some debuging informations such as the full or absolute path of the source code. Here is an example:

[XXX ~]$ dbcast
[2022-03-09T11:06:23] [0] [/stck/montreui/rpmbuild/BUILD/mpiFileUtils-0.11.1/mpifileutils-0.11.1/src/dbcast/dbcast.c:550] ERROR: Failed to find source and/or destination file names

Usage: dbcast [options] <SRC> <DEST>
...

Well, in a context of deploying on a HPC calculator, I found a bit tricky to have in this example the absolute path with my user name. I would rather see a short source code path such as :

[XXX ~]$ dbcast
[2022-03-09T11:06:23] [0] [src/dbcast/dbcast.c:550] ERROR: Failed to find source and/or destination file names

Usage: dbcast [options] <SRC> <DEST>
...

I have test a modification in the source code :

#define MFU_LOG(level, ...) do {  \
        if (mfu_initialized && level <= mfu_debug_level) { \
            char timestamp[256]; \
            char *longfilename=__FILE__; \
            char shortfilename[256]; \
            char *buildpath="/stck/montreui/rpmbuild/BUILD/mpiFileUtils-0.11.1/mpifileutils--0.11.1"; \
            time_t ltime = time(NULL); \
            struct tm *ttime = localtime(&ltime); \
            strftime(timestamp, sizeof(timestamp), \
                     "%Y-%m-%dT%H:%M:%S", ttime); \
            strncpy(shortfilename,&longfilename[strlen(buildpath)],256-strlen(buildpath)); \
            if(level == MFU_LOG_DBG) { \
                fprintf(mfu_debug_stream,"[%s] [%d] [%s:%d] ", \
                        timestamp, mfu_rank, \
                        shortfilename, __LINE__); \
            } else if(level <= MFU_LOG_ERR) { \
                fprintf(mfu_debug_stream,"[%s] [%d] [%s:%d] ERROR: ", \
                        timestamp, mfu_rank, \
                        shortfilename, __LINE__); \
            } else { \
                fprintf(mfu_debug_stream,"[%s] ", \
                        timestamp); \
            } \
            fprintf(mfu_debug_stream, __VA_ARGS__); \
            fprintf(mfu_debug_stream, "\n"); \
            fflush(mfu_debug_stream); \
        } \
    } while (0)

So my idea here is to shorten the path to code source to avoid the guy's username path that have compile the library.

What ever the way of doing that... Changing the mfu_debug_level at MFU_LOG_NONE is a pity because those informations are interesting however. I did not find any way in compile options or whatsoever to avoid the long path source code.

Does it sound right or silly ?

It is my firt post, so, be cool and don't upset yoursef, please ;-)

FR-Montreuil commented 2 years ago

Another way : find an option in cpp to have a short name path for the macro __FILE__

adammoody commented 2 years ago

Thanks, @FR-Montreuil . I like this idea, too. We'll look for a way to shorten the path in those messages.

FR-Montreuil commented 2 years ago

Hi,

I have suggested a way but I have also read other way https://stackoverflow.com/questions/8487986/file-macro-shows-full-path

Take care