コード例 #1
0
ファイル: cifsiostat.c プロジェクト: gavinlin/sysstat-android
/*
 ***************************************************************************
 * Allocate and init structures, according to system state.
 ***************************************************************************
 */
void io_sys_init(void)
{
	int i;
	
	/* How many processors on this machine? */
	cpu_nr = get_cpu_nr(~0);

	/* Get number of CIFS directories in /proc/fs/cifs/Stats */
	if ((cifs_nr = get_cifs_nr()) > 0) {
		cifs_nr += NR_CIFS_PREALLOC;
	}
	if ((st_hdr_cifs = (struct io_hdr_stats *) calloc(cifs_nr, IO_HDR_STATS_SIZE)) == NULL) {
		perror("malloc");
		exit(4);
	}
	
	/* Allocate structures for number of CIFS directories found */
	for (i = 0; i < 2; i++) {
		if ((st_cifs[i] =
		    (struct cifs_stats *) calloc(cifs_nr, CIFS_STATS_SIZE)) == NULL) {
			perror("malloc");
			exit(4);
		}
	}
}
コード例 #2
0
ファイル: nfsiostat.c プロジェクト: alemic/sysstat
/*
 ***************************************************************************
 * Allocate and init structures, according to system state.
 ***************************************************************************
 */
void io_sys_init(void)
{
	int i;
	
	/* How many processors on this machine? */
	cpu_nr = get_cpu_nr(~0, FALSE);

	/* Get number of NFS directories in /proc/self/mountstats */
	if ((ionfs_nr = get_nfs_mount_nr()) > 0) {
		ionfs_nr += NR_NFS_PREALLOC;
	}
	if ((st_hdr_ionfs = (struct io_hdr_stats *) calloc(ionfs_nr, IO_HDR_STATS_SIZE)) == NULL) {
		perror("malloc");
		exit(4);
	}
	
	/* Allocate structures for number of NFS directories found */
	for (i = 0; i < 2; i++) {
		if ((st_ionfs[i] =
		    (struct io_nfs_stats *) calloc(ionfs_nr, IO_NFS_STATS_SIZE)) == NULL) {
			perror("malloc");
			exit(4);
		}
	}
}
コード例 #3
0
ファイル: iostat.c プロジェクト: jimis/sysstat
/*
 ***************************************************************************
 * Allocate and init structures, according to system state.
 ***************************************************************************
 */
void io_sys_init(void)
{
	/* Allocate and init stat common counters */
	init_stats();

	/* How many processors on this machine? */
	cpu_nr = get_cpu_nr(~0, FALSE);

	/* Get number of block devices and partitions in /proc/diskstats */
	if ((iodev_nr = get_diskstats_dev_nr(CNT_PART, CNT_ALL_DEV)) > 0) {
		flags |= I_F_HAS_DISKSTATS;
		iodev_nr += NR_DEV_PREALLOC;
	}

	if (!HAS_DISKSTATS(flags) ||
	    (DISPLAY_PARTITIONS(flags) && !DISPLAY_PART_ALL(flags))) {
		/*
		 * If /proc/diskstats exists but we also want stats for the partitions
		 * of a particular device, stats will have to be found in /sys. So we
		 * need to know if /sys is mounted or not, and set flags accordingly.
		 */

		/* Get number of block devices (and partitions) in sysfs */
		if ((iodev_nr = get_sysfs_dev_nr(DISPLAY_PARTITIONS(flags))) > 0) {
			flags |= I_F_HAS_SYSFS;
			iodev_nr += NR_DEV_PREALLOC;
		}
		else {
			fprintf(stderr, _("Cannot find disk data\n"));
			exit(2);
		}
	}

	/* Also allocate stat structures for "group" devices */
	iodev_nr += group_nr;

	/*
	 * Allocate structures for number of disks found, but also
	 * for groups of devices if option -g has been entered on the command line.
	 * iodev_nr must be <> 0.
	 */
	salloc_device(iodev_nr);
}
コード例 #4
0
ファイル: iostat.c プロジェクト: likev/CodeOrpgPub
/*
 ***************************************************************************
 * Allocate and init structures, according to system state
 ***************************************************************************
 */
void io_sys_init(int *flags)
{
   int i;

   /* Init stat common counters */
   init_stats();

   /* How many processors on this machine ? */
   cpu_nr = get_cpu_nr(~0);

   /* Get number of block devices and partitions in /proc/diskstats */
   if ((iodev_nr = get_diskstats_dev_nr(CNT_PART, CNT_ALL_DEV)) > 0) {
      *flags |= I_F_HAS_DISKSTATS;
      iodev_nr += NR_DEV_PREALLOC;
   }

   if (!HAS_DISKSTATS(*flags) ||
       (DISPLAY_PARTITIONS(*flags) && !DISPLAY_PART_ALL(*flags))) {
      /*
       * If /proc/diskstats exists but we also want stats for the partitions
       * of a particular device, stats will have to be found in /sys. So we
       * need to know if /sys is mounted or not, and set *flags accordingly.
       */

      /* Get number of block devices (and partitions) in sysfs */
      if ((iodev_nr = get_sysfs_dev_nr(DISPLAY_PARTITIONS(*flags))) > 0) {
	 *flags |= I_F_HAS_SYSFS;
	 iodev_nr += NR_DEV_PREALLOC;
      }
      /*
       * Get number of block devices and partitions in /proc/partitions,
       * those with statistics...
       */
      else if ((iodev_nr = get_ppartitions_dev_nr(CNT_PART)) > 0) {
	 *flags |= I_F_HAS_PPARTITIONS;
	 iodev_nr += NR_DEV_PREALLOC;
      }
      /* Get number of "disk_io:" entries in /proc/stat */
      else if ((iodev_nr = get_disk_io_nr()) > 0) {
	 *flags |= I_F_PLAIN_KERNEL24;
	 iodev_nr += NR_DISK_PREALLOC;
      }
      else {
	 /* Assume we have an old kernel: stats for 4 disks are in /proc/stat */
	 iodev_nr = 4;
	 *flags |= I_F_OLD_KERNEL;
      }
   }
   /*
    * Allocate structures for number of disks found.
    * iodev_nr must be <> 0.
    */
   salloc_device(iodev_nr);

   if (HAS_OLD_KERNEL(*flags)) {
      struct io_hdr_stats *shi = st_hdr_iodev;
      /*
       * If we have an old kernel with the stats for the first four disks
       * in /proc/stat, then set the devices names to hdisk[0..3].
       */
      for (i = 0; i < 4; i++, shi++) {
	 shi->used = TRUE;
	 sprintf(shi->name, "%s%d", K_HDISK, i);
      }
   }
}
コード例 #5
0
ファイル: sa_wrap.c プロジェクト: Embedded-linux/sysstat
/*
 ***************************************************************************
 * Compute number of CPU structures to allocate.
 *
 * IN:
 * @a	Activity structure.
 *
 * RETURNS:
 * Number of structures (value in [1, NR_CPUS + 1]).
 * 1 means that there is only one proc and non SMP kernel.
 * 2 means one proc and SMP kernel.
 * Etc.
 ***************************************************************************
 */
__nr_t wrap_get_cpu_nr(struct activity *a)
{
	return (get_cpu_nr(a->bitmap->b_size, FALSE) + 1);
}