- 论坛徽章:
- 1
|
非常感谢楼主。可是我是初次接触FastDFS,没有深入了解,我近几天一直有个的想法是直接在FastDFS下的client目录下直接在fdfs_download_file.c中添加gettimeofday(&start,NULL)和gettimeofday(&end,NULL),然后两者相减得到的结果printf出来,但是在执行完程序后,无法显示结果,请您帮我分析一下,麻烦了!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <string.h>
#include <sys/time.h>#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "fdfs_client.h"
#include "logger.h"
#define MILLION 1000000L
int main(int argc, char *argv[])
{
char *conf_filename;
char *local_filename;
TrackerServerInfo *pTrackerServer;
int result;
char file_id[128];
int64_t file_size;
long timedif;
struct timeval tpend,tpstart;
gettimeofday(&tpstart,NULL); if (argc < 3)
{
printf("Usage: %s <config_file> <remote file id> " \
"[local filename]\n", argv[0]);
return 1;
}
log_init();
g_log_context.log_level = LOG_ERR;
conf_filename = argv[1];
if ((result=fdfs_client_init(conf_filename)) != 0)
{
return result;
}
pTrackerServer = tracker_get_connection();
if (pTrackerServer == NULL)
{
fdfs_client_destroy();
return errno != 0 ? errno : ECONNREFUSED;
}
snprintf(file_id, sizeof(file_id), "%s", argv[2]);
if (argc >= 4)
{
local_filename = argv[3];
}
else
{
local_filename = strrchr(file_id, '/');
if (local_filename != NULL)
{
local_filename++; //skip /
}
else
{
local_filename = file_id;
}
}
result = storage_download_file_to_file1( \
pTrackerServer, NULL, \
file_id,local_filename,&file_size);
gettimeofday(&tpend,NULL);
timedif=MILLION*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
printf("the time is %ld second",timedif);
; if (result != 0)
{
printf("download file fail, " \
"error no: %d, error info: %s\n", \
result, STRERROR(result));
}
fdfs_quit(pTrackerServer);
tracker_close_all_connections();
fdfs_client_destroy();
return 0;
}
之后步骤是:执行make,make install后,对文件进行下载。
可是时间无法显示出来。 |
|