Commit d8d8686d authored by Martyn Russell's avatar Martyn Russell Committed by Jürg Billeter

Added more information about module use to tracker-extract

* src/tracker-extract/tracker-extract.c: Added debugging so we know
  which modules are loaded on start up and to know which modules are
  used to extract content on a per file basis to help when we have
  multiple extractors handling the same mime types.

* src/tracker-extract/tracker-main.c: Change logging format when
  running stand alone and not writing to a log file and don't log
  everything, only log based on the verbosity setting.
parent a3a65d67
...@@ -40,9 +40,15 @@ ...@@ -40,9 +40,15 @@
#define TRACKER_EXTRACT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_EXTRACT, TrackerExtractPrivate)) #define TRACKER_EXTRACT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_EXTRACT, TrackerExtractPrivate))
typedef struct { typedef struct {
GArray *extractors; GArray *specific_extractors;
GArray *generic_extractors;
} TrackerExtractPrivate; } TrackerExtractPrivate;
typedef struct {
const GModule *module;
const TrackerExtractData *edata;
} ModuleData;
static void tracker_extract_finalize (GObject *object); static void tracker_extract_finalize (GObject *object);
G_DEFINE_TYPE(TrackerExtract, tracker_extract, G_TYPE_OBJECT) G_DEFINE_TYPE(TrackerExtract, tracker_extract, G_TYPE_OBJECT)
...@@ -78,7 +84,8 @@ tracker_extract_finalize (GObject *object) ...@@ -78,7 +84,8 @@ tracker_extract_finalize (GObject *object)
tracker_topanalyzer_shutdown (); tracker_topanalyzer_shutdown ();
#endif #endif
g_array_free (priv->extractors, TRUE); g_array_free (priv->specific_extractors, TRUE);
g_array_free (priv->generic_extractors, TRUE);
G_OBJECT_CLASS (tracker_extract_parent_class)->finalize (object); G_OBJECT_CLASS (tracker_extract_parent_class)->finalize (object);
} }
...@@ -102,7 +109,7 @@ tracker_extract_new (void) ...@@ -102,7 +109,7 @@ tracker_extract_new (void)
GDir *dir; GDir *dir;
GError *error; GError *error;
const gchar *name; const gchar *name;
GArray *extractors; GArray *specific_extractors;
GArray *generic_extractors; GArray *generic_extractors;
if (!g_module_supported ()) { if (!g_module_supported ()) {
...@@ -110,33 +117,25 @@ tracker_extract_new (void) ...@@ -110,33 +117,25 @@ tracker_extract_new (void)
return NULL; return NULL;
} }
extractors = g_array_sized_new (FALSE,
TRUE,
sizeof (TrackerExtractData),
10);
/* This array is going to be used to store
* temporarily extractors with mimetypes such as "audio / *"
*/
generic_extractors = g_array_sized_new (FALSE,
TRUE,
sizeof (TrackerExtractData),
10);
error = NULL; error = NULL;
dir = g_dir_open (MODULESDIR, 0, &error); dir = g_dir_open (MODULESDIR, 0, &error);
if (!dir) { if (!dir) {
g_error ("Error opening modules directory: %s", error->message); g_error ("Error opening modules directory: %s", error->message);
g_error_free (error); g_error_free (error);
g_array_free (generic_extractors, TRUE);
g_array_free (extractors, TRUE);
return NULL; return NULL;
} }
specific_extractors = g_array_new (FALSE,
TRUE,
sizeof (ModuleData));
generic_extractors = g_array_new (FALSE,
TRUE,
sizeof (ModuleData));
while ((name = g_dir_read_name (dir)) != NULL) { while ((name = g_dir_read_name (dir)) != NULL) {
TrackerExtractDataFunc func; TrackerExtractDataFunc func;
TrackerExtractData *data;
GModule *module; GModule *module;
gchar *module_path; gchar *module_path;
...@@ -149,7 +148,9 @@ tracker_extract_new (void) ...@@ -149,7 +148,9 @@ tracker_extract_new (void)
module = g_module_open (module_path, G_MODULE_BIND_LOCAL); module = g_module_open (module_path, G_MODULE_BIND_LOCAL);
if (!module) { if (!module) {
g_warning ("Could not load module '%s': %s", name, g_module_error ()); g_warning ("Could not load module '%s': %s",
name,
g_module_error ());
g_free (module_path); g_free (module_path);
continue; continue;
} }
...@@ -157,13 +158,23 @@ tracker_extract_new (void) ...@@ -157,13 +158,23 @@ tracker_extract_new (void)
g_module_make_resident (module); g_module_make_resident (module);
if (g_module_symbol (module, "tracker_get_extract_data", (gpointer *) &func)) { if (g_module_symbol (module, "tracker_get_extract_data", (gpointer *) &func)) {
data = (func) (); ModuleData mdata;
mdata.module = module;
mdata.edata = (func) ();
for (; data->mime; data++) { g_message ("Adding extractor:'%s' with:",
if (strchr (data->mime, '*') != NULL) { g_module_name ((GModule*) mdata.module));
g_array_append_val (generic_extractors, *data);
for (; mdata.edata->mime; mdata.edata++) {
if (G_UNLIKELY (strchr (mdata.edata->mime, '*') != NULL)) {
g_message (" Generic match for mime:'%s'",
mdata.edata->mime);
g_array_append_val (generic_extractors, mdata);
} else { } else {
g_array_append_val (extractors, *data); g_message (" Specific match for mime:'%s'",
mdata.edata->mime);
g_array_append_val (specific_extractors, mdata);
} }
} }
} }
...@@ -173,20 +184,13 @@ tracker_extract_new (void) ...@@ -173,20 +184,13 @@ tracker_extract_new (void)
g_dir_close (dir); g_dir_close (dir);
/* Append the generic extractors at the end of
* the list, so the specific ones are used first
*/
g_array_append_vals (extractors,
generic_extractors->data,
generic_extractors->len);
g_array_free (generic_extractors, TRUE);
/* Set extractors */ /* Set extractors */
object = g_object_new (TRACKER_TYPE_EXTRACT, NULL); object = g_object_new (TRACKER_TYPE_EXTRACT, NULL);
priv = TRACKER_EXTRACT_GET_PRIVATE (object); priv = TRACKER_EXTRACT_GET_PRIVATE (object);
priv->extractors = extractors; priv->specific_extractors = specific_extractors;
priv->generic_extractors = generic_extractors;
return object; return object;
} }
...@@ -303,24 +307,66 @@ get_file_metadata (TrackerExtract *extract, ...@@ -303,24 +307,66 @@ get_file_metadata (TrackerExtract *extract,
*/ */
if (mime_used) { if (mime_used) {
TrackerExtractPrivate *priv; TrackerExtractPrivate *priv;
TrackerExtractData *data;
guint i; guint i;
priv = TRACKER_EXTRACT_GET_PRIVATE (extract); priv = TRACKER_EXTRACT_GET_PRIVATE (extract);
for (i = 0; i < priv->extractors->len; i++) { for (i = 0; i < priv->specific_extractors->len; i++) {
data = &g_array_index (priv->extractors, TrackerExtractData, i); const TrackerExtractData *edata;
ModuleData mdata;
mdata = g_array_index (priv->specific_extractors, ModuleData, i);
edata = mdata.edata;
if (g_pattern_match_simple (edata->mime, mime_used)) {
gint items;
tracker_dbus_request_comment (request_id,
" Extracting with module:'%s'",
g_module_name ((GModule*) mdata.module));
(*edata->extract) (uri, statements);
if (g_pattern_match_simple (data->mime, mime_used)) { items = statements->len;
(*data->extract) (uri, statements);
if (statements->len == 0) { tracker_dbus_request_comment (request_id,
" Found %d metadata items",
items);
if (items == 0) {
continue; continue;
} }
g_free (mime_used);
g_free (content_type);
return statements;
}
}
for (i = 0; i < priv->generic_extractors->len; i++) {
const TrackerExtractData *edata;
ModuleData mdata;
mdata = g_array_index (priv->generic_extractors, ModuleData, i);
edata = mdata.edata;
if (g_pattern_match_simple (edata->mime, mime_used)) {
gint items;
tracker_dbus_request_comment (request_id,
" Extracting with module:'%s'",
g_module_name ((GModule*) mdata.module));
(*edata->extract) (uri, statements);
items = statements->len;
tracker_dbus_request_comment (request_id, tracker_dbus_request_comment (request_id,
" Found %d metadata items", " Found %d metadata items",
statements->len); items);
if (items == 0) {
continue;
}
g_free (mime_used); g_free (mime_used);
g_free (content_type); g_free (content_type);
...@@ -355,12 +401,20 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object, ...@@ -355,12 +401,20 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
g_return_if_fail (uri != NULL); g_return_if_fail (uri != NULL);
tracker_dbus_request_new (request_id,
"Command line request to extract metadata, "
"uri:'%s', mime:%s",
uri,
mime);
/* NOTE: Don't reset the timeout to shutdown here */ /* NOTE: Don't reset the timeout to shutdown here */
statements = get_file_metadata (object, request_id, uri, mime); statements = get_file_metadata (object, request_id, uri, mime);
if (statements) { if (statements) {
statements_free (statements); statements_free (statements);
} }
tracker_dbus_request_success (request_id);
} }
void void
......
...@@ -222,6 +222,37 @@ initialize_signal_handler (void) ...@@ -222,6 +222,37 @@ initialize_signal_handler (void)
#endif /* G_OS_WIN32 */ #endif /* G_OS_WIN32 */
} }
static void
log_handler (const gchar *domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data)
{
if (((log_level & G_LOG_LEVEL_DEBUG) && verbosity < 3) ||
((log_level & G_LOG_LEVEL_INFO) && verbosity < 2) ||
((log_level & G_LOG_LEVEL_MESSAGE) && verbosity < 1)) {
return;
}
switch (log_level) {
case G_LOG_LEVEL_WARNING:
case G_LOG_LEVEL_CRITICAL:
case G_LOG_LEVEL_ERROR:
case G_LOG_FLAG_RECURSION:
case G_LOG_FLAG_FATAL:
g_fprintf (stderr, "%s\n", message);
fflush (stderr);
break;
case G_LOG_LEVEL_MESSAGE:
case G_LOG_LEVEL_INFO:
case G_LOG_LEVEL_DEBUG:
case G_LOG_LEVEL_MASK:
g_fprintf (stdout, "%s\n", message);
fflush (stdout);
break;
}
}
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
...@@ -229,6 +260,8 @@ main (int argc, char *argv[]) ...@@ -229,6 +260,8 @@ main (int argc, char *argv[])
GError *error = NULL; GError *error = NULL;
TrackerConfig *config; TrackerConfig *config;
gchar *log_filename; gchar *log_filename;
gboolean stand_alone = FALSE;
guint log_handler_id = 0;
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
...@@ -283,6 +316,24 @@ main (int argc, char *argv[]) ...@@ -283,6 +316,24 @@ main (int argc, char *argv[])
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
/* Set conditions when we use stand alone settings */
stand_alone |= filename != NULL;
if (stand_alone) {
/* Set log handler for library messages */
log_handler_id = g_log_set_handler (NULL,
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL,
log_handler,
NULL);
g_log_set_default_handler (log_handler, NULL);
/* Set the default verbosity if unset */
if (verbosity == -1) {
verbosity = 3;
}
}
if (filename) { if (filename) {
TrackerExtract *object; TrackerExtract *object;
GFile *file; GFile *file;
...@@ -302,7 +353,7 @@ main (int argc, char *argv[]) ...@@ -302,7 +353,7 @@ main (int argc, char *argv[])
g_object_unref (file); g_object_unref (file);
g_free (uri); g_free (uri);
return EXIT_SUCCESS; goto done;
} }
config = tracker_config_new (); config = tracker_config_new ();
...@@ -361,5 +412,12 @@ main (int argc, char *argv[]) ...@@ -361,5 +412,12 @@ main (int argc, char *argv[])
g_free (log_filename); g_free (log_filename);
g_object_unref (config); g_object_unref (config);
done:
if (log_handler_id != 0) {
/* Unset log handler */
g_log_remove_handler (NULL, log_handler_id);
}
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment