Portable HDF5 Tracing

When compiled with the H5_DEBUG_API define, HDF5 allows tracing of its API calls ( https://support.hdfgroup.org/HDF5/doc/H5.user/Debugging.html ).

To redirect this call into its own logfile instead of the standard output or standard error, HDF5 uses the fdopen() function to make use of an already opened file description, the actual opening operation is left to the Unix shell, as in

HDF5_DEBUG="55 trace" a.out 55>trace-output.log|

However, this mechanism doesn't seem to work under msys bash / mingw. I could trace it down to a simple program:

#include <stdio.h>

main()
{
FILE*F = fdopen(55, "w");
     perror("out 55");
     fprintf(F, "hello\n");
     return 0;
}

Then running it in the shell with

./a.exe 55>more.txt

This works well under Linux, even in the Windows Linux Subsystem, but not in the msys bash:

$ ./a.exe 55> more.txt
out 55: Bad file descriptor

and neither in window's cmd.exe, where it seems only the first 10 numbers are allowed ( https://technet.microsoft.com/en-us/library/bb490982.aspx ):

./a.exe 5> more.txt

out 5: Bad file descriptor

Did anyone else get this mechanism to work under windows? If not, maybe the HDF5 trace function should be modified to allow for a filename instead of just a numerical file descriptor. The function in charge is H5_debug_mask() in H5.c , and instead of calling fdopen() on digits found in the HDF5_DEBUG environment variable, it could check for something like a dot contained in the string, and if so interpret it as filename to be opened instead (assuming that debug package names never will contain a dot, and all logfiles must have a file extension when opening via this mechanism).

Any thoughts?

           Werner

···

--
___________________________________________________________________________
Dr. Werner Benger Visualization Research
Center for Computation & Technology at Louisiana State University (CCT/LSU)
2019 Digital Media Center, Baton Rouge, Louisiana 70803
Tel.: +1 225 578 4809 Fax.: +1 225 578-5362

All,

Will be more than happy to accept a patch for this request.

Elena

When compiled with the H5_DEBUG_API define, HDF5 allows tracing of its API calls ( https://support.hdfgroup.org/HDF5/doc/H5.user/Debugging.html ).

To redirect this call into its own logfile instead of the standard output or standard error, HDF5 uses the fdopen() function to make use of an already opened file description, the actual opening operation is left to the Unix shell, as in

HDF5_DEBUG="55 trace" a.out 55>trace-output.log

However, this mechanism doesn't seem to work under msys bash / mingw. I could trace it down to a simple program:

#include <stdio.h>

main()
{
FILE*F = fdopen(55, "w");
    perror("out 55");
    fprintf(F, "hello\n");
    return 0;
}

Then running it in the shell with

./a.exe 55>more.txt

This works well under Linux, even in the Windows Linux Subsystem, but not in the msys bash:

$ ./a.exe 55> more.txt
out 55: Bad file descriptor

and neither in window's cmd.exe, where it seems only the first 10 numbers are allowed ( https://technet.microsoft.com/en-us/library/bb490982.aspx ):

./a.exe 5> more.txt

out 5: Bad file descriptor

Did anyone else get this mechanism to work under windows? If not, maybe the HDF5 trace function should be modified to allow for a filename instead of just a numerical file descriptor. The function in charge is H5_debug_mask() in H5.c , and instead of calling fdopen() on digits found in the HDF5_DEBUG environment variable, it could check for something like a dot contained in the string, and if so interpret it as filename to be opened instead (assuming that debug package names never will contain a dot, and all logfiles must have a file extension when opening via this mechanism).

Any thoughts?

          Werner

···

On Jul 24, 2017, at 9:53 AM, Werner Benger <werner@cct.lsu.edu<mailto:werner@cct.lsu.edu>> wrote:

--
___________________________________________________________________________
Dr. Werner Benger Visualization Research
Center for Computation & Technology at Louisiana State University (CCT/LSU)
2019 Digital Media Center, Baton Rouge, Louisiana 70803
Tel.: +1 225 578 4809 Fax.: +1 225 578-5362

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org<mailto:Hdf-forum@lists.hdfgroup.org>
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

Hi Elena,

  actually I found an even better way as described below, which is to just check for the ">" sign in the debug-string. Attached is a patch that handles it, and it allows for a syntax like this:

export HDF5_DEBUG=">trace.log trace"

This writes the API trace to the file "trace.log" .

The code should be portable, maybe the PATH_MAX definition needs some more include or define on some platform.

          Werner

trace-open-file.diff (1.2 KB)

···

On 24.07.2017 22:29, Elena Pourmal wrote:

All,

Will be more than happy to accept a patch for this request.

Elena

On Jul 24, 2017, at 9:53 AM, Werner Benger <werner@cct.lsu.edu >> <mailto:werner@cct.lsu.edu>> wrote:

When compiled with the H5_DEBUG_API define, HDF5 allows tracing of its API calls ( Debugging HDF5 Applications ).

To redirect this call into its own logfile instead of the standard output or standard error, HDF5 uses the fdopen() function to make use of an already opened file description, the actual opening operation is left to the Unix shell, as in

>>

>HDF5_DEBUG="55 trace" a.out 55>trace-output.log|
>>

However, this mechanism doesn't seem to work under msys bash / mingw. I could trace it down to a simple program:

#include <stdio.h>

main()
{
FILE*F = fdopen(55, "w");
     perror("out 55");
     fprintf(F, "hello\n");
     return 0;
}

Then running it in the shell with

./a.exe 55>more.txt

This works well under Linux, even in the Windows Linux Subsystem, but not in the msys bash:

$ ./a.exe 55> more.txt
out 55: Bad file descriptor

and neither in window's cmd.exe, where it seems only the first 10 numbers are allowed ( Using command redirection operators | Microsoft Learn ):

> ./a.exe 5> more.txt
out 5: Bad file descriptor

Did anyone else get this mechanism to work under windows? If not, maybe the HDF5 trace function should be modified to allow for a filename instead of just a numerical file descriptor. The function in charge is H5_debug_mask() in H5.c , and instead of calling fdopen() on digits found in the HDF5_DEBUG environment variable, it could check for something like a dot contained in the string, and if so interpret it as filename to be opened instead (assuming that debug package names never will contain a dot, and all logfiles must have a file extension when opening via this mechanism).

Any thoughts?

          Werner

--
___________________________________________________________________________
Dr. Werner Benger Visualization Research
Center for Computation & Technology at Louisiana State University (CCT/LSU)
2019 Digital Media Center, Baton Rouge, Louisiana 70803
Tel.: +1 225 578 4809 Fax.: +1 225 578-5362
_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org <mailto:Hdf-forum@lists.hdfgroup.org>
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

_______________________________________________
Hdf-forum is for HDF software users discussion.
Hdf-forum@lists.hdfgroup.org
http://lists.hdfgroup.org/mailman/listinfo/hdf-forum_lists.hdfgroup.org
Twitter: https://twitter.com/hdf5

--
___________________________________________________________________________
Dr. Werner Benger Visualization Research
Center for Computation & Technology at Louisiana State University (CCT/LSU)
2019 Digital Media Center, Baton Rouge, Louisiana 70803
Tel.: +1 225 578 4809 Fax.: +1 225 578-5362