[Information] Use ptr to get process usage 00/145300/6
authorKichan Kwon <k_c.kwon@samsung.com>
Tue, 22 Aug 2017 04:36:07 +0000 (13:36 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 13 Sep 2017 07:45:55 +0000 (16:45 +0900)
- CAPI uses double pointer, but CSAPI uses pointer

Change-Id: Ib244074ccfec28f7a9b866aaab89eb98c092fd6d
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/Tizen.System.Information/Interop/Interop.RuntimeInfo.cs [changed mode: 0644->0755]
src/Tizen.System.Information/RuntimeInfo/RuntimeInformation.cs

old mode 100644 (file)
new mode 100755 (executable)
index 21ab05e..705df5a
@@ -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);
index 93c76c3..f5513d2 100755 (executable)
@@ -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<int>();
             Interop.RuntimeInfo.ProcessMemoryInfo[] processMemoryArray = new Interop.RuntimeInfo.ProcessMemoryInfo[pid.Count<int>()];
             Dictionary<int, ProcessMemoryInformation> map = new Dictionary<int, ProcessMemoryInformation>();
-            int ret = Interop.RuntimeInfo.GetProcessMemoryInfo(processArray, pid.Count<int>(), out processMemoryArray);
+            IntPtr ptr = new IntPtr();
+            int ret = Interop.RuntimeInfo.GetProcessMemoryInfo(processArray, pid.Count<int>(), 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<int>(); i++)
+            {
+                processMemoryArray[i] = Marshal.PtrToStructure<Interop.RuntimeInfo.ProcessMemoryInfo>(ptr);
+                ptr += Marshal.SizeOf<Interop.RuntimeInfo.ProcessCpuUsage>();
+            }
+
             int idx = 0;
             foreach (Interop.RuntimeInfo.ProcessMemoryInfo cur in processMemoryArray)
             {
@@ -358,13 +366,20 @@ namespace Tizen.System
             int[] processArray = pid.ToArray<int>();
             Interop.RuntimeInfo.ProcessCpuUsage[] processCpuUsageArray = new Interop.RuntimeInfo.ProcessCpuUsage[pid.Count<int>()];
             Dictionary<int, ProcessCpuUsage> map = new Dictionary<int, ProcessCpuUsage>();
-            int ret = Interop.RuntimeInfo.GetProcessCpuUsage(processArray, pid.Count<int>(), out processCpuUsageArray);
+            IntPtr ptr = new IntPtr();
+            int ret = Interop.RuntimeInfo.GetProcessCpuUsage(processArray, pid.Count<int>(), 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<int>(); i++)
+            {
+                processCpuUsageArray[i] = Marshal.PtrToStructure<Interop.RuntimeInfo.ProcessCpuUsage>(ptr);
+                ptr += Marshal.SizeOf<Interop.RuntimeInfo.ProcessCpuUsage>();
+            }
+
             int idx = 0;
             foreach (Interop.RuntimeInfo.ProcessCpuUsage cur in processCpuUsageArray)
             {
@@ -403,7 +418,7 @@ namespace Tizen.System
         /// <since_tizen> 3 </since_tizen>
         /// <param name="coreId">The index (from 0) of the CPU core that you want to know the frequency of.</param>
         /// <returns>The current frequency(MHz) of processor.</returns>
-        /// <exception cref="ArgumentException">Thrown when the <paramref name="coreid"/> is invalid.</exception>
+        /// <exception cref="ArgumentException">Thrown when the <paramref name="coreId"/> is invalid.</exception>
         /// <exception cref="IOException">Thrown when an I/O error occurs while reading from system.</exception>
         /// <exception cref="NotSupportedException">Thrown when this system does not store the current CPU frequency.</exception>
         public static int GetProcessorCurrentFrequency(int coreId)
@@ -424,7 +439,7 @@ namespace Tizen.System
         /// <since_tizen> 3 </since_tizen>
         /// <param name="coreId">The index (from 0) of CPU core that you want to know the frequency of.</param>
         /// <returns>The max frequency(MHz) of processor.</returns>
-        /// <exception cref="ArgumentException">Thrown when the <paramref name="coreid"/> is invalid.</exception>
+        /// <exception cref="ArgumentException">Thrown when the <paramref name="coreId"/> is invalid.</exception>
         /// <exception cref="IOException">Thrown when an I/O error occurs while reading from system.</exception>
         /// <exception cref="NotSupportedException">Thrown when this system does not store the max CPU frequency.</exception>
         public static int GetProcessorMaxFrequency(int coreId)