[tracker/posix_fadvise: 3/3] tracker-extract: Added hints with posix_fadvise() where possible
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/posix_fadvise: 3/3] tracker-extract: Added hints with posix_fadvise() where possible
- Date: Mon, 11 Oct 2010 14:57:10 +0000 (UTC)
commit 62993ec1d194ae8fd348cfb21f00439434160ee9
Author: Martyn Russell <martyn lanedo com>
Date: Mon Oct 11 15:55:55 2010 +0100
tracker-extract: Added hints with posix_fadvise() where possible
All use POSIX_FADVISE_RANDOM except ABW, PS and TEXT.
This includes ABW, JPEG, MP3, PNG, PS, OGG and TEXT so far
src/tracker-extract/tracker-extract-abw.c | 4 ++++
src/tracker-extract/tracker-extract-jpeg.c | 5 +++++
src/tracker-extract/tracker-extract-mp3.c | 4 ++++
src/tracker-extract/tracker-extract-png.c | 6 ++++++
src/tracker-extract/tracker-extract-ps.c | 6 ++++--
src/tracker-extract/tracker-extract-vorbis.c | 4 ++++
src/tracker-extract/tracker-read.c | 25 +++++++++++++++++++++++--
7 files changed, 50 insertions(+), 4 deletions(-)
---
diff --git a/src/tracker-extract/tracker-extract-abw.c b/src/tracker-extract/tracker-extract-abw.c
index 6be54e2..3b238be 100644
--- a/src/tracker-extract/tracker-extract-abw.c
+++ b/src/tracker-extract/tracker-extract-abw.c
@@ -67,6 +67,10 @@ extract_abw (const gchar *uri,
line = NULL;
length = 0;
+#ifdef HAVE_POSIX_FADVISE
+ posix_fadvise (fileno (f), 0, 0, POSIX_FADV_SEQUENTIAL);
+#endif /* HAVE_POSIX_FADVISE */
+
tracker_sparql_builder_predicate (metadata, "a");
tracker_sparql_builder_object (metadata, "nfo:Document");
diff --git a/src/tracker-extract/tracker-extract-jpeg.c b/src/tracker-extract/tracker-extract-jpeg.c
index 429b1dd..d1dcdc5 100644
--- a/src/tracker-extract/tracker-extract-jpeg.c
+++ b/src/tracker-extract/tracker-extract-jpeg.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <setjmp.h>
+#include <fcntl.h>
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* strcasestr() */
@@ -134,6 +135,10 @@ extract_jpeg (const gchar *uri,
return;
}
+#ifdef HAVE_POSIX_FADVISE
+ posix_fadvise (fileno (f), 0, 0, POSIX_FADV_RANDOM);
+#endif /* HAVE_POSIX_FADVISE */
+
tracker_sparql_builder_predicate (metadata, "a");
tracker_sparql_builder_object (metadata, "nfo:Image");
tracker_sparql_builder_predicate (metadata, "a");
diff --git a/src/tracker-extract/tracker-extract-mp3.c b/src/tracker-extract/tracker-extract-mp3.c
index e48e797..85378f3 100644
--- a/src/tracker-extract/tracker-extract-mp3.c
+++ b/src/tracker-extract/tracker-extract-mp3.c
@@ -2019,6 +2019,10 @@ extract_mp3 (const gchar *uri,
}
#endif
+#ifdef HAVE_POSIX_FADVISE
+ posix_fadvise (fd, 0, 0, POSIX_FADV_RANDOM);
+#endif /* HAVE_POSIX_FADVISE */
+
#ifndef G_OS_WIN32
/* We don't use GLib's mmap because size can not be specified */
buffer = mmap (NULL,
diff --git a/src/tracker-extract/tracker-extract-png.c b/src/tracker-extract/tracker-extract-png.c
index 699f2c5..2bef9c1 100644
--- a/src/tracker-extract/tracker-extract-png.c
+++ b/src/tracker-extract/tracker-extract-png.c
@@ -24,6 +24,8 @@
#define _GNU_SOURCE
#endif
+#include <fcntl.h>
+
#include <png.h>
#include <libtracker-common/tracker-file-utils.h>
@@ -510,6 +512,10 @@ extract_png (const gchar *uri,
return;
}
+#ifdef HAVE_POSIX_FADVISE
+ posix_fadvise (fileno (f), 0, size, POSIX_FADV_RANDOM);
+#endif /* HAVE_POSIX_FADVISE */
+
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
NULL,
NULL,
diff --git a/src/tracker-extract/tracker-extract-ps.c b/src/tracker-extract/tracker-extract-ps.c
index 704036a..789c336 100644
--- a/src/tracker-extract/tracker-extract-ps.c
+++ b/src/tracker-extract/tracker-extract-ps.c
@@ -211,8 +211,6 @@ extract_ps_from_filestream (FILE *f,
}
}
-
-
static void
extract_ps (const gchar *uri,
TrackerSparqlBuilder *preupdate,
@@ -229,6 +227,10 @@ extract_ps (const gchar *uri,
return;
}
+#ifdef HAVE_POSIX_FADVISE
+ posix_fadvise (fileno (f), 0, 0, POSIX_FADV_SEQUENTIAL);
+#endif /* HAVE_POSIX_FADVISE */
+
/* Extract from filestream! */
g_debug ("Extracting PS '%s'...", uri);
extract_ps_from_filestream (f, preupdate, metadata);
diff --git a/src/tracker-extract/tracker-extract-vorbis.c b/src/tracker-extract/tracker-extract-vorbis.c
index 6998795..5b060d6 100644
--- a/src/tracker-extract/tracker-extract-vorbis.c
+++ b/src/tracker-extract/tracker-extract-vorbis.c
@@ -118,6 +118,10 @@ extract_vorbis (const char *uri,
return;
}
+#ifdef HAVE_POSIX_FADVISE
+ posix_fadvise (fileno (f), 0, 0, POSIX_FADV_RANDOM);
+#endif /* HAVE_POSIX_FADVISE */
+
if (ov_open (f, &vf, NULL, 0) < 0) {
tracker_file_close (f, FALSE);
return;
diff --git a/src/tracker-extract/tracker-read.c b/src/tracker-extract/tracker-read.c
index f786c09..9ac4d83 100644
--- a/src/tracker-extract/tracker-read.c
+++ b/src/tracker-extract/tracker-read.c
@@ -26,6 +26,10 @@
#include <glib.h>
#include <gio/gio.h>
+#ifdef HAVE_POSIX_FADVISE
+#include <gio/gfiledescriptorbased.h>
+#endif /* HAVE_POSIX_FADVISE */
+
#include <libtracker-extract/tracker-extract.h>
#include "tracker-read.h"
@@ -167,8 +171,8 @@ process_whole_string (GString *s,
**/
gchar *
tracker_read_text_from_stream (GInputStream *stream,
- gsize max_bytes,
- gboolean try_locale_if_not_utf8)
+ gsize max_bytes,
+ gboolean try_locale_if_not_utf8)
{
GString *s = NULL;
gsize n_bytes_remaining = max_bytes;
@@ -176,6 +180,19 @@ tracker_read_text_from_stream (GInputStream *stream,
g_return_val_if_fail (stream, NULL);
g_return_val_if_fail (max_bytes > 0, NULL);
+#ifdef HAVE_POSIX_FADVISE
+ if (G_IS_FILE_DESCRIPTOR_BASED (stream)) {
+ int fd;
+
+ fd = g_file_descriptor_based_get_fd (G_FILE_DESCRIPTOR_BASED (stream));
+
+ if (fd > 0) {
+ posix_fadvise (fd, 0, max_bytes, POSIX_FADV_SEQUENTIAL);
+ }
+ }
+#endif /* HAVE_POSIX_FADVISE */
+
+
/* Reading in chunks of BUFFER_SIZE
* Loop is halted whenever one of this conditions is met:
* a) Read bytes reached the maximum allowed (max_bytes)
@@ -246,6 +263,10 @@ tracker_read_text_from_fd (gint fd,
return NULL;
}
+#ifdef HAVE_POSIX_FADVISE
+ posix_fadvise (fd, 0, max_bytes, POSIX_FADV_SEQUENTIAL);
+#endif /* HAVE_POSIX_FADVISE */
+
/* Reading in chunks of BUFFER_SIZE
* Loop is halted whenever one of this conditions is met:
* a) Read bytes reached the maximum allowed (max_bytes)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]