Random Bits of Open Code

Check-in [b2f7e01263]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added functions for generating peak usage
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:b2f7e012634ebe0b9b45163d4dd6379890e8925d
User & Date: jmoon18 2019-04-24 22:09:49
Context
2019-04-26
23:04
Updated peak html generation for single users check-in: d0f85f520a user: jmoon18 tags: trunk
2019-04-24
22:09
Added functions for generating peak usage check-in: b2f7e01263 user: jmoon18 tags: trunk
22:07
Added gen-peak-for-user to commmand processing check-in: d057b9bff9 user: jmoon18 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ringchart/src/cstats.scm.

391
392
393
394
395
396
397
398
399






















































































      (print "ERROR: Bad record! " my-rec)))
    (if (not db-in)
	(close-database db))))


(define (get-rollup-record db id)
  (query fetch-row (sql db "SELECT id,uid,pid,total,cores_tot,actual, cores_act FROM rollup WHERE id=?;") id))

)






























































































|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
      (print "ERROR: Bad record! " my-rec)))
    (if (not db-in)
	(close-database db))))


(define (get-rollup-record db id)
  (query fetch-row (sql db "SELECT id,uid,pid,total,cores_tot,actual, cores_act FROM rollup WHERE id=?;") id))


(define (gen-peak-for-user-orig user)
   (let* ((jobs-db  (open-db "jobs.db")))
        (print "Getting peak data for " user)
        (let* ((last-peak-cores 0)
               (highest-peak 0)
               (highest-peak-cores 0)
               (select-stmt (prepare jobs-db "select count(*), sum(num_cpus) from jobs where user=? and start_time <= ? and finish_time > ?")))
          (for-each
            (lambda (job)
              ;;(print job)
              (let* ((myrow  (query fetch-row select-stmt user (car job) (car job))))
                ;;(print myrow)
                (if (not (= last-peak-cores (cadr myrow))) (print (car job) " " myrow))
                (set! last-peak-cores (cadr myrow))
                (if (> (car myrow) highest-peak) (set! highest-peak (car myrow)))
                (if (> (cadr myrow) highest-peak-cores) (set! highest-peak-cores (cadr myrow)))
              )
            )
          (query fetch-rows (sql jobs-db "select distinct start_time from jobs where user=? order by start_time asc limit 20") user) 
          )
          (print "Highest peak for " user " is " highest-peak)
        )
   )
)


(define (gen-peak-for-user user)
   (let* ((jobs-db  (open-db "jobs.db")))
        (print "Getting peak data for " user)
        (let* ((last-peak-cores 0)
               (highest-peak 0)
               (highest-peak-cores 0)
               (iterator 0)
               (previous-time-stamp (current-seconds))
               (select-stmt (prepare jobs-db "select count(*), sum(num_cpus) from jobs where user=? and start_time <= ? and finish_time > ?"))
               (alljobs (query fetch-rows (sql jobs-db "select jobid, start_time, finish_time, num_cpus from jobs where user=? order by start_time asc limit 40000000") user)))
          (print "Number of jobs: " (length+ alljobs))
          (for-each
            (lambda (job)
              (let* ((job-start-time (cadr job))
                     (qualifying-jobs 
                          (filter (lambda (x)
                              (let* ((my-start (cadr x))
                                     (my-end   (caddr x)))
                                     (if (and (>= job-start-time my-start) (<= job-start-time my-end)) #t #f)
                              )
                             )
                           alljobs)))
              (let* ((cores (apply + (map cadddr qualifying-jobs))))
                ;;(print "Cores: " cores)
                (set! iterator (+ iterator 1))
                (if (= 0 (modulo iterator 500)) 
                    (begin
                      (print (current-seconds) " " iterator " records/second="  (/ 500 (- (current-seconds) previous-time-stamp)) " " (- (current-seconds) previous-time-stamp) " seconds" )
                      (set! previous-time-stamp (current-seconds))
                      (set! alljobs (filter (lambda(x) (if (<= job-start-time (caddr x)) #t #f)) alljobs))
                      (print "Number of jobs left: " (length+ alljobs))
                    )
                )
                (if (> cores highest-peak-cores) (set! highest-peak-cores cores))
              ) 
              ;;(print "Qualifying jobs: " qualifying-jobs)
              )
            )
          alljobs
          )
          (print "Highest peak for " user " is " highest-peak)
        )
   )
)


(define (gen-peak-data)
  (let* ((people-db (open-db "people.db")))
    (for-each
      (lambda(user)
        (gen-peak-for-user user)
      )
    (query fetch-rows (sql people-db "select uid from people"))
    )
  ))




)