<commit_before>#lang racket/base

(require profile/analyzer racket/gui/base)

(require "sandbox.rkt")

(provide generate-profile)

(define compiled-module-name 'optimization-coach-compiled-module)

(define (generate-profile this source)
  (define snapshots
    (run-inside-optimization-coach-sandbox
     this
     (lambda ()
       (parameterize ([current-module-declare-name
                       (make-resolved-module-path compiled-module-name)])
         (eval (let ([input (open-input-text-editor source)])
                 (port-count-lines! input)
                 (read-syntax #f input)))
         ;; Require, to run the body, without actually adding anything to the
         ;; current namespace, in case the module calls `eval'.
         (eval '(require profile/sampler))
         (eval `(let ([sampler (create-sampler (current-thread) 0.05)])
                  (dynamic-require '',compiled-module-name #f)
                  (sampler 'stop)
                  (sampler 'get-snapshots)))))))
  (for ([n (profile-nodes (analyze-samples snapshots))])
    (printf "~a -- ~a -- ~a -- ~a\n" (node-id n) (node-total n) (node-self n) (node-src n)))
  (profile-nodes (analyze-samples snapshots)))
<commit_msg>Only keep profile reports from the relevant file.<commit_after>#lang racket/base

(require profile/analyzer racket/gui/base)

(require "sandbox.rkt")

(provide generate-profile)

(define compiled-module-name 'optimization-coach-compiled-module)

(define (generate-profile this source)
  (define res-mpi (make-resolved-module-path compiled-module-name))
  (define snapshots
    (run-inside-optimization-coach-sandbox
     this
     (lambda ()
       (parameterize ([current-module-declare-name res-mpi])
         (eval (let ([input (open-input-text-editor source)])
                 (port-count-lines! input)
                 (read-syntax res-mpi input)))
         ;; Require, to run the body, without actually adding anything to the
         ;; current namespace, in case the module calls `eval'.
         (eval '(require profile/sampler))
         (eval `(let ([sampler (create-sampler (current-thread) 0.05)])
                  (dynamic-require '',compiled-module-name #f)
                  (sampler 'stop)
                  (sampler 'get-snapshots)))))))
  (define (right-file? node)
    (define src (node-src node))
    (equal? (and src (srcloc-source src)) res-mpi))
  (define nodes
    (filter right-file? (profile-nodes (analyze-samples snapshots))))
  (for ([n nodes])
    (printf "~a -- ~a -- ~a -- ~a\n" (node-id n) (node-total n) (node-self n) (node-src n)))
  nodes)

{'fraction_non_alphanumeric': 0.1440710699111626, 'fraction_numerical': 0.002317497103128621, 'mean_word_length': 2.6223776223776225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7583471', 'n_tokens_mistral': 822, 'n_tokens_neox': 770, 'n_words': 208}