Changeset 2258


Ignore:
Timestamp:
Dec 24, 2010, 2:22:30 AM (11 years ago)
Author:
schwittmann
Message:

External Client: added more statistics

Location:
trunk/CrypPlugins/KeySearcher/ExternalClient
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/ExternalClient/Cryptool.cpp

    r2256 r2258  
    1616
    1717#include "Cryptool.h"
     18
     19unsigned long DiffMicSec(timeval & start, timeval & end)
     20{
     21    return (end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec);
     22}
    1823
    1924Cryptool::Cryptool()
     
    101106   
    102107    localCosts = new float[subbatch];
    103     lastSubbatchCompleted = clock();
     108
     109    gettimeofday(&lastSubbatchCompleted, NULL);
    104110
    105111    // required for thousand/million separator in printf
     
    160166JobResult Cryptool::doOpenCLJob(const Job& j)
    161167{
     168    res.Guid = j.Guid;
    162169    cl_int err;
    163170
     
    201208void Cryptool::enqueueSubbatch(cl::CommandQueue& queue, cl::Buffer& keybuffer, cl::Buffer& costs, int add, int length, const Job& j)
    202209{
     210    timeval openCLStart;
     211    gettimeofday(&openCLStart, NULL);
    203212        cl_int err;
    204213
     
    241250                throw new std::exception();
    242251        }
     252
     253    timeval openCLEnd;
     254    gettimeofday(&openCLEnd, NULL);
    243255#ifdef _OPENMP
    244256#pragma omp parallel
     
    280292        }
    281293#endif
     294
     295    timeval finishedSubbatch;
     296    gettimeofday(&finishedSubbatch, NULL);
     297
     298    unsigned long totalMic= DiffMicSec(openCLStart, finishedSubbatch);
     299
     300    printf("Completed a subbatch in %.3f seconds. %.2f%% spent on OpenCL, %.2f%% on sorting.\n",
     301            (float)totalMic/1000000, DiffMicSec(openCLStart, openCLEnd)/(float)totalMic*100, DiffMicSec(openCLEnd, finishedSubbatch)/(float)totalMic*100);
     302
    282303}
    283304
     
    288309        enqueueSubbatch(queue, keybuffer, costs, i*subbatch, subbatch, j);
    289310
    290         clock_t now = clock();
    291         clock_t timeDiff = now - lastSubbatchCompleted;
     311        timeval now;
     312        gettimeofday(&now, NULL);
     313        unsigned long timeDiffMicroSec = (now.tv_sec - lastSubbatchCompleted.tv_sec)*1000000 + (now.tv_usec - lastSubbatchCompleted.tv_usec);
    292314        lastSubbatchCompleted = now;
    293         printf("% .2f%% done. %'u keys/sec\n", ((i+1)*subbatch)/(float)size*100, (unsigned int)(subbatch/(timeDiff/(float)CLOCKS_PER_SEC)));
     315        printf("% .2f%% done. %'u keys/sec\n", ((i+1)*subbatch)/(float)size*100, (unsigned int)(subbatch/((float)timeDiffMicroSec/1000000)));
    294316    }
    295317
  • trunk/CrypPlugins/KeySearcher/ExternalClient/Cryptool.h

    r2256 r2258  
    22
    33#include <CL/cl.hpp>
    4 #include <time.h>
     4#include <sys/time.h>
    55
    66#include "Job.h"
     
    1717    bool compareLargerThan;
    1818    int resultSize;
    19     clock_t lastSubbatchCompleted;
     19    timeval lastSubbatchCompleted;
    2020
    2121        static const int subbatch = 256*256*256;
  • trunk/CrypPlugins/KeySearcher/ExternalClient/Job.h

    r2207 r2258  
    1717{
    1818    public:
     19        std::string Guid;
    1920        std::list<std::pair<float, int> > ResultList;
    2021};
  • trunk/CrypPlugins/KeySearcher/ExternalClient/Network.cpp

    r2256 r2258  
    88#include <sys/sysctl.h>
    99#include <iostream>
     10#include <queue>
    1011
    1112#include <sys/types.h>
     
    3031}
    3132
    32 void GetJobsAndPostResults(PlatformIndependentWrapper wrapper)
     33
     34void writeJobResult(PlatformIndependentWrapper& wrapper, JobResult& result)
     35{
     36    wrapper.WriteInt(ClientOpcodes::JOB_RESULT);
     37    wrapper.WriteString(result.Guid);
     38    wrapper.WriteInt(result.ResultList.size());
     39    for (std::list<std::pair<float, int> >::iterator it = result.ResultList.begin(); it != result.ResultList.end(); ++it)
     40    {
     41        wrapper.WriteInt(it->second);
     42        wrapper.WriteFloat(it->first);
     43    }
     44}
     45
     46// Queue of completed jobs
     47std::queue<JobResult> finishedJobs;
     48void GetJobsAndPostResults(PlatformIndependentWrapper& wrapper)
    3349{
    3450    if (cryptool == 0)
     
    3854    wrapper.WriteString(getIdentificationStr());
    3955
     56    while(!finishedJobs.empty())
     57    {
     58        printf("Trying to send %u finished job%s\n", finishedJobs.size(), finishedJobs.size()>1?"s":"");
     59        writeJobResult(wrapper, finishedJobs.front());
     60        finishedJobs.pop();
     61    }
    4062    // loop will be escaped by wrapper exceptions
    4163    while(true)
     
    5779
    5880                    JobResult res = cryptool->doOpenCLJob(j);
    59 
    6081                    //send results back:
    61                     wrapper.WriteInt(ClientOpcodes::JOB_RESULT);
    62                     wrapper.WriteString(j.Guid);
    63                     wrapper.WriteInt(res.ResultList.size());
    64                     for (std::list<std::pair<float, int> >::iterator it = res.ResultList.begin(); it != res.ResultList.end(); it++)
     82                    try {
     83                        writeJobResult(wrapper, res);
     84                    }catch(SocketException e)
    6585                    {
    66                         wrapper.WriteInt(it->second);
    67                         wrapper.WriteFloat(it->first);
     86                        printf("Exception while writing results :(\n");
     87                        throw e;
    6888                    }
    6989                }
  • trunk/CrypPlugins/KeySearcher/ExternalClient/PlatformIndependentWrapper.cpp

    r2207 r2258  
    4848    } while(rec > 0 && offset< num);
    4949
    50     if(rec < 0)
     50    if(rec <= 0)
    5151    {
    5252        throw SocketException();
     
    5656void PlatformIndependentWrapper::WriteArray(const char* buf, int num)
    5757{
    58     write(this->sockfd, buf, num);
     58    if(write(this->sockfd, buf, num)!=num)
     59    {
     60        printf("failed to write :(\n");
     61        throw SocketException();
     62    }
    5963}
Note: See TracChangeset for help on using the changeset viewer.