<commit_before>module azmon

open Nessos.UnionArgParser
open System
open System.Threading

type Arguments =
    | [<Mandatory>] [<EqualsAssignment>] Source of string
    | [<EqualsAssignment>] Sink of string
    |  Stop
with
    interface IArgParserTemplate with
        member s.Usage =
            match s with
            | Source _ -> "Publish events from a named ETW event source."
            | Sink _ -> "Only support HTTP URLs at the moment. No sources means logging to stdout."
            | Stop -> "Stop listening to events (affects ALL running azmon processes). If present, other parameters are ignored."

let parser = UnionArgParser.Create<Arguments>()
let usage = parser.Usage()

let registerExitOnCtrlC (canceller: CancellationTokenSource) session =
    Console.CancelKeyPress
    |> Observable.subscribe (fun _ ->
        // Like tears in rain... time to die.
        // Because it's a clean shutdown, we close the trace
        // session.
        Monitor.stop session |> ignore
        canceller.Cancel())
    |> ignore

[<EntryPoint>]
let main argv =
    try
        if Array.isEmpty argv then
            printfn "%s" usage
            0
        else
            let args = parser.Parse argv

            if args.Contains <@ Stop @> then
                Monitor.stopSessionByName "Azmon-Trace-Session" |> ignore
                0
            else
                let canceller = new CancellationTokenSource()

                let runUntilCancelled = async {
                                let monitoring = Monitor.start "Azmon-Trace-Session" (args.GetResults <@ Source @>)
                                registerExitOnCtrlC canceller monitoring

                                use publishing = monitoring.Subject
                                                 |> Publish.start (args.GetResults <@ Sink @>)

                                while true do
                                    do! Async.Sleep(1000)

                                // Do not put any code here. It's on the far
                                // side of an infinite loop, so you'll be
                                // waiting a while for it to execute!

                                return 0
                           }
                Async.RunSynchronously(runUntilCancelled, 10000, canceller.Token)
    with
    | :? System.ArgumentException as e ->
        printfn "%s" usage
        printfn "-------"
        printfn "%A" (e.ToString())
        1<commit_msg>Actually, I think I prefer the --port 8080 style args over --port=8080.<commit_after>module azmon

open Nessos.UnionArgParser
open System
open System.Threading

type Arguments =
    | [<Mandatory>] Source of string
    | Sink of string
    | Stop
with
    interface IArgParserTemplate with
        member s.Usage =
            match s with
            | Source _ -> "Publish events from a named ETW event source."
            | Sink _ -> "Only support HTTP URLs at the moment. No sources means logging to stdout."
            | Stop -> "Stop listening to events (affects ALL running azmon processes). If present, other parameters are ignored."

let parser = UnionArgParser.Create<Arguments>()
let usage = parser.Usage()

let registerExitOnCtrlC (canceller: CancellationTokenSource) session =
    Console.CancelKeyPress
    |> Observable.subscribe (fun _ ->
        // Like tears in rain... time to die.
        // Because it's a clean shutdown, we close the trace
        // session.
        Monitor.stop session |> ignore
        canceller.Cancel())
    |> ignore

[<EntryPoint>]
let main argv =
    try
        if Array.isEmpty argv then
            printfn "%s" usage
            0
        else
            let args = parser.Parse argv

            if args.Contains <@ Stop @> then
                Monitor.stopSessionByName "Azmon-Trace-Session" |> ignore
                0
            else
                let canceller = new CancellationTokenSource()

                let runUntilCancelled = async {
                                let monitoring = Monitor.start "Azmon-Trace-Session" (args.GetResults <@ Source @>)
                                registerExitOnCtrlC canceller monitoring

                                use publishing = monitoring.Subject
                                                 |> Publish.start (args.GetResults <@ Sink @>)

                                while true do
                                    do! Async.Sleep(1000)

                                // Do not put any code here. It's on the far
                                // side of an infinite loop, so you'll be
                                // waiting a while for it to execute!

                                return 0
                           }
                Async.RunSynchronously(runUntilCancelled, 10000, canceller.Token)
    with
    | :? System.ArgumentException as e ->
        printfn "%s" usage
        printfn "-------"
        printfn "%A" (e.ToString())
        1
{'fraction_non_alphanumeric': 0.07642669893123613, 'fraction_numerical': 0.006856221012300867, 'mean_word_length': 1.4337585868498528, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '618465', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1162, 'n_words': 408}