static int status_stat (void) { TrackerSparqlConnection *connection; TrackerSparqlCursor *cursor; GError *error = NULL; connection = tracker_sparql_connection_get (NULL, &error); if (!connection) { g_printerr ("%s: %s\n", _("Could not establish a connection to Tracker"), error ? error->message : _("No error given")); g_clear_error (&error); return EXIT_FAILURE; } cursor = tracker_sparql_connection_statistics (connection, NULL, &error); g_object_unref (connection); if (error) { g_printerr ("%s, %s\n", _("Could not get Tracker statistics"), error->message); g_error_free (error); return EXIT_FAILURE; } /* We use search terms on ALL ontologies not just common ones */ if (terms && g_strv_length (terms) > 0) { show_all = TRUE; } if (!cursor) { g_print ("%s\n", _("No statistics available")); } else { GString *output; output = g_string_new (""); if (!show_all) { get_common_rdf_types (); } while (tracker_sparql_cursor_next (cursor, NULL, NULL)) { const gchar *rdf_type; const gchar *rdf_type_count; rdf_type = tracker_sparql_cursor_get_string (cursor, 0, NULL); rdf_type_count = tracker_sparql_cursor_get_string (cursor, 1, NULL); if (!show_all && !g_hash_table_contains (common_rdf_types, rdf_type)) { continue; } if (terms) { gint i, n_terms; gboolean show_rdf_type = FALSE; n_terms = g_strv_length (terms); for (i = 0; i < n_terms && !show_rdf_type; i++) { show_rdf_type = g_str_match_string (terms[i], rdf_type, TRUE); } if (!show_rdf_type) { continue; } } g_string_append_printf (output, " %s = %s\n", rdf_type, rdf_type_count); } if (output->len > 0) { /* To translators: This is to say there are no * statistics found. We use a "Statistics: * None" with multiple print statements */ g_string_prepend (output, "\n"); g_string_prepend (output, _("Statistics:")); } else { g_string_append_printf (output, " %s\n", _("None")); } g_print ("%s\n", output->str); g_string_free (output, TRUE); if (common_rdf_types) { g_hash_table_unref (common_rdf_types); } g_object_unref (cursor); } return EXIT_SUCCESS; }
static int collect_debug (void) { /* What to collect? * This is based on information usually requested from maintainers to users. * * 1. Package details, e.g. version. * 2. Disk size, space left, type (SSD/etc) * 3. Size of dataset (tracker-stats), size of databases * 4. Current configuration (libtracker-fts, tracker-miner-fs, tracker-extract) * All txt files in ~/.cache/ * 5. Statistics about data (tracker-stats) */ GDir *d; gchar *data_dir; gchar *str; data_dir = g_build_filename (g_get_user_cache_dir (), "tracker", NULL); /* 1. Package details, e.g. version. */ g_print ("[Package Details]\n"); g_print ("%s: " PACKAGE_VERSION "\n", _("Version")); g_print ("\n\n"); /* 2. Disk size, space left, type (SSD/etc) */ guint64 remaining_bytes; gdouble remaining; g_print ("[%s]\n", _("Disk Information")); remaining_bytes = tracker_file_system_get_remaining_space (data_dir); str = g_format_size (remaining_bytes); remaining = tracker_file_system_get_remaining_space_percentage (data_dir); g_print ("%s: %s (%3.2lf%%)\n", _("Remaining space on database partition"), str, remaining); g_free (str); g_print ("\n\n"); /* 3. Size of dataset (tracker-stats), size of databases */ g_print ("[%s]\n", _("Data Set")); for (d = g_dir_open (data_dir, 0, NULL); d != NULL;) { const gchar *f; gchar *path; goffset size; f = g_dir_read_name (d); if (!f) { break; } if (g_str_has_suffix (f, ".txt")) { continue; } path = g_build_filename (data_dir, f, NULL); size = tracker_file_get_size (path); str = g_format_size (size); g_print ("%s\n%s\n\n", path, str); g_free (str); g_free (path); } g_dir_close (d); g_print ("\n"); /* 4. Current configuration (libtracker-fts, tracker-miner-fs, tracker-extract) * All txt files in ~/.cache/ */ GSList *all, *l; g_print ("[%s]\n", _("Configuration")); all = tracker_gsettings_get_all (NULL); if (all) { for (l = all; l; l = l->next) { ComponentGSettings *c = l->data; gchar **keys, **p; if (!c) { continue; } keys = g_settings_list_keys (c->settings); for (p = keys; p && *p; p++) { GVariant *v; gchar *printed; v = g_settings_get_value (c->settings, *p); printed = g_variant_print (v, FALSE); g_print ("%s.%s: %s\n", c->name, *p, printed); g_free (printed); g_variant_unref (v); } } tracker_gsettings_free (all); } else { g_print ("** %s **\n", _("No configuration was found")); } g_print ("\n\n"); g_print ("[%s]\n", _("States")); for (d = g_dir_open (data_dir, 0, NULL); d != NULL;) { const gchar *f; gchar *path; gchar *content = NULL; f = g_dir_read_name (d); if (!f) { break; } if (!g_str_has_suffix (f, ".txt")) { continue; } path = g_build_filename (data_dir, f, NULL); if (g_file_get_contents (path, &content, NULL, NULL)) { /* Special case last-index.txt which is time() dump to file */ if (g_str_has_suffix (path, "last-crawl.txt")) { guint64 then, now; now = (guint64) time (NULL); then = g_ascii_strtoull (content, NULL, 10); str = tracker_seconds_to_string (now - then, FALSE); g_print ("%s\n%s (%s)\n\n", path, content, str); } else { g_print ("%s\n%s\n\n", path, content); } g_free (content); } g_free (path); } g_dir_close (d); g_print ("\n"); /* 5. Statistics about data (tracker-stats) */ TrackerSparqlConnection *connection; GError *error = NULL; g_print ("[%s]\n", _("Data Statistics")); connection = tracker_sparql_connection_get (NULL, &error); if (!connection) { g_print ("** %s, %s **\n", _("No connection available"), error ? error->message : _("No error given")); g_clear_error (&error); } else { TrackerSparqlCursor *cursor; cursor = tracker_sparql_connection_statistics (connection, NULL, &error); if (error) { g_print ("** %s, %s **\n", _("Could not get statistics"), error ? error->message : _("No error given")); g_error_free (error); } else { if (!cursor) { g_print ("** %s **\n", _("No statistics were available")); } else { gint count = 0; while (tracker_sparql_cursor_next (cursor, NULL, NULL)) { g_print ("%s: %s\n", tracker_sparql_cursor_get_string (cursor, 0, NULL), tracker_sparql_cursor_get_string (cursor, 1, NULL)); count++; } if (count == 0) { g_print ("%s\n", _("Database is currently empty")); } g_object_unref (cursor); } } } g_object_unref (connection); g_print ("\n\n"); g_print ("\n"); g_free (data_dir); return EXIT_SUCCESS; }
int main (int argc, char **argv) { TrackerSparqlConnection *connection; TrackerSparqlCursor *cursor; GOptionContext *context; GError *error = NULL; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Translators: this messagge will apper immediately after the */ /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE> */ context = g_option_context_new (_(" - Show statistics for all Nepomuk defined ontology classes")); g_option_context_add_main_entries (context, entries, NULL); g_option_context_parse (context, &argc, &argv, NULL); if (print_version) { g_print ("\n" ABOUT "\n" LICENSE "\n"); g_option_context_free (context); return EXIT_SUCCESS; } /* We use search terms on ALL ontologies not just common ones */ if (terms && g_strv_length (terms) > 0) { show_all = TRUE; } g_option_context_free (context); connection = tracker_sparql_connection_get (NULL, &error); if (!connection) { g_printerr ("%s: %s\n", _("Could not establish a connection to Tracker"), error ? error->message : _("No error given")); g_clear_error (&error); return EXIT_FAILURE; } cursor = tracker_sparql_connection_statistics (connection, NULL, &error); if (error) { g_printerr ("%s, %s\n", _("Could not get Tracker statistics"), error->message); g_error_free (error); return EXIT_FAILURE; } if (!cursor) { g_print ("%s\n", _("No statistics available")); } else { GString *output; output = g_string_new (""); if (!show_all) { get_common_rdf_types (); } while (tracker_sparql_cursor_next (cursor, NULL, NULL)) { const gchar *rdf_type; const gchar *rdf_type_count; rdf_type = tracker_sparql_cursor_get_string (cursor, 0, NULL); rdf_type_count = tracker_sparql_cursor_get_string (cursor, 1, NULL); if (!show_all && !g_hash_table_contains (common_rdf_types, rdf_type)) { continue; } if (terms) { gint i, n_terms; gboolean show_rdf_type = FALSE; n_terms = g_strv_length (terms); for (i = 0; i < n_terms && !show_rdf_type; i++) { show_rdf_type = g_str_match_string (terms[i], rdf_type, TRUE); } if (!show_rdf_type) { continue; } } g_string_append_printf (output, " %s = %s\n", rdf_type, rdf_type_count); } if (output->len > 0) { /* To translators: This is to say there are no * statistics found. We use a "Statistics: * None" with multiple print statements */ g_string_prepend (output, "\n"); g_string_prepend (output, _("Statistics:")); } else { g_string_append_printf (output, " %s\n", _("None")); } g_print ("%s\n", output->str); g_string_free (output, TRUE); if (common_rdf_types) { g_hash_table_unref (common_rdf_types); } g_object_unref (cursor); } g_object_unref (connection); return EXIT_SUCCESS; }