+++ /dev/null
-/*
-* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the License);
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an AS IS BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.ComponentModel;
-
-namespace Tizen.System
-{
- /// <summary>
- /// The structure for CPU usage.
- /// </summary>
- public class CpuUsage
- {
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal CpuUsage(Interop.RuntimeInfo.CpuUsage usage)
- {
- IoWait = usage.IoWait;
- Nice = usage.IoWait;
- System = usage.System;
- User = usage.User;
- }
- /// <summary>
- /// Running time of un-niced user processes (Percent).
- /// </summary>
- public double User { get; internal set; }
- /// <summary>
- /// Running time of kernel processes (Percent).
- /// </summary>
- public double System { get; internal set; }
- /// <summary>
- /// Running time of niced user processes (Percent).
- /// </summary>
- public double Nice { get; internal set; }
- /// <summary>
- /// Time waiting for I/O completion (Percent).
- /// </summary>
- public double IoWait { get; internal set; }
- }
-
- /// <summary>
- /// The structure for CPU usage per process.
- /// </summary>
- public class ProcessCpuUsage
- {
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal ProcessCpuUsage(Interop.RuntimeInfo.ProcessCpuUsage usage)
- {
- UTime = usage.UTime;
- STime = usage.STime;
- }
- /// <summary>
- /// The amount of time this process has been scheduled in user mode (clock ticks).
- /// </summary>
- public uint UTime { get; internal set; }
- /// <summary>
- /// The amount of time this process has been scheduled in kernel mode (clock ticks).
- /// </summary>
- public uint STime { get; internal set; }
- }
-}
+++ /dev/null
-/*
-* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the License);
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an AS IS BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.ComponentModel;
-
-namespace Tizen.System
-{
- /// <summary>
- /// Memory information.
- /// </summary>
- public class SystemMemoryInformation
- {
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal SystemMemoryInformation(Interop.RuntimeInfo.MemoryInfo info)
- {
- Total = info.Total;
- Used = info.Used;
- Cache = info.Cache;
- Free = info.Free;
- Swap = info.Swap;
- }
- /// <summary>
- /// Total memory (KiB).
- /// </summary>
- public int Total { get; internal set; }
- /// <summary>
- /// Used memory (KiB).
- /// </summary>
- public int Used { get; internal set; }
- /// <summary>
- /// Free memory (KiB).
- /// </summary>
- public int Free { get; internal set; }
- /// <summary>
- /// Cache memory (KiB).
- /// </summary>
- public int Cache { get; internal set; }
- /// <summary>
- /// Swap memory (KiB).
- /// </summary>
- public int Swap { get; internal set; }
- }
-
- /// <summary>
- /// Memory information per process.
- /// </summary>
- public class ProcessMemoryInformation
- {
- [EditorBrowsable(EditorBrowsableState.Never)]
- internal ProcessMemoryInformation(Interop.RuntimeInfo.ProcessMemoryInfo info)
- {
- PrivateClean = info.PrivateClean;
- PrivateDirty = info.PrivateDirty;
- Pss = info.Pss;
- Rss = info.Rss;
- SharedClean = info.SharedClean;
- SharedDirty = info.SharedDirty;
- Vsz = info.Vsz;
- }
- /// <summary>
- /// Virtual memory size (KiB).
- /// </summary>
- public int Vsz { get; internal set; }
- /// <summary>
- /// Resident set size (KiB).
- /// </summary>
- public int Rss { get; internal set; }
- /// <summary>
- /// Proportional set size (KiB).
- /// </summary>
- public int Pss { get; internal set; }
- /// <summary>
- /// Not modified and mapped by other processes (KiB).
- /// </summary>
- public int SharedClean { get; internal set; }
- /// <summary>
- /// Modified and mapped by other processes (KiB).
- /// </summary>
- public int SharedDirty { get; internal set; }
- /// <summary>
- /// Not modified and available only to that process (KiB).
- /// </summary>
- public int PrivateClean { get; internal set; }
- /// <summary>
- /// Modified and available only to that process (KiB).
- /// </summary>
- public int PrivateDirty { get; internal set; }
- }
-}
internal static int is_TV_product = -1;
[EditorBrowsable(EditorBrowsableState.Never)]
- /// This function is for a TV product. It will be removed.
+ /* This function is for a TV product. It will be removed. */
internal static RuntimeInformationKey ConvertKeyIfTvProduct(RuntimeInformationKey key)
{
bool is_key_existed = false;
}
/// <summary>
- /// Gets the system memory information.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <returns>The system memory information structure.</returns>
- /// <exception cref="IOException">Thrown when I/O error occurs while reading from the system.</exception>
- public static SystemMemoryInformation GetSystemMemoryInformation()
- {
- Interop.RuntimeInfo.MemoryInfo info = new Interop.RuntimeInfo.MemoryInfo();
- int ret = Interop.RuntimeInfo.GetSystemMemoryInfo(out info);
- if (ret != (int)RuntimeInfoError.None)
- {
- Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get System memory information");
- RuntimeInfoErrorFactory.ThrowException(ret);
- }
-
- return new SystemMemoryInformation(info);
- }
-
- /// <summary>
- /// Gets the memory information per process.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <param name="pid">List of unique process ids.</param>
- /// <returns>List of memory information per process.</returns>
- /// <privilege>http://tizen.org/privilege/systemmonitor</privilege>
- /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is empty.</exception>
- /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system or requesting to the resource management daemon.</exception>
- /// <exception cref="OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
- /// <exception cref="UnauthorizedAccessException">Thrown when the caller does not have privilege to use this method.</exception>
- public static IDictionary<int, ProcessMemoryInformation> GetProcessMemoryInformation(IEnumerable<int> pid)
- {
- int[] processArray = pid.ToArray<int>();
- Interop.RuntimeInfo.ProcessMemoryInfo[] processMemoryArray = new Interop.RuntimeInfo.ProcessMemoryInfo[pid.Count<int>()];
- Dictionary<int, ProcessMemoryInformation> map = new Dictionary<int, ProcessMemoryInformation>();
- 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)
- {
- ProcessMemoryInformation processMemory = new ProcessMemoryInformation(cur);
- map.Add(processArray[idx], processMemory);
- idx++;
- }
-
- return map;
- }
-
- /// <summary>
- /// Gets the system CPU usage time.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <returns>The system CPU usage time structure.</returns>
- /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system.</exception>
- public static CpuUsage GetCpuUsage()
- {
- Interop.RuntimeInfo.CpuUsage usage = new Interop.RuntimeInfo.CpuUsage();
- int ret = Interop.RuntimeInfo.GetCpuUsage(out usage);
- if (ret != (int)RuntimeInfoError.None)
- {
- Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get cpu usage");
- RuntimeInfoErrorFactory.ThrowException(ret);
- }
- return new CpuUsage(usage);
- }
-
- /// <summary>
- /// Gets the CPU usage time per process.
- /// </summary>
- /// <since_tizen> 3 </since_tizen>
- /// <param name="pid">List of unique process ids.</param>
- /// <returns>List of CPU usage information per process.</returns>
- /// <privilege>http://tizen.org/privilege/systemmonitor</privilege>
- /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is empty.</exception>
- /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system or requesting to the resource management daemon.</exception>
- /// <exception cref="OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
- /// <exception cref="UnauthorizedAccessException">Thrown when the caller does not have privilege to use this method.</exception>
- public static IDictionary<int, ProcessCpuUsage> GetProcessCpuUsage(IEnumerable<int> pid)
- {
- int[] processArray = pid.ToArray<int>();
- Interop.RuntimeInfo.ProcessCpuUsage[] processCpuUsageArray = new Interop.RuntimeInfo.ProcessCpuUsage[pid.Count<int>()];
- Dictionary<int, ProcessCpuUsage> map = new Dictionary<int, ProcessCpuUsage>();
- 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)
- {
- ProcessCpuUsage processUsage = new ProcessCpuUsage(cur);
- map.Add(processArray[idx], processUsage);
- idx++;
- }
-
- return map;
- }
-
- /// <summary>
- /// Gets the number of processors.
- /// </summary>
- /// <value>The number of processors.</value>
- /// <exception cref="IOException">Thrown when an I/O error occurs while reading from system.</exception>
- public static int ProcessorCount
- {
- get
- {
- int count;
- int ret = Interop.RuntimeInfo.GetProcessorCount(out count);
- if (ret != (int)RuntimeInfoError.None)
- {
- Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor count");
- RuntimeInfoErrorFactory.ThrowException(ret);
- }
-
- return count;
- }
- }
-
- /// <summary>
- /// Gets the current frequency of the processor.
- /// </summary>
- /// <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="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)
- {
- int frequency;
- int ret = Interop.RuntimeInfo.GetProcessorCurrentFrequency(coreId, out frequency);
- if (ret != (int)RuntimeInfoError.None)
- {
- Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor current frequency");
- RuntimeInfoErrorFactory.ThrowException(ret);
- }
- return frequency;
- }
-
- /// <summary>
- /// Gets the max frequency of the processor.
- /// </summary>
- /// <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="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)
- {
- int frequency;
- int ret = Interop.RuntimeInfo.GetProcessorMaxFrequency(coreId, out frequency);
- if (ret != (int)RuntimeInfoError.None)
- {
- Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor max frequency");
- RuntimeInfoErrorFactory.ThrowException(ret);
- }
- return frequency;
- }
-
- /// <summary>
/// (event) BluetoothEnabled is raised when the system preference for Bluetooth is changed.
/// </summary>
public static event EventHandler<RuntimeKeyStatusChangedEventArgs> BluetoothEnabled
--- /dev/null
+/*
+* Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+
+namespace Tizen.System
+{
+ /// <summary>
+ /// The class for CPU usage per process.
+ /// </summary>
+ public class ProcessCpuUsage
+ {
+ private int[] Pids;
+ private Interop.RuntimeInfo.ProcessCpuUsage[] Usages;
+
+ /// <summary>
+ /// The constructor of ProcessCpuUsage class.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">List of unique process ids.</param>
+ /// <privilege>http://tizen.org/privilege/systemmonitor</privilege>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is empty.</exception>
+ /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system or requesting to the resource management daemon.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when the caller does not have privilege to use this method.</exception>
+ public ProcessCpuUsage(IEnumerable<int> pid)
+ {
+ Update(pid);
+ }
+
+ /// <summary>
+ /// The number of usage entries.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public int Count { get; internal set; }
+
+ /// <summary>
+ /// Gets the amount of time this process has been scheduled in user mode.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">The process id.</param>
+ /// <returns>The amount of time <paramref name="pid"/> has been scheduled in user mode (clock ticks).</returns>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is invalid.</exception>
+ public uint GetUTime(int pid)
+ {
+ for (int i = 0; i < Count; i++)
+ if (pid == Pids[i])
+ return Usages[i].UTime;
+
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid pid");
+ RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
+ return 0;
+ }
+
+ /// <summary>
+ /// Gets the amount of time this process has been scheduled in kernel mode.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">The process id.</param>
+ /// <returns>The amount of time <paramref name="pid"/> has been scheduled in kernel mode (clock ticks).</returns>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is invalid.</exception>
+ public uint GetSTime(int pid)
+ {
+ for (int i = 0; i < Count; i++)
+ if (pid == Pids[i])
+ return Usages[i].STime;
+
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid pid");
+ RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
+ return 0;
+ }
+
+ /// <summary>
+ /// Update the process CPU usage to the latest.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">List of unique process ids.</param>
+ /// <privilege>http://tizen.org/privilege/systemmonitor</privilege>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is empty.</exception>
+ /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system or requesting to the resource management daemon.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when the caller does not have privilege to use this method.</exception>
+ public void Update(IEnumerable<int> pid)
+ {
+ int ret;
+
+ Pids = pid.ToArray<int>();
+ IntPtr ptr = new IntPtr();
+ Count = Pids.Count<int>();
+
+ ret = Interop.RuntimeInfo.GetProcessCpuUsage(Pids, Count, ref ptr);
+ if (ret != (int)RuntimeInfoError.None)
+ {
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process cpu usage");
+ RuntimeInfoErrorFactory.ThrowException(ret);
+ }
+
+ Usages = new Interop.RuntimeInfo.ProcessCpuUsage[Count];
+ for (int i = 0; i < Count; i++)
+ {
+ Usages[i] = Marshal.PtrToStructure<Interop.RuntimeInfo.ProcessCpuUsage>(ptr);
+ ptr += Marshal.SizeOf<Interop.RuntimeInfo.ProcessCpuUsage>();
+ }
+ }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.InteropServices;
+
+namespace Tizen.System
+{
+ /// <summary>
+ /// The class for memory information per process.
+ /// </summary>
+ public class ProcessMemoryUsage
+ {
+ private int[] Pids;
+ private Interop.RuntimeInfo.ProcessMemoryInfo[] Usages;
+
+ /// <summary>
+ /// The constructor of ProcessMemoryInformation class.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">List of unique process ids.</param>
+ /// <privilege>http://tizen.org/privilege/systemmonitor</privilege>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is empty.</exception>
+ /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system or requesting to the resource management daemon.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when the caller does not have privilege to use this method.</exception>
+ public ProcessMemoryUsage(IEnumerable<int> pid)
+ {
+ Update(pid);
+ }
+
+ /// <summary>
+ /// The number of usage entries.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public int Count { get; internal set; }
+
+ /// <summary>
+ /// Gets the virtual memory size of a process.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">The process id.</param>
+ /// <returns>The virtual memory size <paramref name="pid"/> is using (KiB).</returns>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is invalid.</exception>
+ public int GetVsz(int pid)
+ {
+ for (int i = 0; i < Count; i++)
+ if (pid == Pids[i])
+ return Usages[i].Vsz;
+
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid pid");
+ RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
+ return 0;
+ }
+
+ /// <summary>
+ /// Gets the resident set size of a process.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">The process id.</param>
+ /// <returns>The resident set size <paramref name="pid"/> is using (KiB).</returns>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is invalid.</exception>
+ public int GetRss(int pid)
+ {
+ for (int i = 0; i < Count; i++)
+ if (pid == Pids[i])
+ return Usages[i].Rss;
+
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid pid");
+ RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
+ return 0;
+ }
+
+ /// <summary>
+ /// Gets the proportional set size of a process.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">The process id.</param>
+ /// <returns>The proportional set size <paramref name="pid"/> is using (KiB).</returns>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is invalid.</exception>
+ public int GetPss(int pid)
+ {
+ for (int i = 0; i < Count; i++)
+ if (pid == Pids[i])
+ return Usages[i].Pss;
+
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid pid");
+ RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
+ return 0;
+ }
+
+ /// <summary>
+ /// Gets the size not modified and mapped by other processes of a process.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">The process id.</param>
+ /// <returns>The shared clean memory size <paramref name="pid"/> is using (KiB).</returns>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is invalid.</exception>
+ public int GetSharedClean(int pid)
+ {
+ for (int i = 0; i < Count; i++)
+ if (pid == Pids[i])
+ return Usages[i].SharedClean;
+
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid pid");
+ RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
+ return 0;
+ }
+
+ /// <summary>
+ /// Gets the size modified and mapped by other processes of a process.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">The process id.</param>
+ /// <returns>The shared dirty memory size <paramref name="pid"/> is using (KiB).</returns>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is invalid.</exception>
+ public int GetSharedDirty(int pid)
+ {
+ for (int i = 0; i < Count; i++)
+ if (pid == Pids[i])
+ return Usages[i].SharedDirty;
+
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid pid");
+ RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
+ return 0;
+ }
+
+ /// <summary>
+ /// Gets the size not modified and available only to that process of a process.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">The process id.</param>
+ /// <returns>The private clean memory size <paramref name="pid"/> is using (KiB).</returns>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is invalid.</exception>
+ public int GetPrivateClean(int pid)
+ {
+ for (int i = 0; i < Count; i++)
+ if (pid == Pids[i])
+ return Usages[i].PrivateClean;
+
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid pid");
+ RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
+ return 0;
+ }
+
+ /// <summary>
+ /// Gets the size modified and available only to that process of a process.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">The process id.</param>
+ /// <returns>The private dirty memory size <paramref name="pid"/> is using (KiB).</returns>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is invalid.</exception>
+ public int GetPrivateDirty(int pid)
+ {
+ for (int i = 0; i < Count; i++)
+ if (pid == Pids[i])
+ return Usages[i].PrivateDirty;
+
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid pid");
+ RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
+ return 0;
+ }
+
+ /// <summary>
+ /// Update the process memory information to the latest.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <param name="pid">List of unique process ids.</param>
+ /// <privilege>http://tizen.org/privilege/systemmonitor</privilege>
+ /// <exception cref="ArgumentException">Thrown when the <paramref name="pid"/> is empty.</exception>
+ /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system or requesting to the resource management daemon.</exception>
+ /// <exception cref="OutOfMemoryException">Thrown when the memory is not enough to allocate.</exception>
+ /// <exception cref="UnauthorizedAccessException">Thrown when the caller does not have privilege to use this method.</exception>
+ public void Update(IEnumerable<int> pid)
+ {
+ int ret;
+
+ Pids = pid.ToArray<int>();
+ IntPtr ptr = new IntPtr();
+ Count = Pids.Count<int>();
+
+ ret = Interop.RuntimeInfo.GetProcessMemoryInfo(Pids, Count, ref ptr);
+ if (ret != (int)RuntimeInfoError.None)
+ {
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Process cpu usage");
+ RuntimeInfoErrorFactory.ThrowException(ret);
+ }
+
+ Usages = new Interop.RuntimeInfo.ProcessMemoryInfo[Count];
+ for (int i = 0; i < Count; i++)
+ {
+ Usages[i] = Marshal.PtrToStructure<Interop.RuntimeInfo.ProcessMemoryInfo>(ptr);
+ ptr += Marshal.SizeOf<Interop.RuntimeInfo.ProcessCpuUsage>();
+ }
+ }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System;
+using System.IO;
+
+namespace Tizen.System
+{
+ /// <summary>
+ /// The class for system CPU usage.
+ /// </summary>
+ public class SystemCpuUsage
+ {
+ internal Interop.RuntimeInfo.CpuUsage Usage;
+ internal int[] CurrentFrequencies;
+ internal int[] MaxFrequencies;
+
+ /// <summary>
+ /// The constructor of SystemCpuUsage class.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system.</exception>
+ /// <exception cref="NotSupportedException">Thrown when this system does not store the current CPU frequency.</exception>
+ public SystemCpuUsage()
+ {
+ Update();
+ }
+
+ /// <summary>
+ /// Running time of un-niced user processes (Percent).
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public double User
+ {
+ get
+ {
+ return Usage.User;
+ }
+ }
+
+ /// <summary>
+ /// Running time of kernel processes (Percent).
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public double System
+ {
+ get
+ {
+ return Usage.System;
+ }
+ }
+
+ /// <summary>
+ /// Running time of niced user processes (Percent).
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public double Nice
+ {
+ get
+ {
+ return Usage.Nice;
+ }
+ }
+
+ /// <summary>
+ /// Time waiting for I/O completion (Percent).
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public double IoWait
+ {
+ get
+ {
+ return Usage.IoWait;
+ }
+ }
+
+ /// <summary>
+ /// The number of processors.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public int ProcessorCount { get; internal set; }
+
+ /// <summary>
+ /// Gets the current frequency of the processor.
+ /// </summary>
+ /// <since_tizen> 4 </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>
+ public int GetCurrentFrequency(int coreId)
+ {
+ if(coreId < 0 || coreId >= ProcessorCount)
+ {
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid core ID " + coreId);
+ RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
+ }
+
+ return CurrentFrequencies[coreId];
+ }
+
+ /// <summary>
+ /// Gets the max frequency of the processor.
+ /// </summary>
+ /// <since_tizen> 4 </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>
+ public int GetMaxFrequency(int coreId)
+ {
+ if (coreId < 0 || coreId >= ProcessorCount)
+ {
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Invalid core ID " + coreId);
+ RuntimeInfoErrorFactory.ThrowException((int)RuntimeInfoError.InvalidParameter);
+ }
+
+ return MaxFrequencies[coreId];
+ }
+
+ /// <summary>
+ /// Update the system CPU usage to the latest.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system.</exception>
+ /// <exception cref="NotSupportedException">Thrown when this system does not store the current CPU frequency.</exception>
+ public void Update()
+ {
+ int ret;
+ int count;
+
+ ret = Interop.RuntimeInfo.GetCpuUsage(out Usage);
+ if (ret != (int)RuntimeInfoError.None)
+ {
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get cpu usage");
+ RuntimeInfoErrorFactory.ThrowException(ret);
+ }
+
+ ret = Interop.RuntimeInfo.GetProcessorCount(out count);
+ if (ret != (int)RuntimeInfoError.None)
+ {
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get Processor count");
+ RuntimeInfoErrorFactory.ThrowException(ret);
+ return;
+ }
+
+ ProcessorCount = count;
+ CurrentFrequencies = new int[ProcessorCount];
+ MaxFrequencies = new int[ProcessorCount];
+
+ for (int coreId = 0; coreId < ProcessorCount; coreId++)
+ {
+ ret = Interop.RuntimeInfo.GetProcessorCurrentFrequency(coreId, out CurrentFrequencies[coreId]);
+ if (ret != (int)RuntimeInfoError.None)
+ {
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get the current frequency of processor " + coreId);
+ RuntimeInfoErrorFactory.ThrowException(ret);
+ }
+
+ ret = Interop.RuntimeInfo.GetProcessorMaxFrequency(coreId, out MaxFrequencies[coreId]);
+ if (ret != (int)RuntimeInfoError.None)
+ {
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get the max frequency of processor " + coreId);
+ RuntimeInfoErrorFactory.ThrowException(ret);
+ }
+ }
+ }
+ }
+}
--- /dev/null
+/*
+* Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the License);
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an AS IS BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+using System.IO;
+
+namespace Tizen.System
+{
+ /// <summary>
+ /// The class for system memory information.
+ /// </summary>
+ public class SystemMemoryUsage
+ {
+ internal Interop.RuntimeInfo.MemoryInfo Info;
+
+ /// <summary>
+ /// The constructor of MemoryInformation class.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <exception cref="IOException">Thrown when an I/O error occurs while reading from the system.</exception>
+ public SystemMemoryUsage()
+ {
+ Update();
+ }
+
+ /// <summary>
+ /// Total memory (KiB).
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public int Total
+ {
+ get
+ {
+ return Info.Total;
+ }
+ }
+
+ /// <summary>
+ /// Used memory (KiB).
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public int Used
+ {
+ get
+ {
+ return Info.Used;
+ }
+ }
+
+ /// <summary>
+ /// Free memory (KiB).
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public int Free
+ {
+ get
+ {
+ return Info.Free;
+ }
+ }
+
+ /// <summary>
+ /// Cache memory (KiB).
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public int Cache
+ {
+ get
+ {
+ return Info.Cache;
+ }
+ }
+
+ /// <summary>
+ /// Swap memory (KiB).
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ public int Swap
+ {
+ get
+ {
+ return Info.Swap;
+ }
+ }
+
+ /// <summary>
+ /// Update the system memory information to the latest.
+ /// </summary>
+ /// <since_tizen> 4 </since_tizen>
+ /// <exception cref="IOException">Thrown when I/O error occurs while reading from the system.</exception>
+ public void Update()
+ {
+ int ret = Interop.RuntimeInfo.GetSystemMemoryInfo(out Info);
+ if (ret != (int)RuntimeInfoError.None)
+ {
+ Log.Error(RuntimeInfoErrorFactory.LogTag, "Interop failed to get System memory information");
+ RuntimeInfoErrorFactory.ThrowException(ret);
+ }
+ }
+ }
+}