component::~component() { // don't delete aggComponent, since sampleAggregator will // keep around to aggregate it's data MRN::Network * network = daemon->getNetwork() ; MRN::Communicator * comm = network->new_Communicator( ); comm->add_EndPoint( daemon->getEndPoint() ); MRN::Stream *stream = network->new_Stream(comm); daemon->disableDataCollection(stream, id); assert(id>=0); daemon->disabledMids += (unsigned) id; daemon->activeMids.undef((unsigned)id); }
int main( int argc, char* argv[] ) { int ret = 0; MRN::Network* net = NULL; try { int myNid = FindMyNid(); // connect to the MRNet net = MRN::Network::CreateNetworkBE( argc, argv ); assert( net != NULL ); int myRank = net->get_LocalRank(); //fprintf( stderr, "BE[%d] done creating MRNet net BE\n", myRank ); //fflush( stderr ); // receive the ALPS apid for the application to be monitored MRN::Stream* strm = NULL; MRN::PacketPtr pkt; int tag = 0; int rret = net->recv( &tag, pkt, &strm ); //fprintf( stderr, "BE[%d] received ALPS apid msg\n", myRank ); //fflush( stderr ); if( rret == -1 ) { throw XTMException( "BE[%d] failed to receive control message from FE" ); } if( tag != XTM_APID ) { std::ostringstream mstr; mstr << "BE[" << myRank << "] expected XTM_APID message, got tag=" << tag << std::ends; throw XTMException( mstr.str().c_str() ); } uint64_t apid = (uint64_t)-1; pkt->unpack( "%uld", &apid ); //fprintf( stderr, "BE[%d] received apid=%lu\n", myRank, apid ); //fflush( stderr ); #ifdef TOOL_CODE_GOES_HERE // ---- BEGIN TOOL-SPECIFIC CODE REGION ---- // 1. attach to local application process(es) // 2. indicate to tool FE that we are attached // 3. handle application process events until it finishes // ---- END TOOL-SPECIFIC CODE REGION ---- #else // fake to the FE as if we have connected to the application and // waited for it to finish tag = XTM_APPOK; int dummyVal = 1; int sret = strm->send( tag, "%d", dummyVal ); if( sret == -1 ) { fprintf( stderr, "BE[%d] send of app OK msg failed\n", myRank ); fflush( stderr ); } int fret = strm->flush(); if( fret == -1 ) { fprintf( stderr, "BE[%d] flush of app OK msg failed\n", myRank ); fflush( stderr ); } if( (sret == -1) || (fret == -1) ) { std::ostringstream mstr; mstr << "BE[" << myRank << "] failed to send app OK msg to FE" << std::ends; throw XTMException( mstr.str().c_str() ); } //fprintf( stderr, "BE[%d] sent app OK message to FE\n", myRank ); //fflush( stderr ); sleep( 5 ); #endif //fprintf( stderr, "BE[%d] sending app done message to FE\n", myRank ); //fflush( stderr ); tag = XTM_APPDONE; int appExitCode = 1; sret = strm->send( tag, "%d", appExitCode ); if( sret == -1 ) { fprintf( stderr, "BE[%d] send of app done msg failed\n", myRank ); fflush( stderr ); } fret = strm->flush(); if( fret == -1 ) { fprintf( stderr, "BE[%d] flush of app done msg failed\n", myRank ); fflush( stderr ); } if( (sret == -1) || (fret == -1) ) { std::ostringstream mstr; mstr << "BE[" << myRank << "] failed to send app exit code to FE" << std::ends; throw XTMException( mstr.str().c_str() ); } //fprintf( stderr, "BE[%d] sent app done message to FE\n", myRank ); //fflush( stderr ); // wait for termination message from FE rret = net->recv( &tag, pkt, &strm ); if( rret == -1 ) { std::ostringstream mstr; mstr << "BE[" << myRank << "] failed to receive control message from FE" << std::ends; throw XTMException( mstr.str().c_str() ); } if( tag != XTM_EXIT ) { std::ostringstream mstr; mstr << "BE[" << myRank << "] expected XTM_EXIT message, got tag=" << tag << std::ends; throw XTMException( mstr.str().c_str() ); } // clean up //fprintf( stderr, "BE[%d] exiting\n", myRank ); //fflush( stderr ); net->waitfor_ShutDown(); delete net; } catch( std::exception& e ) { fprintf( stderr, "!!BE EXCEPTION!! %s\n", e.what() ); ret = 1; } return ret; }
void data_recving (MYSQL* conn, char * tablename, int nr_be) { int nr_exited = 0; int tag; int count = 0; // PacketPtr pack; int rank, eid, tid, data, finish, nr_record, mpi_rank, type, src_rank, dst_rank, sendsize, sendtype, recvsize, recvtype; int mpi_comm, mpi_tag; MRN::Network * net = GetNetwork(); unsigned pid; long long unsigned time; unsigned long time_s, time_us; char sql[2048]; char buffer[500]; char instance[40], metric[40]; char *ename = NULL; char *hostname = NULL; char *procdata = NULL; Communicator *comm = net->get_BroadcastCommunicator(); Stream *stream = net->new_Stream( comm, TFILTER_NULL, SFILTER_DONTWAIT ); stream->send( PROT_DATA, "%d", 0 ); printf_d("[MRNFE] recieving data...nr_exited is %d nr_be is %d\n",nr_exited,nr_be); if (mysql_autocommit (conn, 0) != 0) printf_d ("[MRNFE] %s\n", mysql_error(conn)); while( nr_exited != nr_be ) { PacketPtr pack; stream->recv( &tag, pack ); count ++; switch (tag) { case PROT_DATA: pack->unpack("%d %d %d %uld %s %d %s", &tid, &pid, &eid, &time, &hostname, &finish, &ename); char *sql_tmp; sql_tmp = (char *) calloc (sizeof (char *), 200); snprintf_d(sql_tmp, 200, "CALL insertdata ( -1,%d, \"%s\" , %d, \"%s\", 7,\"FFFFFFFF\", '%llu', %d );" , pid, hostname, eid, ename, time, finish); if (mysql_query (conn, sql_tmp)) printf_d ("[MRNFE] %s\n", mysql_error(conn)); free (sql_tmp); free (hostname); free (ename); hostname = NULL; ename = NULL; break; case PROT_MPIDATA: /*MPI wrapper trace 数据*/ pack->unpack("%d %ud %s %d %s %d %d %d %d %d %d %d %d %d %uld %d", &mpi_rank, &pid, &hostname, &eid, &ename, &type, &mpi_comm, &mpi_tag, &src_rank, &dst_rank, &sendsize, &sendtype, &recvsize, &recvtype, &time, &finish); #ifdef debug printf_d ("[DEBUG]:\tRecv_Data: %d %u %s %d %s %d %x %d %d %d %d %d %d %d %llu %d\n", mpi_rank, pid, hostname, eid, ename, type, mpi_comm, mpi_tag, src_rank, dst_rank, sendsize, sendtype, recvsize, recvtype, time, finish); #endif snprintf_d (sql, 2048,"CALL insertdata (%d, %u, \"%s\", %d, \"%s\", %d, \"%x\", %llu, %d);", mpi_rank, pid, hostname, eid, ename, type, mpi_comm, time, finish); #ifdef DEBUG printf_d ("[DEBUG]:\t%s\n", sql); #endif if (mysql_query (conn, sql)) { printf_d ("[MRNFE] %s\n", mysql_error(conn)); } if (type != 0) { snprintf_d (sql, 2048,"CALL insert_comm_data (%d, %u, \"%s\", %d, \"%s\", %d, %d, %d, %d, %d, %d, %d, %llu, %d);", mpi_rank, pid, hostname, eid, ename, mpi_tag, src_rank, dst_rank, sendsize, sendtype, recvsize, recvtype, time, finish); if (mysql_query (conn, sql)) { printf_d ("[MRNFE] %s\n", mysql_error(conn)); } } free (ename); free (hostname); ename = NULL; hostname = NULL; break; case PROT_PROC: /*proc数据*/ if(!use_proc) { printf_d ("[MRNFE] no proc!!! ignored\n"); break; } { pack->unpack("%ud %ud %s %d %s %ud", &time_s, &time_us, &hostname, &nr_record, &procdata, &pid ); //printf_d(" [DEBUG] %ld, %ld, %d %s\n", time_s, time_us, nr_record, procdata ); char *p = procdata; float fdata; for( int i = 0; i < nr_record; i++ ){ sscanf_d( p, "%s", buffer ); p+=strlen(buffer)+1; sscanf_d( buffer, "%[^#]#%[^#]#%f", instance, metric, &fdata ); snprintf_d(sql, 2048, "CALL insertproc( %ld, %ld, \"%s\", %d, \"%s\", \"%s\", '%f')" , time_s, time_us, hostname, pid, metric, instance, fdata); if (mysql_query (conn, sql)) { printf_d ("[MRNFE] %s\n", mysql_error(conn)); } //printf_d ("%s\n", sql); //mysql_query( conn, sql ); } free(procdata); free(hostname); procdata = hostname = NULL; } break; case PROT_PAPI: if (!use_papi) { printf_d ("[MRNFE] no papi!!! ignored\n"); break; } else { long long papi_data; char *papi_event; pack->unpack("%s %ud %d %s %s %ld %uld %d", &ename, &pid, &tid, &hostname, &papi_event, &papi_data, &time, &finish); snprintf_d (sql, 2048, "CALL insert_papi_data(\"%s\", %u, %d, \"%s\", \"%s\", %lld, %llu, %d);", ename, pid, tid, hostname, papi_event, papi_data, time, finish); if (mysql_query (conn, sql)) printf_d ("[MRNFE] %s\n", mysql_error(conn)); free (hostname); free (ename); free (papi_event); hostname = NULL; ename = NULL; papi_event = NULL; } break; case PROT_IO: char *io_data; long long unsigned stime, etime; pack->unpack ("%s %ud %d %s %s %uld %uld", &ename, &pid, &tid, &hostname, &io_data, &stime, &etime); snprintf_d (sql, 2048, "CALL insert_io_data(\"%s\", %u, %d, \"%s\", \"%s\", %llu, %llu);", ename, pid, tid, hostname, io_data, stime, etime); if (mysql_query (conn, sql)) printf_d ("[MRNFE] %s\n", mysql_error(conn)); free (hostname); free (ename); free (io_data); hostname = NULL; ename = NULL; io_data = NULL; break; case PROT_MPIRANK: /*MPI rank数据*/ pack->unpack("%d %d", &rank, &data); snprintf_d( sql, 2048, "update `%s_nodelist` set mpirank=%d where rank=%d", tablename, data, rank ); mysql_query( conn, sql ); break; case PROT_NODEDATA: /*MPI节点数据*/ pack->unpack ("%ud %d", &pid, &mpi_rank); snprintf_d (sql, 2048, "update `%s_nodelist` set mpirank=%d where pid=%u", tablename, mpi_rank, pid); mysql_query( conn, sql ); break; case PROT_HALT: /*发送停止*/ nr_exited ++ ; printf_d( "[DEBUG] %d Back-ends Halted\n", nr_exited ); break; default: break; } if (count % 10000 == 0) mysql_commit(conn); } FE::write_exiting_info(); }