eet: add support for statistique.
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 10 Feb 2012 15:30:33 +0000 (15:30 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 10 Feb 2012 15:30:33 +0000 (15:30 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eet@67829 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
NEWS
src/bin/eet_main.c
src/lib/Eet.h
src/lib/eet_dictionary.c

index 1ecc86f..4de0f82 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
        * add support for GNUTLS 3.x.
 
+2012-02-10  Cedric Bail
+
+       * add eet_dictionary_count.
+       * add "eet -t FILE.EET".
diff --git a/NEWS b/NEWS
index 29f0b57..1abe36e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ Improvements:
 
     * most allocations moved to mempools
     * support GNUTLS 3.x
+    * add "eet -t FILE.EET" to get some stat out of an eet file
 
 Eet 1.5.0
 
index 0d577ad..8a93d11 100644 (file)
@@ -69,6 +69,63 @@ do_eet_list(const char *file)
 } /* do_eet_list */
 
 static void
+do_eet_stats(const char *file)
+{
+   int i, num;
+   int count[2] = { 0, 0 };
+   int size[2] = { 0, 0 };
+   char **list;
+   Eet_File *ef;
+   Eet_Dictionary *ed;
+
+   ef = eet_open(file, EET_FILE_MODE_READ);
+   if (!ef)
+     {
+        ERR("cannot open for reading: %s", file);
+        exit(-1);
+     }
+
+   printf("*** sections stats ***\n");
+   list = eet_list(ef, "*", &num);
+   if (list)
+     {
+        for (i = 0; i < num; i++)
+          {
+             const void *ro = NULL;
+             void *rw = NULL;
+             int tsize;
+
+             ro = eet_read_direct(ef, list[i], &tsize);
+             if (!ro) rw = eet_read(ef, list[i], &tsize);
+             printf(rw ? "%s of size %i is compressed.\n" : "%s of size %i is not compressed.\n", list[i], tsize);
+             count[rw ? 0 : 1]++;
+             size[rw ? 0 : 1] += tsize;
+             free(rw);
+          }
+        free(list);
+     }
+
+   printf("*** dictionary ***\n");
+   ed = eet_dictionary_get(ef);
+   if (ed)
+     {
+        printf("%i strings inside the dictionary.\n", eet_dictionary_count(ed));
+     }
+   else
+     {
+        printf("no dictionary in this file.\n");
+     }
+   printf("*** global ***\n");
+   printf("%i sections\n", num);
+   printf("- %i of them are compressed (%02.2f%%) expanding in %i bytes.\n",
+          count[0], (float) count[0] * 100 / (float) num, size[0]);
+   printf("- %i of them are directly mappable in memory (%02.2f%%) representing %i bytes.\n",
+          count[1], (float) count[1] * 100 / (float) num, size[1]);
+
+   eet_close(ef);
+}
+
+static void
 do_eet_extract(const char *file,
                const char *key,
                const char *out,
@@ -366,6 +423,7 @@ help:
           "  eet -r FILE.EET KEY                                remove KEY in FILE.EET\n"
           "  eet -c FILE.EET                                    report and check the signature information of an eet file\n"
           "  eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY             sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n"
+          "  eet -t FILE.EET                                    give some statistic about a file\n"
           );
         eet_shutdown();
         return -1;
@@ -437,6 +495,8 @@ help:
      do_eet_check(argv[2]);
    else if ((!strcmp(argv[1], "-s")) && (argc > 4))
      do_eet_sign(argv[2], argv[3], argv[4]);
+   else if ((!strcmp(argv[1], "-t")) && (argc > 2))
+     do_eet_stats(argv[2]);
    else
      goto help;
 
index db31767..35dc18a 100644 (file)
@@ -645,6 +645,17 @@ eet_dictionary_string_check(Eet_Dictionary *ed,
                             const char *string);
 
 /**
+ * Return the number of strings inside a dictionary
+ * @param ed A valid dictionary handle
+ * @return the number of strings inside a dictionary
+ *
+ * @since 1.6.0
+ * @ingroup Eet_File_Group
+ */
+EAPI int
+eet_dictionary_count(const Eet_Dictionary *ed);
+
+/**
  * Read a specified entry from an eet file and return data
  * @param ef A valid eet file handle opened for reading.
  * @param name Name of the entry. eg: "/base/file_i_want".
index 287860d..c79239b 100644 (file)
@@ -169,6 +169,12 @@ eet_dictionary_string_get_size(const Eet_Dictionary *ed,
    return 0;
 }
 
+EAPI int
+eet_dictionary_count(const Eet_Dictionary *ed)
+{
+  return ed->count;
+}
+
 int
 eet_dictionary_string_get_hash(const Eet_Dictionary *ed,
                                int                   idx)