📄 reporter.c
字号:
/*--------------------------------------------------------------- * 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 __cplusplusextern "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 printingReportHeader *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.nextTime, agent->report.intervalTime );}/* * InitReport is called by a transfer agent (client or * server) to setup the needed structures to communicate * traffic. */ReportHeader* InitReport( thread_Settings *agent ) { ReportHeader *reporthdr = NULL; ReporterData *data = NULL; if ( isDataReport( agent ) ) { /* * Create in one big chunk */ reporthdr = malloc( sizeof(ReportHeader) + NUM_REPORT_STRUCTS * sizeof(ReportStruct) ); if ( reporthdr != NULL ) { // Only need to make sure the headers are clean memset( reporthdr, 0, sizeof(ReportHeader)); reporthdr->data = (ReportStruct*)(reporthdr+1); reporthdr->multireport = agent->multihdr; data = &reporthdr->report; reporthdr->reporterindex = NUM_REPORT_STRUCTS - 1; data->info.transferID = agent->mSock; data->info.groupID = (agent->multihdr != NULL ? agent->multihdr->groupID : -1); 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 ) ) { reporthdr->report.info.mUDP = (char)agent->mThreadMode; } } else { FAIL(1, "Out of Memory!!\n", agent); } } if ( isConnectionReport( agent ) ) { if ( reporthdr == NULL ) { /* * Create in one big chunk */ reporthdr = malloc( sizeof(ReportHeader) ); if ( reporthdr != NULL ) { // Only need to make sure the headers are clean memset( reporthdr, 0, sizeof(ReportHeader)); data = &reporthdr->report; data->info.transferID = agent->mSock; data->info.groupID = -1; } else { FAIL(1, "Out of Memory!!\n", agent); } } if ( reporthdr != NULL ) { data->type |= CONNECTION_REPORT; data->connection.peer = agent->peer; data->connection.size_peer = agent->size_peer; data->connection.local = agent->local; data->connection.size_local = agent->size_local; } else { FAIL(1, "Out of Memory!!\n", agent); } } if ( isConnectionReport( agent ) || isDataReport( agent ) ) {#ifdef HAVE_THREAD /* * Update the ReportRoot to include this report. */ if ( reporthdr->report.mThreadMode == kMode_Client && reporthdr->multireport != NULL ) { // syncronize watches on my mark...... BarrierClient( reporthdr ); } else { if ( reporthdr->multireport != NULL && isMultipleReport( agent )) { reporthdr->multireport->threads++; if ( reporthdr->multireport->report->startTime.tv_sec == 0 ) { gettimeofday( &(reporthdr->multireport->report->startTime), NULL ); } reporthdr->report.startTime = reporthdr->multireport->report->startTime; } else { // set start time gettimeofday( &(reporthdr->report.startTime), NULL ); } reporthdr->report.nextTime = reporthdr->report.startTime; TimeAdd( reporthdr->report.nextTime, reporthdr->report.intervalTime ); } Condition_Lock( ReportCond ); reporthdr->next = ReportRoot;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -