Beispiel #1
0
        private int[] GetProcessMemoryValueInt(Interop.RuntimeInfo.ProcessMemoryInfoKey key, IEnumerable <int> pids)
        {
            var ret = Interop.RuntimeInfo.GetProcessMemoryValueInt(pids.ToArray <int>(), pids.ToArray <int>().Length, key, out IntPtr ptr);

            if (ret != InformationError.None)
            {
                Log.Error(InformationErrorFactory.LogTag, "Interop failed to get process memory info: " + key.ToString());
                if (ret == InformationError.NoData)
                {
                    return(null);
                }
                InformationErrorFactory.ThrowException(ret);
            }

            try
            {
                var array = new int[Count];
                unsafe
                {
                    for (int i = 0; i < Count; i++)
                    {
                        array[i] = *((int *)ptr.ToPointer() + (i * sizeof(int)));
                    }
                }
                return(array);
            }
            finally
            {
                Interop.Libc.Free(ptr);
            }
        }
Beispiel #2
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)
        {
            InformationError ret;

            Pids = pid.ToArray <int>();
            IntPtr ptr = new IntPtr();

            ret = Interop.RuntimeInfo.GetProcessMemoryInfo(Pids, Count, ref ptr);
            if (ret != InformationError.None)
            {
                Log.Error(InformationErrorFactory.LogTag, "Interop failed to get Process cpu usage.");
                InformationErrorFactory.ThrowException(ret);
            }
            try
            {
                var data = ptr;
                Usages = new Interop.RuntimeInfo.ProcessMemoryInfo[Count];
                for (int i = 0; i < Count; i++)
                {
                    Usages[i] = Marshal.PtrToStructure <Interop.RuntimeInfo.ProcessMemoryInfo>(data);
                    data     += Marshal.SizeOf <Interop.RuntimeInfo.ProcessCpuUsage>();
                }
            }
            finally
            {
                Interop.Libc.Free(ptr);
            }

            Gpus  = GetProcessMemoryValueInt(Interop.RuntimeInfo.ProcessMemoryInfoKey.Gpu, pid);
            Gems  = GetProcessMemoryValueInt(Interop.RuntimeInfo.ProcessMemoryInfoKey.GemRss, pid);
            Swaps = GetProcessMemoryValueInt(Interop.RuntimeInfo.ProcessMemoryInfoKey.Swap, pid);
        }
Beispiel #3
0
        /// This function is for a TV product. It will be removed.
        internal static RuntimeInfoKey ConvertKeyIfTvProduct(RuntimeInfoKey key)
        {
            bool   is_key_existed = false;
            string profile;
            int    key_TV = -1;

            if (is_TV_product == -1)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                is_key_existed = SystemInfo.TryGetValue <string>("http://com.samsung/build_config/product_type", out profile);
#pragma warning restore CS0618 // Type or member is obsolete
                if (is_key_existed && String.Compare(profile, "TV") == 0)
                {
                    is_TV_product = 1;
                }
                else
                {
                    is_TV_product = 0;
                }
            }

            if (is_TV_product == 0)
            {
                return(key);
            }
            else
            {
                if (!s_keyTVkeyMapping.TryGetValue(key, out key_TV))
                {
                    InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
                }
                return((RuntimeInfoKey)key_TV);
            }
        }
Beispiel #4
0
        /// <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(InformationErrorFactory.LogTag, "Invalid core ID " + coreId);
                InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
            }

            return(MaxFrequencies[coreId]);
        }
Beispiel #5
0
        /// <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()
        {
            InformationError ret = Interop.RuntimeInfo.GetSystemMemoryInfo(out Info);

            if (ret != InformationError.None)
            {
                Log.Error(InformationErrorFactory.LogTag, "Interop failed to get System memory information");
                InformationErrorFactory.ThrowException(ret);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Unregisters a change event callback for given runtime feature key.
        /// </summary>
        /// <remarks>
        /// This function is only for runtime feature.
        /// </remarks>
        /// <since_tizen> 4 </since_tizen>
        /// <param name="key">The name of runtime feature which wants to unregister callback.</param>
        /// <param name="callback">The callback function to unsubscribe.</param>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
        /// <exception cref="NotSupportedException">Thrown when the feature related <paramref name="key"/> is not supported.</exception>
        public static void UnsetCallback(string key, EventHandler <RuntimeFeatureStatusChangedEventArgs> callback)
        {
            RuntimeInfoKey runtimeFeature;

            if (!ConvertStringToRuntimeInfoKey(key, out runtimeFeature))
            {
                Log.Error(InformationErrorFactory.LogTag, "Invalid key");
                InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
            }

            RuntimeInfo.UnsetCallback(runtimeFeature, callback);
        }
Beispiel #7
0
        /// <summary>
        /// Unregisters a change event callback for given key.
        /// </summary>
        /// <param name="key">The runtime information key which wants to unregister callback.</param>
        /// <param name="callback">The callback function to unsubscribe.</param>
        /// <exception cref="ArgumentException">Thrown when the <paramref name="key"/> is invalid.</exception>
        internal static void UnsetCallback(RuntimeInfoKey key, EventHandler <RuntimeFeatureStatusChangedEventArgs> callback)
        {
            RuntimeInfoEventHandler handler = null;

            FindEventHandler(key, ref handler);
            if (handler == null)
            {
                Log.Error(InformationErrorFactory.LogTag, "Invalid key");
                InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
            }

            handler.EventHandler -= callback;
        }
Beispiel #8
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(InformationErrorFactory.LogTag, "Invalid pid");
            InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
            return(0);
        }
Beispiel #9
0
        public int GetSwap(int pid)
        {
            if (Swaps == null)
            {
                Log.Error(InformationErrorFactory.LogTag, "No data");
                InformationErrorFactory.ThrowException(InformationError.NoData);
            }

            for (int i = 0; i < Count; i++)
            {
                if (pid == Pids[i])
                {
                    return(Swaps[i]);
                }
            }

            Log.Error(InformationErrorFactory.LogTag, "Invalid pid");
            InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
            return(0);
        }
Beispiel #10
0
        internal static RuntimeInfoKey ConvertKeyIfTvProduct(RuntimeInfoKey key)
        {
            if (is_TV_product == -1)
            {
                CheckTvProduct();
            }

            if (is_TV_product == 1)
            {
                if (!s_keyTVkeyMapping.TryGetValue(key, out int key_TV))
                {
                    InformationErrorFactory.ThrowException(InformationError.InvalidParameter);
                }
                return((RuntimeInfoKey)key_TV);
            }
            else
            {
                return(key);
            }
        }
Beispiel #11
0
        /// <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()
        {
            InformationError ret;
            int count;

            ret = Interop.RuntimeInfo.GetCpuUsage(out Usage);
            if (ret != InformationError.None)
            {
                Log.Error(InformationErrorFactory.LogTag, "Interop failed to get cpu usage");
                InformationErrorFactory.ThrowException(ret);
            }

            ret = Interop.RuntimeInfo.GetProcessorCount(out count);
            if (ret != InformationError.None)
            {
                Log.Error(InformationErrorFactory.LogTag, "Interop failed to get Processor count");
                InformationErrorFactory.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 != InformationError.None)
                {
                    Log.Error(InformationErrorFactory.LogTag, "Interop failed to get the current frequency of processor " + coreId);
                    InformationErrorFactory.ThrowException(ret);
                }

                ret = Interop.RuntimeInfo.GetProcessorMaxFrequency(coreId, out MaxFrequencies[coreId]);
                if (ret != InformationError.None)
                {
                    Log.Error(InformationErrorFactory.LogTag, "Interop failed to get the max frequency of processor " + coreId);
                    InformationErrorFactory.ThrowException(ret);
                }
            }
        }
Beispiel #12
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)
        {
            InformationError ret;

            Pids = pid.ToArray <int>();
            IntPtr ptr = new IntPtr();

            Count = Pids.Count <int>();

            ret = Interop.RuntimeInfo.GetProcessMemoryInfo(Pids, Count, ref ptr);
            if (ret != InformationError.None)
            {
                Log.Error(InformationErrorFactory.LogTag, "Interop failed to get Process cpu usage");
                InformationErrorFactory.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>();
            }
        }