<commit_before>(ns riemann.jvm-profiler
  (:require [riemann.jvm-profiler.stack :as stack]
            [riemann.client.http :as client])
  (:import (java.lang StackTraceElement)))

(def http-client client/client)
(def localhost client/localhost)

(def tags ["jvm" "profile"])

(defn report
  "Send information about stack statistics to Riemann."
  [client dt host prefix stats]
  (let [{:keys [rate sample]} stats]
    (->> sample
         stack/hotspots
         (map (fn [[^StackTraceElement frame
                    {:keys [self-time top-trace top-trace-time]}]]
                {:host        (or host (client/localhost))
                 :service     (str prefix "profiler fn "
                                   (.getClassName frame) " "
                                   (.getMethodName frame))
                 :file        (.getFileName frame)
                 :line        (.getLineNumber frame)
                 :description (stack/trace->string top-trace)
                 :state       "ok"
                 :metric      self-time
                 :ttl         (* 2 dt)
                 :tags        tags}))
         (concat [{:host    host
                   :service (str prefix "profiler rate")
                   :state   "ok"
                   :metric  rate
                   :ttl     (* 2 dt)
                   :tags    tags}])
         (client/send-events client))))

(defn start
  "Starts profiling, sending events to the given Riemann client. Call (stop!)
  with start's return value to stop profiling. Options:

  :client     Riemann HTTP client to send events to. Right now, Because Of
              Reasons (hadoop), we only support our own built-in client
              via (http-client). I'd like to have a runtime check for
              riemann-clojure-client and support its interfaces as well, but
              we can't add the official client as a dep to the jar without
              breaking Hadoop. Shoot me a PR?
  :host       Used to construct a client if no client is given.
  :port       Riemann HTTP port.
  :prefix     Service prefix for distinguishing this telemetry from other apps
              (default \"\")
  :localhost  Override the hostname (default: nil; calls (localhost))
  :dt         How often to send telemetry events to Riemann, in seconds<commit_msg>Correctly fill in default host for profiler rate.<commit_after>(ns riemann.jvm-profiler
  (:require [riemann.jvm-profiler.stack :as stack]
            [riemann.client.http :as client])
  (:import (java.lang StackTraceElement)))

(def http-client client/client)
(def localhost client/localhost)

(def tags ["jvm" "profile"])

(defn report
  "Send information about stack statistics to Riemann."
  [client dt host prefix stats]
  (let [{:keys [rate sample]} stats]
    (->> sample
         stack/hotspots
         (map (fn [[^StackTraceElement frame
                    {:keys [self-time top-trace top-trace-time]}]]
                {:host        (or host (client/localhost))
                 :service     (str prefix "profiler fn "
                                   (.getClassName frame) " "
                                   (.getMethodName frame))
                 :file        (.getFileName frame)
                 :line        (.getLineNumber frame)
                 :description (stack/trace->string top-trace)
                 :state       "ok"
                 :metric      self-time
                 :ttl         (* 2 dt)
                 :tags        tags}))
         (concat [{:host    (or host (client/localhost))
                   :service (str prefix "profiler rate")
                   :state   "ok"
                   :metric  rate
                   :ttl     (* 2 dt)
                   :tags    tags}])
         (client/send-events client))))

(defn start
  "Starts profiling, sending events to the given Riemann client. Call (stop!)
  with start's return value to stop profiling. Options:

  :client     Riemann HTTP client to send events to. Right now, Because Of
              Reasons (hadoop), we only support our own built-in client
              via (http-client). I'd like to have a runtime check for
              riemann-clojure-client and support its interfaces as well, but
              we can't add the official client as a dep to the jar without
              breaking Hadoop. Shoot me a PR?
  :host       Used to construct a client if no client is given.
  :port       Riemann HTTP port.
  :prefix     Service prefix for distinguishing this telemetry from other apps
              (default \"\")
  :localhost  Override the hostname (default: nil; calls (localhost))
  :dt         How often to send telemetry events to Riemann, in seconds
{'fraction_non_alphanumeric': 0.08714224690303289, 'fraction_numerical': 0.0008543357539513029, 'mean_word_length': 1.672945205479452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2107548', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1162, 'n_words': 458}