sigar-loader icon indicating copy to clipboard operation
sigar-loader copied to clipboard

Provisioning failure for MacOS

Open pdeschen opened this issue 9 years ago • 5 comments

I'm getting odd behaviour on sigar provisioning on macos where while first provisioning works out of the box, subsequent ones just fail with a UnsatisfiedLinkError.

To reproduce, here is a small groovy file:

@Grab('io.kamon:sigar-loader:1.6.6-rev002') 

import java.io.File;
import kamon.sigar.SigarProvisioner;
import org.hyperic.sigar.*;

class CPU {
    static {
        SigarProvisioner.provision();
    }
    double percent(long pid) {
        final Sigar sigar = new Sigar();

        try {
            ProcCpu curPc = sigar.getProcCpu(pid);
            println curPc.getPercent();
            return curPc.getPercent();
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
}

cpu = new CPU();
cpu.percent(Long.valueOf(this.args[0]));

Then simply

groovy test.groovy `pidof iTerm`

Which returns with

Oct 01, 2015 4:26:49 PM kamon.sigar.SigarProvisioner discoverLocation
INFO: Using location provided by hard coded value.
Oct 01, 2015 4:26:49 PM kamon.sigar.SigarProvisioner provision
INFO: Sigar library provisioned: /Users/pdeschen/native/libsigar-universal64-macosx.dylib
0.0

Where we have

› ls -l ~/native
total 392
-rw-r--r-- 1 pdeschen staff 397440 Oct  1 16:26 libsigar-universal64-macosx.dylib

Then launching the script once more gets me:

› groovy test.groovy `pidof iTerm`
Oct 01, 2015 4:30:36 PM kamon.sigar.SigarProvisioner discoverLocation
INFO: Using location provided by hard coded value.
Caught: java.lang.UnsatisfiedLinkError: /Users/pdeschen/native/libsigar-universal64-macosx.dylib: dlopen(/Users/pdeschen/native/libsigar-universal64-macosx.dylib, 1): no suitable image found.  Did find:
    /Users/pdeschen/native/libsigar-universal64-macosx.dylib: file too short
java.lang.UnsatisfiedLinkError: /Users/pdeschen/native/libsigar-universal64-macosx.dylib: dlopen(/Users/pdeschen/native/libsigar-universal64-macosx.dylib, 1): no suitable image found.  Did find:
    /Users/pdeschen/native/libsigar-universal64-macosx.dylib: file too short
    at kamon.sigar.SigarProvisioner.provision(SigarProvisioner.java:179)
    at kamon.sigar.SigarProvisioner.provision(SigarProvisioner.java:135)
    at kamon.sigar.SigarProvisioner$provision.call(Unknown Source)
    at CPU.<clinit>(test.groovy:9)
    at test.run(test.groovy:24)

Because we have

› ls -l ~/native
total 0
-rw-r--r-- 1 pdeschen staff 0 Oct  1 16:30 libsigar-universal64-macosx.dylib
› uname -v
Darwin Kernel Version 14.5.0: Wed Jul 29 02:26:53 PDT 2015; root:xnu-2782.40.9~1/RELEASE_X86_64

pdeschen avatar Oct 01 '15 20:10 pdeschen

  1. copy/paste provisioner class in your project, see if you can reliably reproduce the error https://github.com/kamon-io/sigar-loader/blob/master/core/src/main/java/kamon/sigar/SigarProvisioner.java

  2. if so, add targetStream.flush(); at #L174, see if makes a difference https://github.com/kamon-io/sigar-loader/blob/master/core/src/main/java/kamon/sigar/SigarProvisioner.java#L174

Andrei-Pozolotin avatar Oct 02 '15 21:10 Andrei-Pozolotin

@Andrei-Pozolotin I'm a bit puzzled: I've cloned the project, issued sbt package from master, used the resulting jar in my groovy test script and I can't duplicate the error. I'll try to investigate the difference in the actual jars and report back.

pdeschen avatar Oct 02 '15 22:10 pdeschen

Version 1.6.6 seems to be missing the native/libsigar-universal64-macosx.dylib from within the sigar-loader-1.6.6.jar file.

Using version 1.6.5 with or without adding the provisioner class in my java project, I cannot reproduce the error I got with groovy.

All in all, 1.6.6 is definitely broken and missing the necessary native lib for macos. As for 1.6.5, I have no clue about what's going beside pointing finger at groovy. I would be curious to know whether you can duplicate yourself using groovy?

Edit: java v. groovy project

pdeschen avatar Oct 03 '15 22:10 pdeschen

  1. if you extract 1.6.6 jar content http://search.maven.org/#artifactdetails%7Cio.kamon%7Csigar-loader%7C1.6.6-rev002%7Cjar you will find native/libsigar-universal64-macosx.dylib inside; not sure how it is missing

  2. no groovy here, only scala - sorry. try to play with the provisioner class in groovy. it's just one little class :-) you can re-do it in groovy. did you try to add stream.flush()?

  3. if it is 100% reproducible error, please post here your code snippet

Andrei-Pozolotin avatar Oct 05 '15 01:10 Andrei-Pozolotin

@Andrei-Pozolotin if you extract http://maven.hyperic.org/external/org/hyperic/sigar/1.6.6.12/sigar-1.6.6.12-libs.zip there is not libsigar-universal64-macosx.dylib inside... :(

dpsoft avatar Oct 05 '15 03:10 dpsoft