| 27 | ) |
| 28 | |
| 29 | func main() { |
| 30 | h := flags.DefaultHeadRoom |
| 31 | j := flags.DefaultJVMOptions |
| 32 | l := flags.DefaultLoadedClassCount |
| 33 | t := flags.DefaultThreadCount |
| 34 | m := flags.DefaultTotalMemory |
| 35 | |
| 36 | c := calculator.Calculator{HeadRoom: &h, JvmOptions: &j, LoadedClassCount: &l, ThreadCount: &t, TotalMemory: &m} |
| 37 | |
| 38 | flag.Var(c.HeadRoom, flags.FlagHeadRoom, "percentage of total memory available which will be left unallocated to cover JVM overhead") |
| 39 | flag.Var(c.JvmOptions, flags.FlagJVMOptions, "JVM options, typically JAVA_OPTS") |
| 40 | flag.Var(c.LoadedClassCount, flags.FlagLoadedClassCount, "the number of classes that will be loaded when the application is running") |
| 41 | flag.Var(c.ThreadCount, flags.FlagThreadCount, "the number of user threads") |
| 42 | flag.Var(c.TotalMemory, "total-memory", "total memory available to the application, typically expressed with size classification (B, K, M, G, T)") |
| 43 | flag.Parse() |
| 44 | |
| 45 | if !validate(c.HeadRoom, c.JvmOptions, c.LoadedClassCount, c.ThreadCount, c.TotalMemory) { |
| 46 | _, _ = fmt.Fprintln(os.Stderr, "") |
| 47 | flag.Usage() |
| 48 | os.Exit(1) |
| 49 | } |
| 50 | |
| 51 | o, err := c.Calculate() |
| 52 | if err != nil { |
| 53 | _, _ = fmt.Fprintf(os.Stderr, err.Error()) |
| 54 | os.Exit(2) |
| 55 | } |
| 56 | |
| 57 | s := make([]string, len(o)) |
| 58 | for i, t := range o { |
| 59 | s[i] = t.String() |
| 60 | } |
| 61 | |
| 62 | fmt.Println(output(o)) |
| 63 | } |
| 64 | |
| 65 | func output(o []fmt.Stringer) string { |
| 66 | s := make([]string, len(o)) |