Ticket #2782: mythtv_jobqueue_2.patch
File mythtv_jobqueue_2.patch, 3.5 KB (added by , 17 years ago) |
---|
-
libs/libmyth/util.h
61 61 long long getDiskSpace(const QString&,long long&,long long&); 62 62 bool getUptime(time_t &uptime); 63 63 bool getMemStats(int &totalMB, int &freeMB, int &totalVM, int &freeVM); 64 bool getCPUStats(int &totalTime, int &idleTime); 64 65 65 66 #endif // UTIL_H_ -
libs/libmyth/util.cpp
472 472 473 473 return true; 474 474 } 475 476 bool getCPUStats(int &totalTime, int &idleTime) 477 { 478 #ifdef __linux__ 479 bool found = false; 480 char line[256]; 481 FILE *stat = fopen("/proc/stat", "r"); 482 if (stat) 483 { 484 while ( (found = fgets(line, sizeof line, stat)) && strncmp(line, "cpu ", 4) ) 485 ; 486 487 fclose(stat); 488 } 489 490 if (found) 491 { 492 char what[32]; 493 unsigned long user_time, nice_time, system_time, idle_time, wait_time = 0; 494 sscanf(line, "%s %lu %lu %lu %lu %lu", what, &user_time, &nice_time, 495 &system_time, &idle_time, &wait_time); 496 497 unsigned long total_time = user_time + nice_time + system_time + idle_time + wait_time ; 498 static unsigned long last_total_time = 0, last_idle_time = 0; 499 totalTime = total_time - last_total_time; 500 last_total_time = total_time; 501 idleTime = idle_time - last_idle_time; 502 last_idle_time = idle_time; 503 return true; 504 } 505 else 506 { 507 VERBOSE(VB_IMPORTANT, "cpuCPUAvail(): can't read /proc/stat"); 508 return false; 509 } 510 #else 511 VERBOSE(VB_IMPORTANT, "getCPUAvail(): Unknown platform. " 512 "How do I get CPU stats?"); 513 return false; 514 #endif 515 } -
libs/libmythtv/jobqueue.cpp
231 231 jobsRunning++; 232 232 } 233 233 234 int totalTime, idleTime; 234 235 message = QString("Currently Running %1 jobs.") 235 236 .arg(jobsRunning); 236 237 if (!inTimeWindow) … … 251 252 252 253 atMax = true; 253 254 } 255 else if (getCPUStats(totalTime, idleTime) && (idleTime * 100 / totalTime) < 25) 256 { 257 message += QString(" CPU near full capacity (%1% idle), " 258 "will not start new jobs") 259 .arg(idleTime * 100 / totalTime); 260 VERBOSE(VB_JOBQUEUE, LOC + message); 261 atMax = true; 262 } 254 263 else 255 264 { 256 265 VERBOSE(VB_JOBQUEUE, LOC + message); 257 266 atMax = false; 258 267 } 259 268 260 261 269 for (unsigned int x = 0; 262 (x < jobs.size()) && (jobsRunning < maxJobs); x++)270 x < jobs.size(); x++) 263 271 { 264 272 id = jobs[x].id; 265 273 chanid = jobs[x].chanid; … … 431 439 } 432 440 433 441 // never start or claim more than one job in a single run 434 if (startedJobAlready )442 if (startedJobAlready || atMax) 435 443 continue; 436 444 437 445 if ((inTimeWindow) && … … 470 478 } 471 479 } 472 480 473 if (startedJobAlready) 474 sleep(5); 475 else 476 sleep(sleepTime); 481 sleep(sleepTime); 477 482 } 478 483 } 479 484