kwo pushed a commit to branch master.

http://git.enlightenment.org/legacy/imlib2.git/commit/?id=9996028e7d4bd61e0190da830e07f26c71f954bf

commit 9996028e7d4bd61e0190da830e07f26c71f954bf
Author: Kim Woelders <[email protected]>
Date:   Mon Nov 11 19:31:24 2019 +0100

    debug: Add some debug related to file access and image loading
---
 src/lib/file.c    | 22 ++++++++++++++++++++++
 src/lib/image.c   | 20 ++++++++++++++++++++
 src/lib/loaders.c | 15 +++++++++++++++
 3 files changed, 57 insertions(+)

diff --git a/src/lib/file.c b/src/lib/file.c
index 4f7c43a..caa322a 100644
--- a/src/lib/file.c
+++ b/src/lib/file.c
@@ -10,13 +10,19 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#include "debug.h"
 #include "file.h"
 
+#define DBG_PFX "FILE"
+#define DP(fmt...) DC(DBG_FILE, fmt)
+
 int
 __imlib_IsRealFile(const char *s)
 {
    struct stat         st;
 
+   DP("%s: '%s'\n", __func__, s);
+
    return (stat(s, &st) != -1) && (S_ISREG(st.st_mode));
 }
 
@@ -63,6 +69,8 @@ __imlib_FileRealFile(const char *file)
 {
    char               *newfile;
 
+   DP("%s: '%s'\n", __func__, file);
+
    newfile = malloc(strlen(file) + 1);
    if (!newfile)
       return NULL;
@@ -106,6 +114,8 @@ __imlib_FileExtension(const char *file)
    const char         *p, *s;
    int                 ch;
 
+   DP("%s: '%s'\n", __func__, file);
+
    if (!file)
       return NULL;
 
@@ -120,6 +130,8 @@ __imlib_FileExtension(const char *file)
 int
 __imlib_FileStat(const char *file, struct stat *st)
 {
+   DP("%s: '%s'\n", __func__, file);
+
    if ((!file) || (!*file))
       return -1;
 
@@ -131,6 +143,8 @@ __imlib_FileExists(const char *s)
 {
    struct stat         st;
 
+   DP("%s: '%s'\n", __func__, s);
+
    return __imlib_FileStat(s, &st) == 0;
 }
 
@@ -139,6 +153,8 @@ __imlib_FileIsFile(const char *s)
 {
    struct stat         st;
 
+   DP("%s: '%s'\n", __func__, s);
+
    if (__imlib_FileStat(s, &st))
       return 0;
 
@@ -150,6 +166,8 @@ __imlib_FileIsDir(const char *s)
 {
    struct stat         st;
 
+   DP("%s: '%s'\n", __func__, s);
+
    if (__imlib_FileStat(s, &st))
       return 0;
 
@@ -161,6 +179,8 @@ __imlib_FileModDate(const char *s)
 {
    struct stat         st;
 
+   DP("%s: '%s'\n", __func__, s);
+
    if (__imlib_FileStat(s, &st))
       return 0;
 
@@ -183,6 +203,8 @@ __imlib_FileCanRead(const char *s)
 {
    struct stat         st;
 
+   DP("%s: '%s'\n", __func__, s);
+
    if (__imlib_FileStat(s, &st))
       return 0;
 
diff --git a/src/lib/image.c b/src/lib/image.c
index 2e2a94c..e825827 100644
--- a/src/lib/image.c
+++ b/src/lib/image.c
@@ -12,10 +12,14 @@
 #endif
 
 #include "Imlib2.h"
+#include "debug.h"
 #include "file.h"
 #include "image.h"
 #include "loaders.h"
 
+#define DBG_PFX "IMG"
+#define DP(fmt...) DC(DBG_LOAD, fmt)
+
 /* Imlib loader context */
 struct _imlibldctx {
    ImlibProgressFunction progress;
@@ -503,6 +507,13 @@ __imlib_LoadImageWrapper(const ImlibLoader * l, ImlibImage 
* im, int load_data)
 {
    int                 rc;
 
+   DP("%s: fmt='%s' file='%s'(%s), imm=%d\n", __func__,
+      l->formats[0], im->file, im->real_file, load_data);
+
+#if IMLIB2_DEBUG
+   unsigned int        t0 = __imlib_time_us();
+#endif
+
    if (l->load2)
      {
         FILE               *fp = NULL;
@@ -530,19 +541,28 @@ __imlib_LoadImageWrapper(const ImlibLoader * l, 
ImlibImage * im, int load_data)
         return LOAD_FAIL;
      }
 
+   DP("%s: %-4s: %s: Elapsed time: %.3f ms\n", __func__,
+      l->formats[0], im->file, 1e-3 * (__imlib_time_us() - t0));
+
    if (rc <= LOAD_FAIL)
      {
         /* Failed - clean up */
+        DP("%s: Failed\n", __func__);
+
         if (im->w != 0 || im->h != 0)
           {
+             DP("%s: Loader %s: Didn't clear w/h=%d/%d\n", __func__,
+                l->formats[0], im->w, im->h);
              im->w = im->h = 0;
           }
         if (im->data)
           {
+             DP("%s: Loader %s: Free im->data\n", __func__, l->formats[0]);
              __imlib_FreeData(im);
           }
         if (im->format)
           {
+             DP("%s: Loader %s: Free im->format\n", __func__, l->formats[0]);
              free(im->format);
              im->format = NULL;
           }
diff --git a/src/lib/loaders.c b/src/lib/loaders.c
index ae10271..73e58f0 100644
--- a/src/lib/loaders.c
+++ b/src/lib/loaders.c
@@ -5,10 +5,14 @@
 #include <string.h>
 #include <time.h>
 
+#include "debug.h"
 #include "file.h"
 #include "image.h"
 #include "loaders.h"
 
+#define DBG_PFX "LOAD"
+#define DP(fmt...) DC(DBG_LOAD, fmt)
+
 static ImlibLoader *loaders = NULL;
 
 ImlibLoader       **
@@ -25,6 +29,8 @@ __imlib_ProduceLoader(char *file)
    ImlibLoader        *l;
    void                (*l_formats)(ImlibLoader * l);
 
+   DP("%s: %s\n", __func__, file);
+
    l = malloc(sizeof(ImlibLoader));
    l->num_formats = 0;
    l->formats = NULL;
@@ -93,6 +99,8 @@ __imlib_LoadAllLoaders(void)
    int                 i, num;
    char              **list;
 
+   DP("%s\n", __func__);
+
    if (loaders)
       return;
 
@@ -125,6 +133,8 @@ __imlib_FindBestLoaderForFormat(const char *format, int 
for_save)
 {
    ImlibLoader        *l;
 
+   DP("%s: fmt='%s'\n", __func__, format);
+
    if (!format || format[0] == '\0')
       return NULL;
 
@@ -159,6 +169,7 @@ __imlib_FindBestLoaderForFormat(const char *format, int 
for_save)
      }
 
  done:
+   DP("%s: fmt='%s': %s\n", __func__, format, l ? l->file : "-");
    return l;
 }
 
@@ -167,6 +178,8 @@ __imlib_FindBestLoaderForFile(const char *file, int 
for_save)
 {
    ImlibLoader        *l;
 
+   DP("%s: file='%s'\n", __func__, file);
+
    l = __imlib_FindBestLoaderForFormat(__imlib_FileExtension(file), for_save);
 
    return l;
@@ -176,6 +189,8 @@ ImlibLoader        *
 __imlib_FindBestLoaderForFileFormat(const char *file, const char *format,
                                     int for_save)
 {
+   DP("%s: file='%s' ext='%s'\n", __func__, file, format);
+
    /* if the format is provided ("png" "jpg" etc.) use that */
    /* otherwise us the file extension */
    if (format)

-- 


Reply via email to