github.com/verrazzano/verrazzano-monitoring-operator@v0.0.30/pkg/util/memory/jvmheap.go (about) 1 // Copyright (C) 2021, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package memory 5 6 import ( 7 "fmt" 8 ) 9 10 // UnitK is 1 Kilobyte 11 const UnitK = 1024 12 13 // UnitM is 1 Megabyte 14 const UnitM = 1024 * UnitK 15 16 // UnitG is 1 Gigabyte 17 const UnitG = 1024 * UnitM 18 19 // FormatJvmHeapMinMax returns the identical min and max JVM heap setting in the format 20 // Java expects like "-Xms2g -Xmx2g" 21 func FormatJvmHeapMinMax(heap string) string { 22 return fmt.Sprintf("-Xms%s -Xmx%s", heap, heap) 23 } 24 25 // FormatJvmHeapSize formats the string based on the size of the input value 26 // Return whole number (1200M not 1.2G) 27 // Return a minimum magnitude of K 28 func FormatJvmHeapSize(sizeB int64) string { 29 if sizeB >= UnitG { 30 if sizeB%UnitG == 0 { 31 // e.g. 50g 32 return fmt.Sprintf("%.0fg", float64(sizeB)/UnitG) 33 } 34 if sizeB%UnitM == 0 { 35 // e.g. 1500m - value in exact mb 36 return fmt.Sprintf("%.0fm", float64(sizeB)/UnitM) 37 } 38 // round up to next mb 39 return fmt.Sprintf("%.0fm", float64(sizeB)/UnitM+1) 40 } 41 if sizeB >= UnitM && sizeB%UnitM == 0 { 42 // e.g. 50m 43 return fmt.Sprintf("%.0fm", float64(sizeB)/UnitM) 44 } 45 if sizeB%UnitK == 0 { 46 // e.g. 1500k - value in exact kb 47 return fmt.Sprintf("%.0fk", float64(sizeB)/UnitK) 48 } 49 // round up to next kb 50 return fmt.Sprintf("%vk", sizeB/UnitK+1) 51 }