/*---------------------------------------------------------------
* Copyright (c) 1999,2000,2001,2002,2003
* The Board of Trustees of the University of Illinois
* All Rights Reserved.
*---------------------------------------------------------------
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software (Iperf) and associated
* documentation files (the "Software"), to deal in the Software
* without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
*
* Redistributions of source code must retain the above
* copyright notice, this list of conditions and
* the following disclaimers.
*
*
* Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimers in the documentation and/or other materials
* provided with the distribution.
*
*
* Neither the names of the University of Illinois, NCSA,
* nor the names of its contributors may be used to endorse
* or promote products derived from this Software without
* specific prior written permission.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* ________________________________________________________________
* National Laboratory for Applied Network Research
* National Center for Supercomputing Applications
* University of Illinois at Urbana-Champaign
* http://www.ncsa.uiuc.edu
* ________________________________________________________________
*
* Reporter.c
* by Kevin Gibbs <kgibbs@nlanr.net>
*
* ________________________________________________________________ */
#include "headers.h"
#include "Settings.hpp"
#include "util.h"
#include "Reporter.h"
#include "Thread.h"
#include "Locale.h"
#include "PerfSocket.hpp"
#include "SocketAddr.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
The following 4 functions are provided for Reporting
styles that do not have all the reporting formats. For
instance the provided CSV format does not have a settings
report so it uses settings_notimpl.
*/
void* connection_notimpl( Connection_Info * nused, int nuse ) {
return NULL;
}
void settings_notimpl( ReporterData * nused ) { }
void statistics_notimpl( Transfer_Info * nused ) { }
void serverstatistics_notimpl( Connection_Info *nused1, Transfer_Info *nused2 ) { }
// To add a reporting style include its header here.
#include "report_default.h"
#include "report_CSV.h"
// The following array of report structs contains the
// pointers required for reporting in different reporting
// styles. To add a reporting style add a report struct
// below.
report_connection connection_reports[kReport_MAXIMUM] = {
reporter_reportpeer,
CSV_peer
};
report_settings settings_reports[kReport_MAXIMUM] = {
reporter_reportsettings,
settings_notimpl
};
report_statistics statistics_reports[kReport_MAXIMUM] = {
reporter_printstats,
CSV_stats
};
report_serverstatistics serverstatistics_reports[kReport_MAXIMUM] = {
reporter_serverstats,
CSV_serverstats
};
report_statistics multiple_reports[kReport_MAXIMUM] = {
reporter_multistats,
CSV_stats
};
char buffer[64]; // Buffer for printing
ReportHeader *ReportRoot = NULL;
extern Condition ReportCond;
int reporter_process_report ( ReportHeader *report );
void process_report ( ReportHeader *report );
int reporter_handle_packet( ReportHeader *report );
int reporter_condprintstats( ReporterData *stats, MultiHeader *multireport, int force );
int reporter_print( ReporterData *stats, int type, int end );
void PrintMSS( ReporterData *stats );
MultiHeader* InitMulti( thread_Settings *agent, int inID ) {
MultiHeader *multihdr = NULL;
if ( agent->mThreads > 1 || agent->mThreadMode == kMode_Server ) {
if ( isMultipleReport( agent ) ) {
multihdr = malloc(sizeof(MultiHeader) + sizeof(ReporterData) +
NUM_MULTI_SLOTS * sizeof(Transfer_Info));
} else {
multihdr = malloc(sizeof(MultiHeader));
}
if ( multihdr != NULL ) {
memset( multihdr, 0, sizeof(MultiHeader) );
Condition_Initialize( &multihdr->barrier );
multihdr->groupID = inID;
multihdr->threads = agent->mThreads;
if ( isMultipleReport( agent ) ) {
int i;
ReporterData *data = NULL;
multihdr->report = (ReporterData*)(multihdr + 1);
memset(multihdr->report, 0, sizeof(ReporterData));
multihdr->data = (Transfer_Info*)(multihdr->report + 1);
data = multihdr->report;
for ( i = 0; i < NUM_MULTI_SLOTS; i++ ) {
multihdr->data[i].startTime = -1;
multihdr->data[i].transferID = inID;
multihdr->data[i].groupID = -2;
}
data->type = TRANSFER_REPORT;
if ( agent->mInterval != 0.0 ) {
struct timeval *interval = &data->intervalTime;
interval->tv_sec = (long) agent->mInterval;
interval->tv_usec = (long) ((agent->mInterval - interval->tv_sec)
* rMillion);
}
data->mHost = agent->mHost;
data->mLocalhost = agent->mLocalhost;
data->mBufLen = agent->mBufLen;
data->mMSS = agent->mMSS;
data->mTCPWin = agent->mTCPWin;
data->flags = agent->flags;
data->mThreadMode = agent->mThreadMode;
data->mode = agent->mReportMode;
data->info.mFormat = agent->mFormat;
data->info.mTTL = agent->mTTL;
if ( isUDP( agent ) ) {
multihdr->report->info.mUDP = (char)agent->mThreadMode;
}
if ( isConnectionReport( agent ) ) {
data->type |= CONNECTION_REPORT;
data->connection.peer = agent->peer;
data->connection.size_peer = agent->size_peer;
SockAddr_setPortAny( &data->connection.peer );
data->connection.local = agent->local;
data->connection.size_local = agent->size_local;
SockAddr_setPortAny( &data->connection.local );
}
}
} else {
FAIL(1, "Out of Memory!!\n", agent);
}
}
return multihdr;
}
/*
* BarrierClient allows for multiple stream clients to be syncronized
*/
void BarrierClient( ReportHeader *agent ) {
Condition_Lock(agent->multireport->barrier);
agent->multireport->threads--;
if ( agent->multireport->threads == 0 ) {
// last one set time and wake up everyone
gettimeofday( &(agent->multireport->startTime), NULL );
Condition_Broadcast( &agent->multireport->barrier );
} else {
Condition_Wait( &agent->multireport->barrier );
}
agent->multireport->threads++;
Condition_Unlock( agent->multireport->barrier );
agent->report.startTime = agent->multireport->startTime;
agent->report.nextTime = agent->report.startTime;
TimeAdd( agent->report
- 1
- 2
- 3
- 4
- 5
- 6
前往页