Skip to content

Commit b57f020

Browse files
committed
Add RFC: Resource Usage APIs
1 parent 832622d commit b57f020

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

text/0058-resource-usage-apis.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Summary
2+
3+
This RFC proposes the addition of libobs and various object (sources, encoders, etc.) APIs that allow querying system resource usage.
4+
5+
# Motivation
6+
7+
When using larger scene collections with many sources it can be difficult to identify which elements use system resources.
8+
9+
For example:
10+
- RAM and CPU usage of browser sources
11+
- VRAM usage of image sources or delay filters
12+
- CPU usage of x264 and other CPU encoders
13+
- Network usage of a media source streaming in data
14+
15+
# Proposed implementation approaches
16+
17+
## 0. General additions
18+
19+
The platform utilities shall be extended with APIs to query CPU/RAM/etc. usage of individual threads or processes that are not OBS itself (e.g. browser subprocess, encoder thread), as well as other information that may be necessary to implement reporting in plugins.
20+
21+
## 1. Resource-specific APIs
22+
23+
### libobs APIs
24+
25+
Additional APIs for querying specific resource usage would be added to all applicable source types, for example:
26+
27+
- `int64_t obs_encoder_get_cpu_usage(obs_encoder_t *source)`
28+
- `int64_t obs_source_get_system_memory(obs_source_t *source)`
29+
30+
Non-support would be indicated by a predefined invalid return value (e.g. `-1`).
31+
32+
### Source/Encoder/etc. APIs
33+
34+
The "info" struct (e.g. `obs_source_info`) of a given object would be extended by APIs for querying usage of a specific resource, e.g.
35+
36+
- `info.cpu_usage()`
37+
- `info.system_memory()`
38+
39+
The capabilitiy of a source would be determined by the absence or presence of it in the info object registered with OBS.
40+
41+
## 2. Capability flags and structs
42+
43+
In this case rather than adding specific APIs for resources sources would be queried to fill in a struct containing fields for all the values supported by libobs, and indicate via flags which are supported and shall be read by the consumer.
44+
45+
*Possible alteration: Flags could be part of the returned struct itself rather than be queried separately.*
46+
47+
### libobs APIs
48+
49+
A new struct would be introduced, e.g. `obs_resources_t` with a structure similar to this:
50+
51+
```c
52+
struct obs_resources {
53+
float cpu,
54+
float ram,
55+
float vram,
56+
...
57+
}
58+
```
59+
60+
Additionally, new flags would be added to allow objects to indicate which values can be queried, e.g.
61+
```c
62+
enum supported_queries {
63+
OBS_RESOURCE_RAM = 1 << 0,
64+
OBS_RESOURCE_CPU = 1 << 1,
65+
...
66+
}
67+
```
68+
69+
An API user would then query the information from an object via its specific resource query API, as well as the supported flags to determine its supported values. All other data shall be discarded.
70+
71+
For example:
72+
- `uint32_t obs_get_source_resources_flags(const char *id)`
73+
- `uint32_t obs_source_get_resources_flags(obs_source_t *source)`
74+
- `obs_resources_t *obs_source_query_resources(obs_source_t *source)`
75+
76+
### Source/Encoder/etc. APIs
77+
78+
The info object would be extended to add additional flags and one method to query resource usage:
79+
80+
```c
81+
struct obs_source_info my_source = {
82+
...
83+
.resource_query_flags = OBS_RESOURCE_RAM | OBS_RESOURCE_CPU,
84+
.resource_query = my_source_resource_usage,
85+
...
86+
```
87+
88+
The resource query function could have a signature like `void resource_query(void *data, obs_resources_t *resources)`.
89+
90+
# Drawbacks
91+
92+
In order for resource usage to be shown this must be implemented by sources and other eligible objects. This may not be trivial especially for GPU/VRAM usage.
93+
94+
Additionally there may be a performance hit from data collection, as such it should only be enabled when a user is actively monitoring usage (e.g. has an OBS internal "task manager" open).
95+
96+
# Additional Information
97+
98+
- Chrome developer API with similar goals: https://developer.chrome.com/docs/extensions/reference/processes

0 commit comments

Comments
 (0)