     //--------------------------------------------------------------------------
     
     
-    // Assuming x86 for now
-    
-    public func isProcforeign(procCPUType: cpu_type_t) -> Bool {
-        // "The arch(arm) build configuration does not return true for ARM 64
-        //  devices. The arch(i386) build configuration returns true when code
-        //  is compiled for the 32–bit iOS simulator." ...
-//        #if arch(i386) || arch(x86_64)
-            return procCPUType != CPU_TYPE_X86_64 && procCPUType != CPU_TYPE_X86
-//        #elseif arch(arm) || arch(arm64)
-//            return procCPUType == CPU_TYPE_ARM || procCPUType == CPU_TYPE_ARM_64
-//        #endif
-    }
-    
-    
-    public class func isProc64Bit(procCPUType: cpu_type_t) -> Bool {
-        return procCPUType == CPU_TYPE_X86_64
-    }
-    
-    
-    private func getProcCPUType(pid: pid_t) -> cpu_type_t {
-        var result :Int32 = -1
-        var miblen = UInt(CTL_MAXNAME)
-        // count: CTL_MAXNAME
-        var mib    = [Int32](count: 12, repeatedValue:0)
-        var cputype : cpu_type_t = 0
-        
-        result = sysctlnametomib("sysctl.proc_cputype", &mib, &miblen)
-        
-        if (result != 0) {
-            miblen = 0
-            println("1 - ERROR getting CPU type for proc")
-        }
-        
-        if (miblen > 0) {
-            mib[Int(miblen)] = pid
-            var len : size_t = UInt(sizeof(cpu_type_t))
-            
-            result = sysctl(&mib, UInt32(miblen + UInt(1)), &cputype, &len, nil, 0)
-        }
-        
-        if (result != 0) {
-            println("2 - ERROR getting CPU type for proc")
-        }
-        
-        return cputype
-    }
-    
-    
-    /**
-    
-    :returns: On error, struct with all values set to 0.
-    */
-    private func hostBasicInfo() -> host_basic_info {
+    private static func hostBasicInfo() -> host_basic_info {
         // TODO: Why is host_basic_info.max_mem val different from sysctl?
         
         var size = HOST_BASIC_INFO_COUNT
         var hi = host_info_t.alloc(Int(HOST_BASIC_INFO_COUNT))
         hi.initialize(0)
         
-        let result = host_info(libport, HOST_BASIC_INFO, hi, &size)
-        
-        if (result != KERN_SUCCESS) {
-            #if DEBUG
-                println("ERROR - \(__FILE__):\(__FUNCTION__) - \(result)")
+        let result = host_info(mach_host_self(), HOST_BASIC_INFO, hi, &size)
+        
+        if (result != KERN_SUCCESS) {
+            #if DEBUG
+                println("ERROR - \(__FILE__):\(__FUNCTION__) - kern_result_t = "
+                        + "\(result)")
             #endif
             return host_basic_info(max_cpus         : 0,
                                    avail_cpus       : 0,

    }
    
    
    public func processList() { //-> task_array_t {
        var psets = processor_set_name_array_t.alloc(1)
        psets.initialize(0)
        var pcnt  : mach_msg_type_number_t = 0

        // Need root
        var result = host_processor_sets(mach_host_self(), &psets, &pcnt)
        if result != KERN_SUCCESS {
            // DEBUG
            // return
            println("ERROR - need root")
            return
        }
        
        
        // For each CPU
        result = host_processor_set_priv(mach_host_self(), psets[0], &pset);
        if result != KERN_SUCCESS {
            // DEBUG
            // return
            println("ERROR - get CPU")
            return
        }
        
        
        var processList = task_array_t.alloc(1)
        processList.initialize(0)
        var processCount  : mach_msg_type_number_t = 0
        result = processor_set_tasks(pset, &processList, &processCount);
        
        
        var procList : [libtop_psamp_s] = []
        
        
        // For each proc
        for var i = 0; i < Int(processCount); ++i {
            var pinfo = libtop_psamp_s()
            let process = processList[i]
            var pid : pid_t = 0
            
            
            result = pid_for_task(process, &pid)
            
            if (pid != 20849) {
                continue
            }
            
            println("PID: \(pid)")
            var kinfo_sk = kinfo_proc_systemkit(__p_starttime: timeval(tv_sec: 0, tv_usec: 0),
                                                p_flag: 0, p_stat: 0,
                                                p_comm: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
                                                e_ucred: _ucred(cr_ref: 0, cr_uid: 0, cr_ngroups: 0, cr_groups: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)),
                                                e_ppid: 0, e_pgid: 0)
            kinfo_for_pid(pid, &kinfo_sk)
            
            
            pinfo.uid  = kinfo_sk.e_ucred.cr_uid
            pinfo.ppid = kinfo_sk.e_ppid
            pinfo.pgrp = kinfo_sk.e_pgid
            //pinfo. = kinfo_sk.p_flag  // TODO: set this - see libtop_pinfo_s
            pinfo.started = kinfo_sk.__p_starttime
            
            pinfo.p_seq = pinfo.seq
            //pinfo.seq   = tsamp.seq  // TODO: Set this
            
            processMachPorts(process)
            processMemoryInformation(process)
            var power = processPowerInformationV2(process)
            
            println("GPU POWER: \(power.gpu_energy.task_gpu_utilisation)")
            
            var cpuType = getProcCPUType(pid)
            println("PROC TYPE: \(cpuType)")
            println("PROC Foreign: \(isProcforeign(cpuType))")
            println("PROC 64-bit: \(System.isProc64Bit(cpuType))")
            
            break
        }
    }


    private func processMemoryInformation(process: task_t) -> task_basic_info_64_data_t {
        var count = TASK_BASIC_INFO_64_COUNT
        var memoryInfo = task_info_t.alloc(Int(TASK_BASIC_INFO_64_COUNT))

        var result = task_info(process, UInt32(TASK_BASIC_INFO_64), memoryInfo, &count)

        if (result != KERN_SUCCESS) {
            // TODO: Or maybe just return memoryInfo?
            // TODO: Should we return result as well?
            return task_basic_info_64_data_t(suspend_count: 0,
                                             virtual_size: 0,
                                             resident_size: 0,
                                             user_time: time_value_t(seconds: 0, microseconds: 0),
                                             system_time: time_value_t(seconds: 0, microseconds: 0),
                                             policy: 0)
        }

        let data = UnsafePointer<task_basic_info_64_data_t>(memoryInfo).memory
        
        memoryInfo.dealloc(Int(TASK_BASIC_INFO_64_COUNT))
        
        println("VIRT MEM: \(data.virtual_size)")
        
        return data

    }
    
    
    /**
    Wired memory usage
    */
    private func processKerenlMemoryInformation(process: task_t) {
        /*
        kern_return_t kr;
        
        mach_msg_type_number_t count = TASK_KERNELMEMORY_INFO_COUNT;
        
        pinfo->psamp.p_palloc = pinfo->psamp.palloc;
        pinfo->psamp.p_pfree = pinfo->psamp.pfree;
        pinfo->psamp.p_salloc = pinfo->psamp.salloc;
        pinfo->psamp.p_sfree = pinfo->psamp.sfree;
        
        kr = task_info(task, TASK_KERNELMEMORY_INFO, (task_info_t)&pinfo->psamp.palloc, &count);
        return kr;
        */
        
        
        var result: kern_return_t
        var count: mach_msg_type_number_t = TASK_KERNELMEMORY_INFO_COUNT
        
        // TODO: Why just palloc?
        var palloc = task_info_t.alloc(Int(TASK_KERNELMEMORY_INFO_COUNT))
        
        result = task_info(process, TASK_KERNELMEMORY_INFO_COUNT, palloc, &count)
        
        if result != KERN_SUCCESS {
            return
        }
        
        let data = UnsafePointer<task_power_info_data_t>(palloc).memory
        
        palloc.dealloc(Int(TASK_KERNELMEMORY_INFO_COUNT))
        
        //return data
        
    }
    
    
    /**
    Number of Mach ports
    */
    private func processMachPorts(process : task_t) {
        // http://www.gnu.org/software/hurd/gnumach-doc/Port-Names.html
        /*
        kern_return_t kr;
        mach_msg_type_number_t ncnt, tcnt;
        mach_port_name_array_t names;
        mach_port_type_array_t types;
        
        pinfo->psamp.p_prt = pinfo->psamp.prt;
        
        kr = mach_port_names(task, &names, &ncnt, &types, &tcnt);
        if (kr != KERN_SUCCESS) return 0;
        
        pinfo->psamp.prt = ncnt;
        
        kr = mach_vm_deallocate(mach_task_self(), (mach_vm_address_t)(uintptr_t)names, ncnt * sizeof(*names));
        kr = mach_vm_deallocate(mach_task_self(), (mach_vm_address_t)(uintptr_t)types, tcnt * sizeof(*types));
        */
        
        var result: kern_return_t
        var ncnt: mach_msg_type_number_t = 0
        var tcnt: mach_msg_type_number_t = 0
        var names = mach_port_name_array_t.alloc(1)
        var types = mach_port_type_array_t.alloc(1)
        
        // UnsafeMutablePointer<mach_port_name_array_t>
        result = mach_port_names(process, &names, &ncnt, &types, &tcnt)
        
        if (result != KERN_SUCCESS) {
            println("PORT CALL: \(result)")
            return
        }
    
        println("PORT COUNT: \(ncnt)")

        // http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/vm_deallocate.html
        // sizeof(*names) = 4
        var address: mach_vm_address_t = UnsafePointer<mach_vm_address_t>(names).memory
        result = mach_vm_deallocate(mach_task_self_, address, UInt64(ncnt) * UInt64(sizeof(mach_port_name_t)))
        
        println("DEALLOC: \(result)")
    }
    
    
    private func processPowerInformation(process : task_t) -> task_power_info_data_t {
        var count = TASK_POWER_INFO_COUNT
        var powerInfo = task_info_t.alloc(Int(TASK_POWER_INFO_COUNT))
        var result = task_info(process, UInt32(TASK_POWER_INFO), powerInfo, &count)
        
        if result != KERN_SUCCESS {
            return task_power_info_data_t(total_user                 : 0,
                                          total_system               : 0,
                                          task_interrupt_wakeups     : 0,
                                          task_platform_idle_wakeups : 0,
                                          task_timer_wakeups_bin_1   : 0,
                                          task_timer_wakeups_bin_2   : 0)
        }
        
        let data = UnsafePointer<task_power_info_data_t>(powerInfo).memory
        
        powerInfo.dealloc(Int(TASK_POWER_INFO_COUNT))
        
        return data
    }
    
    
    private func processPowerInformationV2(process: task_t) -> task_power_info_v2_data_t {
        // Doesn't seem to work. Maybe need a newer GPU? Discrete GPU?
        // GPU - Returns the total gpu time used by the all the threads of the task
        
        var count = TASK_POWER_INFO_V2_COUNT
        var powerInfo = task_info_t.alloc(Int(TASK_POWER_INFO_V2_COUNT))
        var result = task_info(process, UInt32(TASK_POWER_INFO_V2), powerInfo, &count)
        
        if result != KERN_SUCCESS {
           let temp = task_power_info_data_t(total_user                 : 0,
                            total_system               : 0,
                            task_interrupt_wakeups     : 0,
                            task_platform_idle_wakeups : 0,
                            task_timer_wakeups_bin_1   : 0,
                            task_timer_wakeups_bin_2   : 0)
            let gpu_temp = gpu_energy_data(task_gpu_utilisation: 0, task_gpu_stat_reserved0: 0, task_gpu_stat_reserved1: 0, task_gpu_stat_reserved2: 0)
            return task_power_info_v2_data_t(cpu_energy: temp, gpu_energy: gpu_temp)

        }
        
        let data = UnsafePointer<task_power_info_v2_data_t>(powerInfo).memory
        
        powerInfo.dealloc(Int(TASK_POWER_INFO_V2_COUNT))
        
        return data
    }
    
    
    /**
    32-bit virtual memory statistics. Used for 32-bit iOS devices.
    */
    public func VMStatistics() -> vm_statistics {
        // This doesn't give you swap, may have to get it from sysctl
        var size = HOST_VM_INFO_COUNT
        var hi = host_info_t.alloc(Int(HOST_VM_INFO_COUNT))
        hi.initialize(0)
        
        let result = host_statistics(host, HOST_VM_INFO, hi, &size)
        
        if (result != KERN_SUCCESS) {
            #if DEBUG
                println("ERROR - \(__FILE__):\(__FUNCTION__) - kern_result_t ="
                        + " \(result)")
            #endif
            return vm_statistics(free_count: 0,
                                 active_count      : 0,
                                 inactive_count    : 0,
                                 wire_count        : 0,
                                 zero_fill_count   : 0,
                                 reactivations     : 0,
                                 pageins           : 0,
                                 pageouts          : 0,
                                 faults            : 0,
                                 cow_faults        : 0,
                                 lookups           : 0,
                                 hits              : 0,
                                 purgeable_count   : 0,
                                 purges            : 0,
                                 speculative_count : 0)
        }
        
        let data = UnsafePointer<vm_statistics>(hi).memory
        
        hi.dealloc(Int(HOST_VM_INFO_COUNT))
        
        return data
    }
    
    
    /**
    64-bit virtual memory statistics. This should apply to all Mac's that run
    10.9 and above, and iPhone 5S and on, and iPad Air & iPad Mini 2 and on.
    // Swift runs on 10.9 and above, and 10.9 is x86_64 only. On iOS though
    // its 7 and above, with both ARM & ARM64
    // TODO: Does iOS 32-bit have supported for commpressed memory?
    // TODO: For now we have two methods, but we could use arch macros
    */
    public func VMStatistics64() -> vm_statistics64 {
        var size = HOST_VM_INFO64_COUNT
        var hi = host_info_t.alloc(Int(HOST_VM_INFO64_COUNT))
        hi.initialize(0)
        
        let result = host_statistics64(host, HOST_VM_INFO64, hi, &size)
        
        if (result != KERN_SUCCESS) {
            #if DEBUG
                println("ERROR - \(__FILE__):\(__FUNCTION__) - kern_result_t ="
                        + " \(result)")
            #endif
            return vm_statistics64(free_count                             : 0,
                                   active_count                           : 0,

        
        return data
    }

    
    private static func hostLoadInfo() -> host_load_info {
        // - Can get stat from cl with w or uptime as well
        // - getloadavg()
        // http://en.wikipedia.org/wiki/Load_(computing)
        
        var size = HOST_LOAD_INFO_COUNT
        var hi = host_info_t.alloc(Int(HOST_LOAD_INFO_COUNT))
