github.com/newrelic/go-agent@v3.26.0+incompatible/internal/sysinfo/memtotal_solaris.go (about)

     1  // Copyright 2020 New Relic Corporation. All rights reserved.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  package sysinfo
     5  
     6  /*
     7  #include <unistd.h>
     8  */
     9  import "C"
    10  
    11  // PhysicalMemoryBytes returns the total amount of host memory.
    12  func PhysicalMemoryBytes() (uint64, error) {
    13  	// The function we're calling on Solaris is
    14  	// long sysconf(int name);
    15  	var pages C.long
    16  	var pagesizeBytes C.long
    17  	var err error
    18  
    19  	pagesizeBytes, err = C.sysconf(C._SC_PAGE_SIZE)
    20  	if pagesizeBytes < 1 {
    21  		return 0, err
    22  	}
    23  	pages, err = C.sysconf(C._SC_PHYS_PAGES)
    24  	if pages < 1 {
    25  		return 0, err
    26  	}
    27  
    28  	return uint64(pages) * uint64(pagesizeBytes), nil
    29  }