gchar * tracker_seconds_estimate_to_string (gdouble seconds_elapsed, gboolean short_string, guint items_done, guint items_remaining) { guint estimate; estimate = tracker_seconds_estimate (seconds_elapsed, items_done, items_remaining); if (estimate == 0) return g_strdup (_("unknown time")); return tracker_seconds_to_string (estimate, short_string); }
static int get_no_args (void) { gchar *str; gchar *data_dir; guint64 remaining_bytes; gdouble remaining; gint remaining_time; gint files, folders; /* How many files / folders do we have? */ if (get_file_and_folder_count (&files, &folders) != 0) { return EXIT_FAILURE; } g_print (_("Currently indexed")); g_print (": "); g_print (g_dngettext (NULL, "%d file", "%d files", files), files); g_print (", "); g_print (g_dngettext (NULL, "%d folders", "%d folders", folders), folders); g_print ("\n"); /* How much space is left? */ data_dir = g_build_filename (g_get_user_cache_dir (), "tracker", NULL); 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_free (data_dir); /* Are we finished indexing? */ if (!are_miners_finished (&remaining_time)) { gchar *remaining_time_str; remaining_time_str = tracker_seconds_to_string (remaining_time, TRUE); g_print ("%s: ", _("Data is still being indexed")); g_print (_("Estimated %s left"), remaining_time_str); g_print ("\n"); g_free (remaining_time_str); } else { g_print ("%s\n", _("All data miners are idle, indexing complete")); } g_print ("\n\n"); 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; }
static void miner_print_state (TrackerMinerManager *manager, const gchar *miner_name, const gchar *status, gdouble progress, gint remaining_time, gboolean is_running, gboolean is_paused) { const gchar *name; time_t now; gchar time_str[64]; size_t len; struct tm *local_time; now = time ((time_t *) NULL); local_time = localtime (&now); len = strftime (time_str, sizeof (time_str) - 1, "%d %b %Y, %H:%M:%S:", local_time); time_str[len] = '\0'; name = tracker_miner_manager_get_display_name (manager, miner_name); if (is_running) { gchar *progress_str = NULL; gchar *remaining_time_str = NULL; if (progress >= 0.0 && progress < 1.0) { progress_str = g_strdup_printf ("%3u%%", (guint)(progress * 100)); } /* Progress > 0.01 here because we want to avoid any message * during crawling, as we don't have the remaining time in that * case and it would just print "unknown time left" */ if (progress > 0.01 && progress < 1.0 && remaining_time >= 0) { /* 0 means that we couldn't properly compute the remaining * time. */ if (remaining_time > 0) { gchar *seconds_str = tracker_seconds_to_string (remaining_time, TRUE); /* Translators: %s is a time string */ remaining_time_str = g_strdup_printf (_("%s remaining"), seconds_str); g_free (seconds_str); } else { remaining_time_str = g_strdup (_("unknown time left")); } } g_print ("%s %s %-*.*s %s%-*.*s%s %s %s %s\n", time_str, progress_str ? progress_str : "✓ ", longest_miner_name_length, longest_miner_name_length, name, is_paused ? "(" : " ", paused_length, paused_length, is_paused ? _("PAUSED") : " ", is_paused ? ")" : " ", status ? "-" : "", status ? _(status) : "", remaining_time_str ? remaining_time_str : ""); g_free (progress_str); g_free (remaining_time_str); } else { g_print ("%s ✗ %-*.*s %-*.*s - %s\n", time_str, longest_miner_name_length, longest_miner_name_length, name, paused_length, paused_length, " ", _("Not running or is a disabled plugin")); } }