Ankkaserver


    __
  >(' )
    )/
    /(
   /  `----/
   \  ~=- /
 ~^~^~^~^~^~^~^
Navigointi
Etusivu
PhpSysInfo
~sami/
Blogi
vnstat
Ladattavaa
Virityksiä
Muuta
Linkkejä
Monsujen tappopeli
Vieraskirja
Chat

Kernelin lukunopeuden testausohjelma

Tämä ohjelma lukee tiedostoa käyttäjän määrittelemässä blokkikoossa, kunnes tietty määrä blokkeja on luettu. Sen jälkeen ohjelma ilmoittaa läpisyötön, jolla dataa saatiin siirrettyä.

Ohjelman käynnistyksen syntaksi on seuraava:
readtest [tiedosto] [blokkikoko] [blokkien määrä]

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
  int fd;
  int rc;
  unsigned block_size;
  unsigned long read_count;
  void *buffer;
  unsigned char update;
  unsigned long n;
  time_t start_time;
  time_t seconds;
  double kilobytes, megabytes;
  unsigned long long read_bytes;

  if(argc < 4)
  {
    puts("readtest [file] [block size] [count]");
    return 1;
  }

#ifdef DOS
  fd = open(argv[1], O_RDONLY | O_BINARY, S_IRUSR);
#else
  fd = open(argv[1], O_RDONLY, S_IRUSR);
#endif
  if(fd == -1)
  {
    printf("Could not open file %s\n", argv[1]);
    return 2;
  }

  block_size = atoi(argv[2]);
  n = read_count = atol(argv[3]);

  buffer = malloc(block_size);
  if(!buffer)
  {
    printf("Error! Could not allocate a buffer of %u bytes.\n", block_size);
    return 3;
  }

  printf("Reading %lu blocks of %u bytes from %s.\n", read_count, block_size, argv[1]);

  start_time = time(0);

  while(n--)
  {
    rc = read(fd, buffer, block_size);
    if(rc != block_size) break;

    if(!update--)
    {
      printf("\r%llu bytes read", (read_count-n)*(unsigned long long)block_size);
    }
  }

  seconds = time(0)-start_time;
  read_bytes = (read_count-n-1)*(unsigned long long)block_size+rc;
  kilobytes = read_bytes>>10;
  megabytes = kilobytes/1024;


  if(seconds)
  {
    printf("\r%llu bytes read in %lu seconds (%llu bytes per second, ", read_bytes, seconds,
         read_bytes/seconds);
    printf("%g %sbytes per second)\n", (megabytes>10 ? megabytes : kilobytes) / seconds, megabytes>10 ? "mega" : "kilo");
  }

  return 0;
}

 05:31:55 up 394 days,  8:12,  2 users,  load average: 0.00, 0.00, 0.00
               total        used        free      shared  buff/cache   available
Mem:             493         147          48           9         298         323
Swap:            486         150         336

Valid HTML 4.01 Strict Valid CSS!

http://sininenankka.dy.fi
Tietoja ylläpitäjästä

Sivun generointi kesti 0.652 s