From 9f53e468c7b30d1efaaefeaca368d69b64b9535e Mon Sep 17 00:00:00 2001 From: Kichan Kwon Date: Tue, 22 Aug 2017 13:36:07 +0900 Subject: [PATCH] [Information] Use ptr to get process usage - CAPI uses double pointer, but CSAPI uses pointer Change-Id: Ib244074ccfec28f7a9b866aaab89eb98c092fd6d Signed-off-by: Kichan Kwon --- .../Interop/Interop.RuntimeInfo.cs | 4 ++-- .../RuntimeInfo/RuntimeInformation.cs | 23 ++++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) mode change 100644 => 100755 src/Tizen.System.Information/Interop/Interop.RuntimeInfo.cs diff --git a/src/Tizen.System.Information/Interop/Interop.RuntimeInfo.cs b/src/Tizen.System.Information/Interop/Interop.RuntimeInfo.cs old mode 100644 new mode 100755 index 21ab05e..705df5a --- a/src/Tizen.System.Information/Interop/Interop.RuntimeInfo.cs +++ b/src/Tizen.System.Information/Interop/Interop.RuntimeInfo.cs @@ -78,13 +78,13 @@ internal static partial class Interop public static extern int GetSystemMemoryInfo(out MemoryInfo memoryInfo); [DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_process_memory_info")] - public static extern int GetProcessMemoryInfo(int[] pid, int size, out ProcessMemoryInfo[] array); + public static extern int GetProcessMemoryInfo(int[] pid, int size, ref IntPtr array); [DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_cpu_usage")] public static extern int GetCpuUsage(out CpuUsage cpuUsage); [DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_process_cpu_usage")] - public static extern int GetProcessCpuUsage(int[] pid, int size, out ProcessCpuUsage[] array); + public static extern int GetProcessCpuUsage(int[] pid, int size, ref IntPtr array); [DllImport(Libraries.RuntimeInfo, EntryPoint = "runtime_info_get_processor_count")] public static extern int GetProcessorCount(out int processorCount); diff --git a/src/Tizen.System.Information/RuntimeInfo/RuntimeInformation.cs b/src/Tizen.System.Information/RuntimeInfo/RuntimeInformation.cs index 93c76c3..f5513d2 100755 --- a/src/Tizen.System.Information/RuntimeInfo/RuntimeInformation.cs +++ b/src/Tizen.System.Information/RuntimeInfo/RuntimeInformation.cs @@ -21,6 +21,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.ComponentModel; +using System.Runtime.InteropServices; namespace Tizen.System { @@ -306,13 +307,20 @@ namespace Tizen.System int[] processArray = pid.ToArray(); Interop.RuntimeInfo.ProcessMemoryInfo[] processMemoryArray = new Interop.RuntimeInfo.ProcessMemoryInfo[pid.Count()]; Dictionary map = new Dictionary(); - int ret = Interop.RuntimeInfo.GetProcessMemoryInfo(processArray, pid.Count(), out processMemoryArray); + IntPtr ptr = new IntPtr(); + int ret = Interop.RuntimeInfo.GetProcessMemoryInfo(processArray, pid.Count(), ref ptr); if (ret != (int)RuntimeInfoError.None) { Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process memory information"); RuntimeInfoErrorFactory.ThrowException(ret); } + for (int i = 0; i < pid.Count(); i++) + { + processMemoryArray[i] = Marshal.PtrToStructure(ptr); + ptr += Marshal.SizeOf(); + } + int idx = 0; foreach (Interop.RuntimeInfo.ProcessMemoryInfo cur in processMemoryArray) { @@ -358,13 +366,20 @@ namespace Tizen.System int[] processArray = pid.ToArray(); Interop.RuntimeInfo.ProcessCpuUsage[] processCpuUsageArray = new Interop.RuntimeInfo.ProcessCpuUsage[pid.Count()]; Dictionary map = new Dictionary(); - int ret = Interop.RuntimeInfo.GetProcessCpuUsage(processArray, pid.Count(), out processCpuUsageArray); + IntPtr ptr = new IntPtr(); + int ret = Interop.RuntimeInfo.GetProcessCpuUsage(processArray, pid.Count(), ref ptr); if (ret != (int)RuntimeInfoError.None) { Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process cpu usage"); RuntimeInfoErrorFactory.ThrowException(ret); } + for (int i = 0; i < pid.Count(); i++) + { + processCpuUsageArray[i] = Marshal.PtrToStructure(ptr); + ptr += Marshal.SizeOf(); + } + int idx = 0; foreach (Interop.RuntimeInfo.ProcessCpuUsage cur in processCpuUsageArray) { @@ -403,7 +418,7 @@ namespace Tizen.System /// 3 /// The index (from 0) of the CPU core that you want to know the frequency of. /// The current frequency(MHz) of processor. - /// Thrown when the is invalid. + /// Thrown when the is invalid. /// Thrown when an I/O error occurs while reading from system. /// Thrown when this system does not store the current CPU frequency. public static int GetProcessorCurrentFrequency(int coreId) @@ -424,7 +439,7 @@ namespace Tizen.System /// 3 /// The index (from 0) of CPU core that you want to know the frequency of. /// The max frequency(MHz) of processor. - /// Thrown when the is invalid. + /// Thrown when the is invalid. /// Thrown when an I/O error occurs while reading from system. /// Thrown when this system does not store the max CPU frequency. public static int GetProcessorMaxFrequency(int coreId) -- 2.7.4