benchmarks: added raw_download test
Этот коммит содержится в:
родитель
a2c94abb92
Коммит
5d9cd8bf39
@ -109,13 +109,12 @@ int benchmarks_raw_up (ssh_session session, struct argument_s *args,
|
||||
unsigned long bytes=0x1000000;
|
||||
char *script=get_python_eater(bytes);
|
||||
char cmd[128];
|
||||
char buffer[1024];
|
||||
static char buffer[0x10000];
|
||||
int err;
|
||||
ssh_channel channel;
|
||||
struct timestamp_struct ts;
|
||||
float ms=0.0;
|
||||
unsigned long total=0;
|
||||
(void)bps;
|
||||
|
||||
err=upload_script(session,"/tmp/eater.py",script);
|
||||
free(script);
|
||||
@ -144,8 +143,8 @@ int benchmarks_raw_up (ssh_session session, struct argument_s *args,
|
||||
while(total < bytes){
|
||||
unsigned long towrite = bytes - total;
|
||||
int w;
|
||||
if(towrite > 0x1000)
|
||||
towrite = 0x1000;
|
||||
if(towrite > 0x10000)
|
||||
towrite = 32758;
|
||||
w=ssh_channel_write(channel,buffer,towrite);
|
||||
if(w == SSH_ERROR)
|
||||
goto error;
|
||||
@ -180,3 +179,100 @@ error:
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char python_giver[] =
|
||||
"#!/usr/bin/python\n"
|
||||
"import sys\n"
|
||||
"r=sys.stdin.read(2)\n"
|
||||
"towrite=XXXXXXXXXX\n"
|
||||
"wrote=0\n"
|
||||
"while(wrote < towrite):\n"
|
||||
" buffersize=towrite-wrote\n"
|
||||
" if(buffersize > 4096):\n"
|
||||
" buffersize=4096\n"
|
||||
" sys.stdout.write('A'*buffersize)\n"
|
||||
" wrote+=buffersize\n"
|
||||
"sys.stdout.flush()\n";
|
||||
|
||||
static char *get_python_giver(unsigned long bytes){
|
||||
char *giver=malloc(sizeof(python_giver));
|
||||
char *ptr;
|
||||
char buffer[12];
|
||||
|
||||
memcpy(giver,python_giver,sizeof(python_giver));
|
||||
ptr=strstr(giver,"XXXXXXXXXX");
|
||||
if(!ptr){
|
||||
free(giver);
|
||||
return NULL;
|
||||
}
|
||||
sprintf(buffer,"0x%.8lx",bytes);
|
||||
memcpy(ptr,buffer,10);
|
||||
return giver;
|
||||
}
|
||||
|
||||
/** @internal
|
||||
* @brief benchmarks a raw download (simple upload in a SSH channel) using an
|
||||
* existing SSH session.
|
||||
* @param[in] session Open SSH session
|
||||
* @param[in] args Parsed command line arguments
|
||||
* @param[out] bps The calculated bytes per second obtained via benchmark.
|
||||
* @return 0 on success, -1 on error.
|
||||
*/
|
||||
int benchmarks_raw_down (ssh_session session, struct argument_s *args,
|
||||
float *bps){
|
||||
unsigned long bytes=0x1000000;
|
||||
char *script=get_python_giver(bytes);
|
||||
char cmd[128];
|
||||
static char buffer[0x10000];
|
||||
int err;
|
||||
ssh_channel channel;
|
||||
struct timestamp_struct ts;
|
||||
float ms=0.0;
|
||||
unsigned long total=0;
|
||||
|
||||
err=upload_script(session,"/tmp/giver.py",script);
|
||||
free(script);
|
||||
if(err<0)
|
||||
return err;
|
||||
channel=ssh_channel_new(session);
|
||||
if(channel == NULL)
|
||||
goto error;
|
||||
if(ssh_channel_open_session(channel)==SSH_ERROR)
|
||||
goto error;
|
||||
snprintf(cmd,sizeof(cmd),"%s /tmp/giver.py", PYTHON_PATH);
|
||||
if(ssh_channel_request_exec(channel,cmd)==SSH_ERROR)
|
||||
goto error;
|
||||
if((err=ssh_channel_write(channel,"go",2))==SSH_ERROR)
|
||||
goto error;
|
||||
if(args->verbose>0)
|
||||
fprintf(stdout,"Starting download of %lu bytes now\n",bytes);
|
||||
timestamp_init(&ts);
|
||||
while(total < bytes){
|
||||
unsigned long toread = bytes - total;
|
||||
int r;
|
||||
if(toread > sizeof(buffer))
|
||||
toread = sizeof(buffer);
|
||||
r=ssh_channel_read(channel,buffer,toread,0);
|
||||
if(r == SSH_ERROR)
|
||||
goto error;
|
||||
total += r;
|
||||
}
|
||||
|
||||
if(args->verbose>0)
|
||||
fprintf(stdout,"Finished download\n");
|
||||
ms=elapsed_time(&ts);
|
||||
*bps=8000 * (float)bytes / ms;
|
||||
if(args->verbose > 0)
|
||||
fprintf(stdout,"Download took %f ms for %lu bytes, at %f bps\n",ms,
|
||||
bytes,*bps);
|
||||
ssh_channel_close(channel);
|
||||
ssh_channel_free(channel);
|
||||
return 0;
|
||||
error:
|
||||
fprintf(stderr,"Error during raw upload : %s\n",ssh_get_error(session));
|
||||
if(channel){
|
||||
ssh_channel_close(channel);
|
||||
ssh_channel_free(channel);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -28,8 +28,8 @@
|
||||
#include <stdio.h>
|
||||
|
||||
const char *libssh_benchmarks_names[]={
|
||||
"null",
|
||||
"benchmark_raw_upload"
|
||||
"benchmark_raw_upload",
|
||||
"benchmark_raw_download"
|
||||
};
|
||||
|
||||
#ifdef HAVE_ARGP_H
|
||||
@ -62,6 +62,14 @@ static struct argp_option options[] = {
|
||||
.doc = "Upload raw data using channel",
|
||||
.group = 0
|
||||
},
|
||||
{
|
||||
.name = "raw-download",
|
||||
.key = '2',
|
||||
.arg = NULL,
|
||||
.flags = 0,
|
||||
.doc = "Download raw data using channel",
|
||||
.group = 0
|
||||
},
|
||||
{
|
||||
.name = "host",
|
||||
.key = 'h',
|
||||
@ -85,7 +93,8 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) {
|
||||
|
||||
switch (key) {
|
||||
case '1':
|
||||
arguments->benchmarks[key - '1' + 1] = 1;
|
||||
case '2':
|
||||
arguments->benchmarks[key - '1'] = 1;
|
||||
arguments->ntests ++;
|
||||
break;
|
||||
case 'v':
|
||||
@ -185,13 +194,20 @@ static void do_benchmarks(ssh_session session, struct argument_s *arguments,
|
||||
if(err==0){
|
||||
fprintf(stdout, "SSH RTT : %f ms\n",ssh_rtt);
|
||||
}
|
||||
if(arguments->benchmarks[BENCHMARK_RAW_UPLOAD-1]){
|
||||
if(arguments->benchmarks[BENCHMARK_RAW_UPLOAD]){
|
||||
err=benchmarks_raw_up(session,arguments,&bps);
|
||||
if(err==0){
|
||||
fprintf(stdout, "%s : %s : %s\n",hostname,
|
||||
libssh_benchmarks_names[BENCHMARK_RAW_UPLOAD], network_speed(bps));
|
||||
}
|
||||
}
|
||||
if(arguments->benchmarks[BENCHMARK_RAW_DOWNLOAD]){
|
||||
err=benchmarks_raw_down(session,arguments,&bps);
|
||||
if(err==0){
|
||||
fprintf(stdout, "%s : %s : %s\n",hostname,
|
||||
libssh_benchmarks_names[BENCHMARK_RAW_DOWNLOAD], network_speed(bps));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
@ -207,9 +223,9 @@ int main(int argc, char **argv){
|
||||
}
|
||||
if (arguments.ntests==0){
|
||||
for(i=1; i < BENCHMARK_NUMBER ; ++i){
|
||||
arguments.benchmarks[i-1]=1;
|
||||
arguments.benchmarks[i]=1;
|
||||
}
|
||||
arguments.ntests=BENCHMARK_NUMBER-1;
|
||||
arguments.ntests=BENCHMARK_NUMBER;
|
||||
}
|
||||
if (arguments.verbose > 0){
|
||||
fprintf(stdout, "Will try hosts ");
|
||||
@ -217,9 +233,9 @@ int main(int argc, char **argv){
|
||||
fprintf(stdout,"\"%s\" ", arguments.hosts[i]);
|
||||
}
|
||||
fprintf(stdout,"with benchmarks ");
|
||||
for(i=0;i<BENCHMARK_NUMBER-1;++i){
|
||||
for(i=0;i<BENCHMARK_NUMBER;++i){
|
||||
if(arguments.benchmarks[i])
|
||||
fprintf(stdout,"\"%s\" ",libssh_benchmarks_names[i+1]);
|
||||
fprintf(stdout,"\"%s\" ",libssh_benchmarks_names[i]);
|
||||
}
|
||||
fprintf(stdout,"\n");
|
||||
}
|
||||
|
@ -30,13 +30,14 @@
|
||||
#define MAX_HOSTS_CONNECT 20
|
||||
|
||||
enum libssh_benchmarks {
|
||||
BENCHMARK_RAW_UPLOAD=1,
|
||||
BENCHMARK_RAW_UPLOAD=0,
|
||||
BENCHMARK_RAW_DOWNLOAD,
|
||||
BENCHMARK_NUMBER
|
||||
};
|
||||
|
||||
struct argument_s {
|
||||
const char *hosts[MAX_HOSTS_CONNECT];
|
||||
char benchmarks[BENCHMARK_NUMBER -1];
|
||||
char benchmarks[BENCHMARK_NUMBER];
|
||||
int verbose;
|
||||
int nhosts;
|
||||
int ntests;
|
||||
@ -58,5 +59,7 @@ float elapsed_time(struct timestamp_struct *ts);
|
||||
|
||||
int benchmarks_raw_up (ssh_session session, struct argument_s *args,
|
||||
float *bps);
|
||||
int benchmarks_raw_down (ssh_session session, struct argument_s *args,
|
||||
float *bps);
|
||||
|
||||
#endif /* BENCHMARKS_H_ */
|
||||
|
@ -137,7 +137,7 @@ int benchmarks_ssh_latency(ssh_session session, float *average){
|
||||
ssh_channel_close(channel);
|
||||
ssh_channel_free(channel);
|
||||
channel=NULL;
|
||||
printf("Times : %f ms ; %f ms ; %f ms\n", times[0], times[1], times[2]);
|
||||
printf("SSH request times : %f ms ; %f ms ; %f ms\n", times[0], times[1], times[2]);
|
||||
*average=(times[0]+times[1]+times[2])/3;
|
||||
return 0;
|
||||
error:
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user