DysectAPI::DysectErrorCode Probe::sendEnqueuedNotifications() { if(awaitingNotifications == 0) return OK; assert(dom != 0); MRN::Stream* stream = dom->getStream(); assert(stream != 0); DYSECTVERBOSE(true, "Sending %d notifications on stream id: %x", awaitingNotifications, stream->get_Id()); if(stream->send(dom->getProbeNotifyTag(), "%d %auc", awaitingNotifications, "", 1) == -1) { return StreamError; } if(stream->flush() == -1) { return StreamError; } awaitingNotifications = 0; return OK; }
DysectAPI::DysectErrorCode Probe::notifyTriggered() { assert(dom != 0); MRN::Stream* stream = dom->getStream(); assert(stream != 0); DYSECTVERBOSE(true, "Sending on stream id: %x", stream->get_Id()); if(stream->send(dom->getProbeEnabledTag(), "%d %auc", 1, "", 1) == -1) { return StreamError; } if(stream->flush() == -1) { return StreamError; } return OK; }
void HelloBE::mEnterMainLoop(void) { VCOMP_COUT("Entering Main Loop." << std::endl); // TODO //toolcommon::beReady(mGladiusPluginArgs.protoStream); // MRN::PacketPtr packet; const bool recvShouldBlock = true; // Convenience pointer to network. auto *network = mGladiusPluginArgs.network; MRN::Stream *protoStream = nullptr; int status = 0; int action = 0; // Do Until the FE Says So... do { // What action is next FE? status = network->recv(&action, packet, &protoStream, recvShouldBlock); if (1 != status) GLADIUS_THROW_CALL_FAILED("Network::Recv"); switch (action) { case hello::SayHello: { const char *hello = "hello"; status = protoStream->send(action, "%s", hello); if (-1 == status) { GLADIUS_THROW_CALL_FAILED("Stream::Send"); } status = protoStream->flush(); if (-1 == status) { GLADIUS_THROW_CALL_FAILED("Stream::Flush"); } break; } case hello::Shutdown: { break; } } } while (action != hello::Shutdown); VCOMP_COUT("Done with Main Loop." << std::endl); }
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; }
DysectAPI::DysectErrorCode Probe::sendEnqueuedActions() { struct packet* p = 0; int len = 0, actionsHandled = 0; DYSECTVERBOSE(true, "Sending %d enqueued actions for %x", awaitingActions, dom->getId()); if(actions.empty()) { DYSECTVERBOSE(true, "No enqueued actions", len); return OK; } if(awaitingActions == 0) { return OK; } vector<Act*>::iterator actIter = actions.begin(); for(;actIter != actions.end(); actIter++) { Act* act = *actIter; struct packet* np = 0; if(act) { DYSECTVERBOSE(true, "Getting packet from action"); act->finishBE(np, len); act->actionPending = false; actionsHandled += 1; DYSECTVERBOSE(true, "Aggregate packet length: %d", len); } if(!p) { p = np; } else if(np && p) { struct packet* mp = 0; AggregateFunction::mergePackets(p, np, mp, len); p = mp; } } if((len > 0) && (p == 0)) { return DYSECTVERBOSE(Error, "Packet is not set, even tough len != 0 (%d)", len); } assert(dom != 0); MRN::Stream* stream = dom->getStream(); assert(stream != 0); if(len > 0) { DYSECTVERBOSE(true, "Sending %d byte aggregate packet", len); if(stream->send(dom->getProbeEnabledTag(), "%d %auc", processCount, (char*)p, len) == -1) { return StreamError; } if(stream->flush() == -1) { return StreamError; } } else { if(stream->send(dom->getProbeEnabledTag(), "%d %auc", processCount, "", 1) == -1) { return StreamError; } if(stream->flush() == -1) { return StreamError; } } processCount = 0; return OK; }