ohmu
·
2026-10-15
1#include "top.h"
2
3#include <OS.h>
4#include <string.h>
5
6const char* ffTopGetProcessSnapshot(FFlist* snapshots, FFTopTypes showTypes) {
7 int32 cookie = 0;
8 team_info team;
9 while (get_next_team_info(&cookie, &team) == B_OK) {
10 if (team.team == B_SYSTEM_TEAM) {
11 continue; // The kernel team
12 }
13
14 FFTopProcessSnapshot* item = FF_LIST_ADD(FFTopProcessSnapshot, *snapshots);
15
16 ffStrbufInitS(&item->name, team.name);
17
18 item->pid = (uint32_t) team.team;
19
20 // User and kernel time of all threads of the team combined in microseconds.
21 item->cpuTime = 0;
22 team_usage_info usage;
23 if (get_team_usage_info(team.team, B_TEAM_USAGE_SELF, &usage) == B_OK) {
24 item->cpuTime = ((uint64_t) usage.user_time + (uint64_t) usage.kernel_time) / 1000;
25 }
26
27 // Sum up the physically resident memory of all areas of the team;
28 // ram_size is the amount of physical pages committed to an area,
29 // whereas size is just its virtual reservation.
30 uint64_t memBytes = 0;
31 ssize_t areaCookie = 0;
32 area_info area;
33 while (get_next_area_info(team.team, &areaCookie, &area) == B_OK) {
34 memBytes += area.ram_size;
35 }
36 item->memBytes = memBytes;
37
38 // start_time is microseconds since boot.
39 item->startTime = (uint64_t) team.start_time;
40
41 // Storage io counters are not exposed by Haiku; leave them zeroed.
42 item->bytesRead = 0;
43 item->bytesWritten = 0;
44 item->threads = (uint32_t) team.thread_count;
45 }
46
47 return nullptr;
48}