Exemple #1
0
void
baobab_get_filesystem (BaobabFS *fs)
{
	size_t i;
	glibtop_mountlist mountlist;
	glibtop_mountentry *mountentries;

	memset (fs, 0, sizeof *fs);

	mountentries = glibtop_get_mountlist (&mountlist, FALSE);

	for (i = 0; i < mountlist.number; ++i) {
		GFile *file;
		glibtop_fsusage fsusage;

		file = g_file_new_for_path (mountentries[i].mountdir);

		if (!baobab_is_excluded_location (file)) {

			glibtop_get_fsusage (&fsusage, mountentries[i].mountdir);

			fs->total += fsusage.blocks * fsusage.block_size;
			fs->avail += fsusage.bfree * fsusage.block_size;
			fs->used += (fsusage.blocks - fsusage.bfree) * fsusage.block_size;
		}

		g_object_unref (file);
	}

	g_free (mountentries);
}
Exemple #2
0
static PyObject* gtop_fsusage(PyObject *self, PyObject *args)
{

	glibtop_fsusage buf;
	const char *mount_dir;
	PyObject *d;

	if(!PyArg_ParseTuple(args, "s", &mount_dir))
		return NULL;

	glibtop_get_fsusage(&buf, mount_dir);

	d = PyDict_New();

	/* (x * block_size) may overflow ?
	 * mult should be done with PyLong
	 * but who has a PB harddrive ?
	 */

	my_dict_add_and_decref(d, "total", PyL_ULL(buf.blocks * buf.block_size));
	my_dict_add_and_decref(d, "free",  PyL_ULL(buf.bfree  * buf.block_size));
	my_dict_add_and_decref(d, "avail", PyL_ULL(buf.bavail * buf.block_size));

	my_dict_add_and_decref(d, "files", PyL_ULL(buf.files));
	my_dict_add_and_decref(d, "ffree", PyL_ULL(buf.ffree));

	my_dict_add_and_decref(d, "block_size", PyL_ULL(buf.block_size));

	my_dict_add_and_decref(d, "read",  PyL_ULL(buf.read));
	my_dict_add_and_decref(d, "write", PyL_ULL(buf.write));

	return _struct_new(d);
}
Exemple #3
0
void
GetDiskLoad (int Maximum, int data [3], LoadGraph *g)
{
	static gboolean first_call = TRUE;
	static guint64 lastread = 0, lastwrite = 0;
	static AutoScaler scaler;

	glibtop_mountlist mountlist;
	glibtop_mountentry *mountentries;
	guint i;
	int max;

	guint64 read, write;
	guint64 readdiff, writediff;


	if(first_call)
	{
	    autoscaler_init(&scaler, 60, 500);
	}

	read = write = 0;

	mountentries = glibtop_get_mountlist (&mountlist, FALSE);

	for (i = 0; i < mountlist.number; i++)
	{
		glibtop_fsusage fsusage;

		if (strcmp(mountentries[i].type, "smbfs") == 0
		    || strcmp(mountentries[i].type, "nfs") == 0
		    || strcmp(mountentries[i].type, "cifs") == 0)
			continue;

		glibtop_get_fsusage(&fsusage, mountentries[i].mountdir);
		read += fsusage.read; write += fsusage.write;
	}

	g_free(mountentries);

	readdiff  = read - lastread;
	writediff = write - lastwrite;

	lastread  = read;
	lastwrite = write;

	if(first_call)
	{
		first_call = FALSE;
		memset(data, 0, 3 * sizeof data[0]);
		return;
	}

	max = autoscaler_get_max(&scaler, readdiff + writediff);

	data[0] = (float)Maximum *  readdiff / (float)max;
	data[1] = (float)Maximum * writediff / (float)max;
	data[2] = (float)Maximum - (data [0] + data[1]);
}
Exemple #4
0
static void
fill_props_model (GtkListStore *store)
{
	GtkTreeIter iter;
	guint lo;
	glibtop_mountlist mountlist;
	glibtop_mountentry *mountentry, *mountentry_tofree;
	guint64 fstotal, fsavail;

	mountentry_tofree = glibtop_get_mountlist (&mountlist, 0);

	for (lo = 0, mountentry = mountentry_tofree;
	     lo < mountlist.number;
	     lo++, mountentry++) {
		glibtop_fsusage fsusage;
		gchar * total, *avail;
		GFile *file;
		gchar *uri;
		gboolean excluded;

		struct stat buf;
		if (g_stat (mountentry->devname,&buf) == -1)
			continue;

		glibtop_get_fsusage (&fsusage, mountentry->mountdir);
		fstotal = fsusage.blocks * fsusage.block_size;
		fsavail = fsusage.bfree * fsusage.block_size;
		
			total = g_format_size(fstotal);
			avail = g_format_size(fsavail);
		
		file = g_file_new_for_path (mountentry->mountdir);
		uri = g_file_get_uri (file);
		excluded = baobab_is_excluded_location (file);

		gtk_list_store_append (store, &iter);
		gtk_list_store_set (store, &iter,
				    COL_CHECK, !excluded,
				    COL_DEVICE, mountentry->devname,
				    COL_MOUNT_D, mountentry->mountdir,
				    COL_MOUNT, uri,
				    COL_TYPE, mountentry->type,
				    COL_FS_SIZE, total,
				    COL_FS_AVAIL, avail,
				    -1);
		g_free(total);
		g_free(avail);
		g_free(uri);
		g_object_unref(file);
	}

	g_free (mountentry_tofree);
}
Exemple #5
0
static void pprint_get_fsusage(const char *mountpoint)
{
  glibtop_fsusage buf;

  glibtop_get_fsusage(&buf, mountpoint);

  HEADER_PPRINT(glibtop_get_fsusage);
  printf("pprint_get_fsusage (mountpoint = \"%s\"\n", mountpoint);
  PPRINT(flags, "%#llx");
  PPRINT(blocks, "%llu");
  PPRINT(bfree, "%llu");
  PPRINT(bavail, "%llu");
  PPRINT(files, "%llu");
  PPRINT(ffree, "%llu");
  PPRINT(block_size, "%u");
  PPRINT(read, "%llu");
  PPRINT(write, "%llu");
  FOOTER_PPRINT();
}
static void
add_disk(GtkListStore *list, const glibtop_mountentry *entry, bool show_all_fs)
{
	Glib::RefPtr<Gdk::Pixbuf> pixbuf;
	GtkTreeIter iter;
	glibtop_fsusage usage;
	guint64 bused, bfree, bavail, btotal;
	gint percentage;

	glibtop_get_fsusage(&usage, entry->mountdir);

	if (not show_all_fs and usage.blocks == 0) {
		if (find_disk_in_model(GTK_TREE_MODEL(list), entry->mountdir, &iter))
			gtk_list_store_remove(list, &iter);
		return;
	}

	fsusage_stats(&usage, &bused, &bfree, &bavail, &btotal, &percentage);
	pixbuf = get_icon_for_device(entry->mountdir);

	/* if we can find a row with the same mountpoint, we get it but we
	   still need to update all the fields.
	   This makes selection persistent.
	*/
	if (!find_disk_in_model(GTK_TREE_MODEL(list), entry->mountdir, &iter))
		gtk_list_store_append(list, &iter);

	gtk_list_store_set(list, &iter,
			   DISK_ICON, pixbuf->gobj(),
			   DISK_DEVICE, entry->devname,
			   DISK_DIR, entry->mountdir,
			   DISK_TYPE, entry->type,
			   DISK_USED_PERCENTAGE, percentage,
			   DISK_TOTAL, btotal,
			   DISK_FREE, bfree,
			   DISK_AVAIL, bavail,
			   DISK_USED, bused,
			   -1);
}
Exemple #7
0
int
main (int argc, char *argv [])
{
	glibtop_fsusage fsusage;
	glibtop_mountlist mount_list;
	glibtop_mountentry *mount_entries;
	unsigned c, index, method, count, port;
	char buffer [BUFSIZ];

	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, GTOPLOCALEDIR);
	textdomain (GETTEXT_PACKAGE);

	glibtop_init_r (&glibtop_global_server, 0, GLIBTOP_INIT_NO_OPEN);

	glibtop_get_parameter (GLIBTOP_PARAM_METHOD, &method, sizeof (method));

	printf ("Method = %d\n", method);

	count = glibtop_get_parameter (GLIBTOP_PARAM_COMMAND, buffer, BUFSIZ);
	buffer [count] = 0;

	printf ("Command = '%s'\n", buffer);

	count = glibtop_get_parameter (GLIBTOP_PARAM_HOST, buffer, BUFSIZ);
	buffer [count] = 0;

	glibtop_get_parameter (GLIBTOP_PARAM_PORT, &port, sizeof (port));

	printf ("Host = '%s' - %u\n\n", buffer, port);

	printf ("sbrk (0) = %p\n\n", sbrk (0));

	for (c = 0; c < PROFILE_COUNT; c++) {
		mount_entries = glibtop_get_mountlist (&mount_list, 1);

		g_free (mount_entries);
	}

	printf ("sbrk (0) = %p\n\n", sbrk (0));

	mount_entries = glibtop_get_mountlist (&mount_list, 1);

	if (mount_entries == NULL)
		_exit (1);

	for (index = 0; index < mount_list.number; index++)
		printf ("Mount_Entry: %-30s %-10s %-20s\n",
			mount_entries [index].mountdir,
			mount_entries [index].type,
			mount_entries [index].devname);

	printf ("\n\n%-16s %9s %9s %9s %9s %9s %9s\n",
		"Mount", "Blocks", "Free", "Avail", "Files", "Free", "BlockSz");

	for (index = 0; index < mount_list.number; index++) {
		glibtop_get_fsusage (&fsusage,
				     mount_entries [index].mountdir);

		printf ("%-16s %9Lu %9Lu %9Lu %9Lu %9Lu %9d\n",
			mount_entries [index].mountdir,
			fsusage.blocks, fsusage.bfree,
			fsusage.bavail, fsusage.files,
			fsusage.ffree, fsusage.block_size);
	}

	g_free (mount_entries);

	printf ("\nsbrk (0) = %p\n\n", sbrk (0));

	glibtop_close ();

	exit (0);
}