Skip to content

Instantly share code, notes, and snippets.

@dyigitpolat
Created June 22, 2017 09:11
Show Gist options
  • Select an option

  • Save dyigitpolat/8bcfde2f26f5db12a67ed0e9dbbb8e10 to your computer and use it in GitHub Desktop.

Select an option

Save dyigitpolat/8bcfde2f26f5db12a67ed0e9dbbb8e10 to your computer and use it in GitHub Desktop.
#include "stdio.h"
#include "stdlib.h"
long int parse()
{
long int bytes;
char str[4096];
int indexes[10];
char* c;
FILE* f = fopen( "output", "r");
c = str;
while((*(c++) = getc(f)) != EOF); c--;
sscanf( str, "%ld", &bytes);
return bytes;
}
//
// Run by ./a.out fname
// Shows the file size difference with time. Simple!
// You can also check if a download is completed or not
//
int main( int argc, char** argv)
{
char command[4096];
long int bytes1, bytes2;
float mbps;
float avgmbps = 0;
sprintf( command, "stat --printf=%cs %s > output", '%',argv[1]);
int i;
for(i = 0; i < 5; i++)
{
system(command);
bytes1 = parse();
system("rm output");
sleep(1);
system(command);
bytes2 = parse();
system("rm output");
mbps = (bytes2-bytes1) / 1e6;
avgmbps += mbps;
printf( "Current download rate of file %s = %f Mbytes/sec\n", argv[1], mbps);
}
printf( "5 second average = %f Mbytes/sec\n", avgmbps / 5.0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment