[PATCH] Reduce the number of stat calls for each plugin from 3 to 1.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] Reduce the number of stat calls for each plugin from 3 to 1.

Simon Holm Thøgersen
The code already called stat directly in one place. By moving this code
further up we avoid doing a stat with g_file_test twice by replacing the
g_file_test calls with similar code that uses the cached stat.

Signed-off-by: Simon Holm Thøgersen <[hidden email]>
---
 gst/gstregistry.c |   21 ++++++++++-----------
 1 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/gst/gstregistry.c b/gst/gstregistry.c
index 1c1d27a..6850b91 100644
--- a/gst/gstregistry.c
+++ b/gst/gstregistry.c
@@ -808,9 +808,17 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
     return FALSE;
 
   while ((dirent = g_dir_read_name (dir))) {
+    struct stat file_status;
+
     filename = g_strjoin ("/", path, dirent, NULL);
+    if (stat(filename, &file_status) < 0) {
+        /* Plugin will be removed from cache after the scan completes if it
+         * is still marked 'cached' */
+        g_free (filename);
+        continue;
+    }
 
-    if (g_file_test (filename, G_FILE_TEST_IS_DIR)) {
+    if (S_ISDIR(file_status.st_mode)) {
       /* skip the .debug directory, these contain elf files that are not
        * useful or worse, can crash dlopen () */
       if (g_str_equal (dirent, ".debug")) {
@@ -831,7 +839,7 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
       g_free (filename);
       continue;
     }
-    if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
+    if (!S_ISREG(file_status.st_mode)) {
       GST_LOG_OBJECT (registry, "%s is not a regular file, ignoring", filename);
       g_free (filename);
       continue;
@@ -853,15 +861,6 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
      * was already seen by the registry, we ignore it */
     plugin = gst_registry_lookup (registry, filename);
     if (plugin) {
-      struct stat file_status;
-
-      if (stat (filename, &file_status)) {
-        /* Plugin will be removed from cache after the scan completes if it
-         * is still marked 'cached' */
-        g_free (filename);
-        gst_object_unref (plugin);
-        continue;
-      }
       if (plugin->registered) {
         GST_DEBUG_OBJECT (registry,
             "plugin already registered from path \"%s\"",
--
1.6.0.2.526.g5c283


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Reduce the number of stat calls for each plugin from 3 to 1.

Jan Schmidt-6
Hi Simon,

This looks like a good idea. I think it'll need some more work to remain
portable to Windows. I don't think the S_ISDIR and S_ISREG macros exist
there.

J.

On Fri, 2008-11-07 at 21:42 +0100, Simon Holm Thøgersen wrote:

> The code already called stat directly in one place. By moving this code
> further up we avoid doing a stat with g_file_test twice by replacing the
> g_file_test calls with similar code that uses the cached stat.
>
> Signed-off-by: Simon Holm Thøgersen <[hidden email]>
> ---
>  gst/gstregistry.c |   21 ++++++++++-----------
>  1 files changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/gst/gstregistry.c b/gst/gstregistry.c
> index 1c1d27a..6850b91 100644
> --- a/gst/gstregistry.c
> +++ b/gst/gstregistry.c
> @@ -808,9 +808,17 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
>      return FALSE;
>  
>    while ((dirent = g_dir_read_name (dir))) {
> +    struct stat file_status;
> +
>      filename = g_strjoin ("/", path, dirent, NULL);
> +    if (stat(filename, &file_status) < 0) {
> +        /* Plugin will be removed from cache after the scan completes if it
> +         * is still marked 'cached' */
> +        g_free (filename);
> +        continue;
> +    }
>  
> -    if (g_file_test (filename, G_FILE_TEST_IS_DIR)) {
> +    if (S_ISDIR(file_status.st_mode)) {
>        /* skip the .debug directory, these contain elf files that are not
>         * useful or worse, can crash dlopen () */
>        if (g_str_equal (dirent, ".debug")) {
> @@ -831,7 +839,7 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
>        g_free (filename);
>        continue;
>      }
> -    if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
> +    if (!S_ISREG(file_status.st_mode)) {
>        GST_LOG_OBJECT (registry, "%s is not a regular file, ignoring", filename);
>        g_free (filename);
>        continue;
> @@ -853,15 +861,6 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
>       * was already seen by the registry, we ignore it */
>      plugin = gst_registry_lookup (registry, filename);
>      if (plugin) {
> -      struct stat file_status;
> -
> -      if (stat (filename, &file_status)) {
> -        /* Plugin will be removed from cache after the scan completes if it
> -         * is still marked 'cached' */
> -        g_free (filename);
> -        gst_object_unref (plugin);
> -        continue;
> -      }
>        if (plugin->registered) {
>          GST_DEBUG_OBJECT (registry,
>              "plugin already registered from path \"%s\"",
--
Jan Schmidt <[hidden email]>


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] Reduce the number of stat calls for each plugin from 3 to 1.

Edward Hervey
Administrator
Hi Simon,

  Just tried the patch on linux. Seems to work fine. One remark though,
we don't track patches on the mailing-list, could you open a bug on the
gstreamer bugtracker so we can properly track this ?

    Edward

On Sat, 2008-11-08 at 19:02 +0000, Jan Schmidt wrote:

> Hi Simon,
>
> This looks like a good idea. I think it'll need some more work to remain
> portable to Windows. I don't think the S_ISDIR and S_ISREG macros exist
> there.
>
> J.
>
> On Fri, 2008-11-07 at 21:42 +0100, Simon Holm Thøgersen wrote:
> > The code already called stat directly in one place. By moving this code
> > further up we avoid doing a stat with g_file_test twice by replacing the
> > g_file_test calls with similar code that uses the cached stat.
> >
> > Signed-off-by: Simon Holm Thøgersen <[hidden email]>
> > ---
> >  gst/gstregistry.c |   21 ++++++++++-----------
> >  1 files changed, 10 insertions(+), 11 deletions(-)
> >
> > diff --git a/gst/gstregistry.c b/gst/gstregistry.c
> > index 1c1d27a..6850b91 100644
> > --- a/gst/gstregistry.c
> > +++ b/gst/gstregistry.c
> > @@ -808,9 +808,17 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
> >      return FALSE;
> >  
> >    while ((dirent = g_dir_read_name (dir))) {
> > +    struct stat file_status;
> > +
> >      filename = g_strjoin ("/", path, dirent, NULL);
> > +    if (stat(filename, &file_status) < 0) {
> > +        /* Plugin will be removed from cache after the scan completes if it
> > +         * is still marked 'cached' */
> > +        g_free (filename);
> > +        continue;
> > +    }
> >  
> > -    if (g_file_test (filename, G_FILE_TEST_IS_DIR)) {
> > +    if (S_ISDIR(file_status.st_mode)) {
> >        /* skip the .debug directory, these contain elf files that are not
> >         * useful or worse, can crash dlopen () */
> >        if (g_str_equal (dirent, ".debug")) {
> > @@ -831,7 +839,7 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
> >        g_free (filename);
> >        continue;
> >      }
> > -    if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
> > +    if (!S_ISREG(file_status.st_mode)) {
> >        GST_LOG_OBJECT (registry, "%s is not a regular file, ignoring", filename);
> >        g_free (filename);
> >        continue;
> > @@ -853,15 +861,6 @@ gst_registry_scan_path_level (GstRegistry * registry, const gchar * path,
> >       * was already seen by the registry, we ignore it */
> >      plugin = gst_registry_lookup (registry, filename);
> >      if (plugin) {
> > -      struct stat file_status;
> > -
> > -      if (stat (filename, &file_status)) {
> > -        /* Plugin will be removed from cache after the scan completes if it
> > -         * is still marked 'cached' */
> > -        g_free (filename);
> > -        gst_object_unref (plugin);
> > -        continue;
> > -      }
> >        if (plugin->registered) {
> >          GST_DEBUG_OBJECT (registry,
> >              "plugin already registered from path \"%s\"",


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel