Esempio n. 1
0
void WorkerStatistics::Visit( Scheduler &scheduler )
{
    std::ostringstream ss;

    const Scheduler::IPToNodeState &nodeState = scheduler.GetNodeState();

    ss << "================" << std::endl;

    auto it_beg = nodeState.cbegin();
    for( auto n_it = it_beg ; n_it != nodeState.cend(); ++n_it )
    {
        const NodeState &nodeState = n_it->second;
        const WorkerPtr &worker = nodeState.GetWorker();
        if ( !worker )
            continue;

        if ( n_it != it_beg )
            ss << "----------------" << std::endl;

        ss << "host = '" << worker->GetHost() << "', ip = " << worker->GetIP() << std::endl;

        if ( !worker->GetGroup().empty() )
        {
            ss << "group = " << worker->GetGroup() << std::endl;
        }

        const WorkerJob &workerJob = worker->GetJob();

        ss << "num cpu = " << worker->GetNumCPU() << std::endl <<
            "memory = " << worker->GetMemorySize() << std::endl <<
            "num executing tasks = " << workerJob.GetTotalNumTasks() << std::endl;

        ss << "tasks = {";
        std::vector< WorkerTask > tasks;
        workerJob.GetTasks( tasks );
        for( auto it = tasks.cbegin(); it != tasks.cend(); ++it )
        {
            const WorkerTask &task = *it;
            if ( it != tasks.begin() )
                ss << ",";
            ss << "(jobId=" << task.GetJobId() << ", taskId=" << task.GetTaskId() << ")";
        }
        ss << "}" << std::endl;
    }

    ss << "================";

    info_ = ss.str();
}
Esempio n. 2
0
int Statistics::GetNumBusyCPU( Scheduler &scheduler ) const
{
    const Scheduler::Scheduler::IPToNodeState &nodeState = scheduler.GetNodeState();

    int num = 0;
    for( auto it = nodeState.cbegin(); it != nodeState.cend(); ++it )
    {
        const NodeState &nodeState = it->second;
        const WorkerPtr &worker = nodeState.GetWorker();
        if ( !worker || !worker->IsAvailable() )
            continue;

        num += nodeState.GetNumBusyCPU();
    }
    return num;
}
Esempio n. 3
0
void JobInfo::PrintJobInfo( std::string &info, Scheduler &scheduler, int64_t jobId )
{
    std::ostringstream ss;

    ScheduledJobs &jobs = scheduler.GetScheduledJobs();
    JobPtr job;
    if ( !jobs.FindJobByJobId( jobId, job ) )
     {
        ss << "job isn't executing now, jobId = " << jobId;
        info = ss.str();
        return;
    }

    ss << "================" << std::endl <<
        "Job info, jobId = " << job->GetJobId() << std::endl;

    if ( job->GetGroupId() >= 0 )
    {
        ss << "group id = " << job->GetGroupId() << std::endl;
    }

    if ( job->GetJobGroup() )
    {
        const std::string &metaJobName = job->GetJobGroup()->GetName();
        if ( !metaJobName.empty() )
        {
            ss << "meta job name = '" << metaJobName << '\'' << std::endl;
        }
    }

    if ( !job->GetAlias().empty() )
    {
        ss << "job alias = '" << job->GetAlias() << '\'' << std::endl;
    }
    else
    {
        ss << "job path = '" << job->GetFilePath() << '\'' << std::endl;
    }

    if ( !job->GetName().empty() )
    {
        ss << "job name = '" << job->GetName() << '\'' << std::endl;
    }

    ss << "----------------" << std::endl;

    {
        int totalExec = job->GetNumPlannedExec();
        int numExec = totalExec - jobs.GetNumExec( jobId );
        ss << "job executions = " << numExec << std::endl <<
            "total planned executions = " << totalExec << std::endl;
    }

    {
        int numWorkers = 0;
        int numCPU = 0;
        const Scheduler::IPToNodeState &nodeState = scheduler.GetNodeState();
        for( auto it = nodeState.cbegin(); it != nodeState.cend(); ++it )
        {
            const NodeState &nodeState = it->second;
            const WorkerPtr &worker = nodeState.GetWorker();
            if ( !worker )
                continue;

            const WorkerJob &workerJob = worker->GetJob();

            if ( workerJob.HasJob( jobId ) )
            {
                ++numWorkers;
                numCPU += workerJob.GetNumTasks( jobId );
            }
        }
        ss << "busy workers = " << numWorkers << std::endl;
        ss << "busy cpu's = " << numCPU << std::endl;
    }

    ss << "================";
    info = ss.str();
}