1 | /** @file
|
---|
2 | * IPRT - System.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | *
|
---|
25 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
27 | * additional information or have any questions.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef ___iprt_system_h
|
---|
31 | #define ___iprt_system_h
|
---|
32 |
|
---|
33 | #include <iprt/cdefs.h>
|
---|
34 | #include <iprt/types.h>
|
---|
35 |
|
---|
36 | #define IPRT_USAGE_MULTIPLIER UINT64_C(1000000000)
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * This structure holds both computed and raw values of overall CPU load counters.
|
---|
40 | *
|
---|
41 | * @todo r=bird: What does these values mean?
|
---|
42 | *
|
---|
43 | * Also, I no longer use 'u32', 'u16', 'u8', 'u64', etc unless this information
|
---|
44 | * is really important for the user. So, unless there is a better prefix just
|
---|
45 | * stick to 'u' here.
|
---|
46 | *
|
---|
47 | * The name of the struct should include the prefix or a shortened
|
---|
48 | * version of it: RTSYSCPUUSAGESTATS
|
---|
49 | *
|
---|
50 | * Also, I'd sugest calling it RTSYSCPULOADSTATS, replacing 'usage' with 'load',
|
---|
51 | * no particular reason, other than that it is easier to read in the (silly)
|
---|
52 | * condensed form we use for typedefs here.
|
---|
53 | *
|
---|
54 | * Finally, I'm wondering how portable this is. I'd like to see what APIs are
|
---|
55 | * available on the important systems (Windows, Solaris, Linux) and compare
|
---|
56 | * the kind of info they return. This should be done in the defect *before*
|
---|
57 | * any of the above, please.
|
---|
58 | */
|
---|
59 | typedef struct RTSYSCPUUSAGESTATS
|
---|
60 | {
|
---|
61 | uint32_t u32User;
|
---|
62 | uint32_t u32System;
|
---|
63 | uint32_t u32Idle;
|
---|
64 | /* Internal raw counter values. */
|
---|
65 | uint32_t u32RawUser;
|
---|
66 | uint32_t u32RawNice;
|
---|
67 | uint32_t u32RawSystem;
|
---|
68 | uint32_t u32RawIdle;
|
---|
69 | } RTCPUUSAGESTATS;
|
---|
70 | typedef RTCPUUSAGESTATS *PRTCPUUSAGESTATS;
|
---|
71 |
|
---|
72 | /* This structure holds both computed and raw values of per-VM CPU load counters. */
|
---|
73 | typedef struct
|
---|
74 | {
|
---|
75 | uint32_t u32User;
|
---|
76 | uint32_t u32System;
|
---|
77 | /* Internal raw counter values. */
|
---|
78 | uint64_t u64RawTotal;
|
---|
79 | uint32_t u32RawProcUser;
|
---|
80 | uint32_t u32RawProcSystem;
|
---|
81 | } RTPROCCPUUSAGESTATS;
|
---|
82 | typedef RTPROCCPUUSAGESTATS *PRTPROCCPUUSAGESTATS;
|
---|
83 |
|
---|
84 |
|
---|
85 | __BEGIN_DECLS
|
---|
86 |
|
---|
87 | /** @defgroup grp_rt_system RTSystem - System Information
|
---|
88 | * @ingroup grp_rt
|
---|
89 | * @{
|
---|
90 | */
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Gets the number of logical (not physical) processors in the system.
|
---|
94 | *
|
---|
95 | * @returns Number of logical processors in the system.
|
---|
96 | *
|
---|
97 | * @todo Replaced by RTMpGetOnlineCount / RTMpGetCount, retire this guy.
|
---|
98 | */
|
---|
99 | RTDECL(unsigned) RTSystemProcessorGetCount(void);
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Gets the active logical processor mask.
|
---|
103 | *
|
---|
104 | * @returns Active logical processor mask. (bit 0 == logical cpu 0)
|
---|
105 | *
|
---|
106 | * @todo Replaced by RTMpGetOnlineSet, retire this guy.
|
---|
107 | */
|
---|
108 | RTDECL(uint64_t) RTSystemProcessorGetActiveMask(void);
|
---|
109 |
|
---|
110 | /**
|
---|
111 | * Gets the current figures of overall system processor usage.
|
---|
112 | *
|
---|
113 | * @remarks To get meaningful stats this function has to be
|
---|
114 | * called twice with a bit of delay between calls. This
|
---|
115 | * is due to the fact that at least two samples of
|
---|
116 | * system usage stats are needed to calculate the load.
|
---|
117 | *
|
---|
118 | * @returns IPRT status code.
|
---|
119 | * @param pStats Pointer to the structure that contains the
|
---|
120 | * results. Note that this structure is
|
---|
121 | * modified with each call to this function and
|
---|
122 | * is used to provide both in and out values.
|
---|
123 | * @todo r=bird: Change to RTSystemGetCpuLoadStats.
|
---|
124 | */
|
---|
125 | RTDECL(int) RTSystemProcessorGetUsageStats(PRTCPUUSAGESTATS pStats);
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Gets the current processor usage for a partucilar process.
|
---|
129 | *
|
---|
130 | * @remarks To get meaningful stats this function has to be
|
---|
131 | * called twice with a bit of delay between calls. This
|
---|
132 | * is due to the fact that at least two samples of
|
---|
133 | * system usage stats are needed to calculate the load.
|
---|
134 | *
|
---|
135 | * @returns IPRT status code.
|
---|
136 | * @param pid VM process id.
|
---|
137 | * @param pStats Pointer to the structure that contains the
|
---|
138 | * results. Note that this structure is
|
---|
139 | * modified with each call to this function and
|
---|
140 | * is used to provide both in and out values.
|
---|
141 | *
|
---|
142 | * @todo Perharps this function should be moved somewhere
|
---|
143 | * else.
|
---|
144 | * @todo r=bird: Yes is should, iprt/proc.h. RTProcGetCpuLoadStats.
|
---|
145 | */
|
---|
146 | RTDECL(int) RTProcessGetProcessorUsageStats(RTPROCESS pid, PRTPROCCPUUSAGESTATS pStats);
|
---|
147 |
|
---|
148 | /** @} */
|
---|
149 |
|
---|
150 | __END_DECLS
|
---|
151 |
|
---|
152 | #endif
|
---|
153 |
|
---|