1 /* 2 * Copyright (c) 2001-2005, Haiku. 3 * 4 * This software is part of the Haiku distribution and is covered 5 * by the MIT license. 6 * 7 * Author: Daniel Reinhold (danielre@users.sf.net) 8 */ 9 10 /** Lists area info for all currently running teams */ 11 12 13 #include <OS.h> 14 15 #include <stdio.h> 16 #include <stdlib.h> 17 #include <string.h> 18 19 20 static void list_areas_for_id(team_id team); 21 static void list_areas_for_name(const char *teamName); 22 static void show_memory_totals(void); 23 24 25 static void 26 show_memory_totals(void) 27 { 28 int32 max = 0, used = 0; 29 30 system_info info; 31 if (get_system_info(&info) == B_OK) { 32 // pages are 4KB 33 max = info.max_pages * 4; 34 used = info.used_pages * 4; 35 } 36 37 printf("memory: total: %4" B_PRId32 "KB, used: %4" B_PRId32 "KB, left: %4" 38 B_PRId32 "KB\n", max, used, max - used); 39 } 40 41 42 static void 43 list_areas_for_id(team_id id) 44 { 45 ssize_t cookie = 0; 46 team_info teamInfo; 47 area_info areaInfo; 48 49 if (id != 1 && get_team_info(id, &teamInfo) == B_BAD_TEAM_ID) { 50 printf("\nteam %" B_PRId32 " unknown\n", id); 51 return; 52 } else if (id == 1) 53 strcpy(teamInfo.args, "KERNEL SPACE"); 54 55 printf("\n%s (team %" B_PRId32 ")\n", teamInfo.args, id); 56 printf(" ID name address size alloc." 57 " #-cow #-in #-out\n"); 58 printf("------------------------------------------------------------------" 59 "------------------\n"); 60 61 while (get_next_area_info(id, &cookie, &areaInfo) == B_OK) { 62 printf("%5" B_PRId32 " %32s %p %8" B_PRIxSIZE " %8" B_PRIx32 " %5" 63 B_PRId32 " %5" B_PRId32 " %5" B_PRId32 "\n", 64 areaInfo.area, 65 areaInfo.name, 66 areaInfo.address, 67 areaInfo.size, 68 areaInfo.ram_size, 69 areaInfo.copy_count, 70 areaInfo.in_count, 71 areaInfo.out_count); 72 } 73 } 74 75 76 static void 77 list_areas_for_name(const char *name) 78 { 79 int32 cookie = 0; 80 team_info info; 81 while (get_next_team_info(&cookie, &info) >= B_OK) { 82 if (strstr(info.args, name) != NULL) 83 list_areas_for_id(info.team); 84 } 85 } 86 87 88 int 89 main(int argc, char **argv) 90 { 91 show_memory_totals(); 92 93 if (argc == 1) { 94 // list areas of all teams 95 int32 cookie = 0; 96 team_info info; 97 98 while (get_next_team_info(&cookie, &info) >= B_OK) 99 list_areas_for_id(info.team); 100 } else { 101 // list areas for each team ID/name on the command line 102 while (--argc) { 103 const char *arg = *++argv; 104 team_id team = atoi(arg); 105 106 // if atoi returns >0 it's likely it's a number, else take it as string 107 if (team > 0) 108 list_areas_for_id(team); 109 else 110 list_areas_for_name(arg); 111 } 112 } 113 114 return 0; 115 } 116 117