Exemple #1
0
void ProfilerThread::responseReceived()
{
  if (m_query->getErrno() == SUCCESS) incCounter();
  qDebug() << getCounter() << m_sendTime.msecsTo(QDateTime::currentDateTime()) <<  (int)(m_query->getErrno()!=SUCCESS) << m_requests_per_second;
  //QString a=QString("echo \"%1 %2 %3 %4 `ps -e -o rss,comm | grep fcgi | grep -o \\\"^[0-9 ]*\\\"`\"").arg(getCounter()).arg(m_sendTime.msecsTo(QDateTime::currentDateTime())).arg((int)(m_query->getErrno()!=SUCCESS)).arg(m_requests_per_second);
  //system(a.toStdString().c_str());
  if (m_counter == m_number_of_requests ) exit();
  emit doRequest();
}
Exemple #2
0
void Machine::performTurnover()
{
    clearCounters();

    // find situations where the rotor on the right causes the rotor
    // on the left to turnover
    for (int i = rotorArray.count() - 1; i > 0; i--)
    {
        if (rotorArray.value(i+1)->checkForTurnover())
        {
            qDebug("1 - rotorname [%s] number [%d] turnover YES",
                   rotorArray.value(i)->getRotorName().toStdString().data(),
                   i);
            incCounter(i);
        }
    }

    // rotor double steps if its on its turnover position and
    // its not the first or last rotor.
    for (int i = 2; i < rotorArray.count(); i++)
    {
        qDebug("\t\t Double Step rotor [%d] name [%s]",
               i,
               rotorArray.value(i)->getRotorName().toStdString().data());
        if (rotorArray.value(i)->checkForTurnover() )
        {
            incCounter(i);
        }
    }

    // The right hand rotor ALWAYS turns one position
    qDebug("3 - rotor name [%s] number [%d] turnover YES",
           rotorArray.value(rotorArray.count())->getRotorName().toStdString().data(),
           rotorArray.count());
    incCounter(rotorArray.count()); // force a turnover on the right most rotor

    displayCounters(); // display debug information

    executeTurnovers(); // use the accumulated information to turnover the rotor(s)
}
Exemple #3
0
void solve() {
    int64 argument;
    {
        FILE  *in = fopen("function.in" ,"r");
        fscanf(in,"%lld",&argument);
        fclose(in );
    }

    cache = (int32*)malloc(sizeof(int32*)*(argument+1));
    memset(cache,0,argument+1);

    {
        //todo: realloc
        request **stack  = (request**)malloc(sizeof(request*)*INIT_STACK);
               ( *stack) = (request* )malloc(sizeof(request ));
               (**stack) = create_request(argument);

        request **bottom = stack;
        do {
            request current = **bottom;
            int64   value   = current.argument;

            if (value < 3 || cache[value] != 0) {
                incCounter(value);
                free(*bottom);
                bottom--;
            } else {
                int64 left, right;
                if (value % 2 == 0) {
                    left  = value - 1;
                    right = value - 3;
                } else {
                    left  = (value / 7)*6 + ((value % 7)*6)/7;
                    right = (value / 3)*2 + ((value % 3)*2)/3;
                }
                if (cache[left] == 0 || cache[right] == 0) {
                    //left and right will be computed twice =/
                    processArg(left, &bottom);
                    processArg(right,&bottom);
                } else {
                    cache[value] = (cache[left] + cache[right]) % two32;
                }
            }
        } while (bottom != stack);
    }

    {
        FILE *out = fopen("function.out","w");
        fprintf(out,"%lld",counter);
        fclose(out);
    }
}
Exemple #4
0
int doDeletes(const char* root, int count){
    char nodeName[1024];
    int i;
    counter=0;
    for(i=0; i<count;i++){
        int rc = 0;
        snprintf(nodeName, sizeof(nodeName),"%s/%d",root,i);
        incCounter(1);
        rc=zoo_adelete(zh, nodeName,-1,delete_completion, 0);
        if(rc!=ZOK) return rc;        
    }
    return ZOK;
}
Exemple #5
0
void read_completion(int rc, const char *value, int value_len,
        const struct Stat *stat, const void *data) {
    incCounter(-1);    
    if(rc!=ZOK){
        LOG_ERROR(LOGSTREAM, "Failed to read a node rc=%d",rc);
        return;
    }
    if(memcmp(value,"second",6)!=0){
        char buf[value_len+1];
        memcpy(buf,value,value_len);buf[value_len]=0;
        LOG_ERROR(LOGSTREAM, "Invalid read, expected [second], received [%s]\n",buf);
        exit(1);
    }
}
Exemple #6
0
int doCreateNodes(const char* root, int count){
    char nodeName[1024];
    int i;
    for(i=0; i<count;i++){
        int rc = 0;
        snprintf(nodeName, sizeof(nodeName),"%s/%d",root,i);
        incCounter(1);
        rc=zoo_acreate(zh, nodeName, "first", 5, &ZOO_OPEN_ACL_UNSAFE, 0,
                            create_completion, 0);
        if(i%1000==0){
            LOG_INFO(LOGSTREAM, "Created %s", nodeName);
        }
        if(rc!=ZOK) return rc;        
    }
    return ZOK;
}
/**
 * Transfer the block form the remote rank, that holds it,
 * or if it´s the same rank, copy it by using memcpy.
 */
void grid::NumaDistStaticGrid::getBlock(unsigned long block,
        long oldBlock,
        unsigned long cacheIndex,
        unsigned char *cache) {
    unsigned long blockSize = getTotalBlockSize();
    int remoteRank = getBlockRank(block);
    incCounter(perf::Counter::MPI);
    int mpiResult;
     
    if (remoteRank == getMPIRank()) {
        //The block is located in the same NUMA Domain, but in the memspace of another thread.
        pthread_t remoteId = getThreadId(block);
        size_t offset = getType().getSize()*blockSize*getBlockThreadOffset(block);
        //copy the block
     //   std::cout << "Memcpy Thread: " << remoteId << " Pointer: " << &(m_threadHandle.getStaticPtr(remoteId, m_id));
        memcpy(cache, m_threadHandle.getStaticPtr(remoteId, m_id) + offset, getType().getSize()*blockSize);
    } 
    else {
        
        //This section is critical. Only one Thread is allowed to access.
        //TODO: Find a better solution than pthread mutex.
        unsigned long offset = getBlockOffset(block);
        NDBG_UNUSED(mpiResult);
        mpiResult = m_threadHandle.getBlock(cache,
                blockSize,
                getType().getMPIType(),
                remoteRank,
                offset * blockSize,
                blockSize,
                getType().getMPIType(),
                m_threadHandle.mpiWindow);
        assert(mpiResult == MPI_SUCCESS);

    }



}
Exemple #8
0
void create_completion(int rc, const char *name, const void *data) {
    incCounter(-1);
    if(rc!=ZOK){
        LOG_ERROR(LOGSTREAM, "Failed to create a node rc=%d",rc);
    }
}
Exemple #9
0
void delete_completion(int rc, const void *data) {
    incCounter(-1);    
}
Exemple #10
0
void write_completion(int rc, const struct Stat *stat, const void *data) {
    incCounter(-1);
    if(rc!=ZOK){
        LOG_ERROR(LOGSTREAM, "Failed to write a node rc=%d",rc);
    }
}