Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef spacetrace_h__ |
michael@0 | 8 | #define spacetrace_h__ |
michael@0 | 9 | |
michael@0 | 10 | /* |
michael@0 | 11 | ** spacetrace.h |
michael@0 | 12 | ** |
michael@0 | 13 | ** SpaceTrace is meant to take the output of trace-malloc and present |
michael@0 | 14 | ** a picture of allocations over the run of the application. |
michael@0 | 15 | */ |
michael@0 | 16 | |
michael@0 | 17 | /* |
michael@0 | 18 | ** Required includes. |
michael@0 | 19 | */ |
michael@0 | 20 | #include <stdint.h> |
michael@0 | 21 | #include "nspr.h" |
michael@0 | 22 | #include "prlock.h" |
michael@0 | 23 | #include "prrwlock.h" |
michael@0 | 24 | #include "nsTraceMalloc.h" |
michael@0 | 25 | #include "tmreader.h" |
michael@0 | 26 | #include "formdata.h" |
michael@0 | 27 | |
michael@0 | 28 | /* |
michael@0 | 29 | ** Turn on to attempt adding support for graphs on your platform. |
michael@0 | 30 | */ |
michael@0 | 31 | #if defined(HAVE_BOUTELL_GD) |
michael@0 | 32 | #define ST_WANT_GRAPHS 1 |
michael@0 | 33 | #endif /* HAVE_BOUTELL_GD */ |
michael@0 | 34 | #if !defined(ST_WANT_GRAPHS) |
michael@0 | 35 | #define ST_WANT_GRAPHS 0 |
michael@0 | 36 | #endif |
michael@0 | 37 | |
michael@0 | 38 | /* |
michael@0 | 39 | ** REPORT_ERROR |
michael@0 | 40 | ** REPORT_INFO |
michael@0 | 41 | ** |
michael@0 | 42 | ** Just report errors and stuff in a consistent manner. |
michael@0 | 43 | */ |
michael@0 | 44 | #define REPORT_ERROR(code, function) \ |
michael@0 | 45 | PR_fprintf(PR_STDERR, "error(%d):\t%s\n", code, #function) |
michael@0 | 46 | #define REPORT_ERROR_MSG(code, msg) \ |
michael@0 | 47 | PR_fprintf(PR_STDERR, "error(%d):\t%s\n", code, msg) |
michael@0 | 48 | #define REPORT_INFO(msg) \ |
michael@0 | 49 | PR_fprintf(PR_STDOUT, "%s: %s\n", globals.mProgramName, (msg)) |
michael@0 | 50 | |
michael@0 | 51 | #if defined(DEBUG_blythe) && 1 |
michael@0 | 52 | #define REPORT_blythe(code, msg) \ |
michael@0 | 53 | PR_fprintf(PR_STDOUT, "gab(%d):\t%s\n", code, msg) |
michael@0 | 54 | #else |
michael@0 | 55 | #define REPORT_blythe(code, msg) |
michael@0 | 56 | #endif /* DEBUG_blythe */ |
michael@0 | 57 | |
michael@0 | 58 | /* |
michael@0 | 59 | ** CALLSITE_RUN |
michael@0 | 60 | ** |
michael@0 | 61 | ** How to get a callsite run. |
michael@0 | 62 | ** Allows for further indirection if needed later. |
michael@0 | 63 | */ |
michael@0 | 64 | #define CALLSITE_RUN(callsite) \ |
michael@0 | 65 | ((STRun*)((callsite)->data)) |
michael@0 | 66 | |
michael@0 | 67 | /* |
michael@0 | 68 | ** ST_PERMS |
michael@0 | 69 | ** ST_FLAGS |
michael@0 | 70 | ** |
michael@0 | 71 | ** File permissions we desire. |
michael@0 | 72 | ** 0644 |
michael@0 | 73 | */ |
michael@0 | 74 | #define ST_PERMS (PR_IRUSR | PR_IWUSR | PR_IRGRP | PR_IROTH) |
michael@0 | 75 | #define ST_FLAGS (PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE) |
michael@0 | 76 | |
michael@0 | 77 | /* |
michael@0 | 78 | ** Sorting order |
michael@0 | 79 | */ |
michael@0 | 80 | #define ST_WEIGHT 0 /* size * timeval */ |
michael@0 | 81 | #define ST_SIZE 1 |
michael@0 | 82 | #define ST_TIMEVAL 2 |
michael@0 | 83 | #define ST_COUNT 3 |
michael@0 | 84 | #define ST_HEAPCOST 4 |
michael@0 | 85 | |
michael@0 | 86 | /* |
michael@0 | 87 | ** Callsite loop direction flags. |
michael@0 | 88 | */ |
michael@0 | 89 | #define ST_FOLLOW_SIBLINGS 0 |
michael@0 | 90 | #define ST_FOLLOW_PARENTS 1 |
michael@0 | 91 | |
michael@0 | 92 | /* |
michael@0 | 93 | ** Graph data. |
michael@0 | 94 | */ |
michael@0 | 95 | #define STGD_WIDTH 640 |
michael@0 | 96 | #define STGD_HEIGHT 480 |
michael@0 | 97 | #define STGD_MARGIN 75 |
michael@0 | 98 | #define STGD_SPACE_X (STGD_WIDTH - (2 * STGD_MARGIN)) |
michael@0 | 99 | #define STGD_SPACE_Y (STGD_HEIGHT - (2 * STGD_MARGIN)) |
michael@0 | 100 | |
michael@0 | 101 | /* |
michael@0 | 102 | ** Minimum lifetime default, in seconds. |
michael@0 | 103 | */ |
michael@0 | 104 | #define ST_DEFAULT_LIFETIME_MIN 10 |
michael@0 | 105 | |
michael@0 | 106 | /* |
michael@0 | 107 | ** Allocations fall to this boundry size by default. |
michael@0 | 108 | ** Overhead is taken after alignment. |
michael@0 | 109 | ** |
michael@0 | 110 | ** The msvcrt malloc has an alignment of 16 with an overhead of 8. |
michael@0 | 111 | ** The win32 HeapAlloc has an alignment of 8 with an overhead of 8. |
michael@0 | 112 | */ |
michael@0 | 113 | #define ST_DEFAULT_ALIGNMENT_SIZE 16 |
michael@0 | 114 | #define ST_DEFAULT_OVERHEAD_SIZE 8 |
michael@0 | 115 | |
michael@0 | 116 | /* |
michael@0 | 117 | ** Numer of substring match specifications to allow. |
michael@0 | 118 | */ |
michael@0 | 119 | #define ST_SUBSTRING_MATCH_MAX 5 |
michael@0 | 120 | |
michael@0 | 121 | /* |
michael@0 | 122 | ** Max Number of patterns per rule |
michael@0 | 123 | */ |
michael@0 | 124 | #define ST_MAX_PATTERNS_PER_RULE 16 |
michael@0 | 125 | |
michael@0 | 126 | /* |
michael@0 | 127 | ** Rule pointers and child pointers are allocated in steps of ST_ALLOC_STEP |
michael@0 | 128 | */ |
michael@0 | 129 | #define ST_ALLOC_STEP 16 |
michael@0 | 130 | |
michael@0 | 131 | /* |
michael@0 | 132 | ** Name of the root category. Appears in UI. |
michael@0 | 133 | */ |
michael@0 | 134 | #define ST_ROOT_CATEGORY_NAME "All" |
michael@0 | 135 | |
michael@0 | 136 | /* |
michael@0 | 137 | ** Size of our option string buffers. |
michael@0 | 138 | */ |
michael@0 | 139 | #define ST_OPTION_STRING_MAX 256 |
michael@0 | 140 | |
michael@0 | 141 | /* |
michael@0 | 142 | ** Set the desired resolution of the timevals. |
michael@0 | 143 | ** The resolution is just mimicking what is recorded in the trace-malloc |
michael@0 | 144 | ** output, and that is currently milliseconds. |
michael@0 | 145 | */ |
michael@0 | 146 | #define ST_TIMEVAL_RESOLUTION 1000 |
michael@0 | 147 | #define ST_TIMEVAL_FORMAT "%.3f" |
michael@0 | 148 | #define ST_TIMEVAL_PRINTABLE(timeval) ((double)(timeval) / (double)ST_TIMEVAL_RESOLUTION) |
michael@0 | 149 | #define ST_TIMEVAL_PRINTABLE64(timeval) ((double)((int64_t)(timeval)) / (double)ST_TIMEVAL_RESOLUTION) |
michael@0 | 150 | #define ST_TIMEVAL_MAX ((uint32_t)-1 - ((uint32_t)-1 % ST_TIMEVAL_RESOLUTION)) |
michael@0 | 151 | |
michael@0 | 152 | #define ST_MICROVAL_RESOLUTION 1000000 |
michael@0 | 153 | #define ST_MICROVAL_FORMAT "%.6f" |
michael@0 | 154 | #define ST_MICROVAL_PRINTABLE(timeval) ((double)(timeval) / (double)ST_MICROVAL_RESOLUTION) |
michael@0 | 155 | #define ST_MICROVAL_PRINTABLE64(timeval) ((double)((int64_t)(timeval)) / (double)ST_MICROVAL_RESOLUTION) |
michael@0 | 156 | #define ST_MICROVAL_MAX ((uint32_t)-1 - ((uint32_t)-1 % ST_MICROVAL_RESOLUTION)) |
michael@0 | 157 | |
michael@0 | 158 | /* |
michael@0 | 159 | ** Forward Declaration |
michael@0 | 160 | */ |
michael@0 | 161 | typedef struct __struct_STCategoryNode STCategoryNode; |
michael@0 | 162 | typedef struct __struct_STCategoryRule STCategoryRule; |
michael@0 | 163 | |
michael@0 | 164 | |
michael@0 | 165 | /* |
michael@0 | 166 | ** STAllocEvent |
michael@0 | 167 | ** |
michael@0 | 168 | ** An event that happens to an allocation (malloc, free, et. al.) |
michael@0 | 169 | */ |
michael@0 | 170 | typedef struct __struct_STAllocEvent |
michael@0 | 171 | { |
michael@0 | 172 | /* |
michael@0 | 173 | ** The type of allocation event. |
michael@0 | 174 | ** This maps directly to the trace malloc events (i.e. TM_EVENT_MALLOC) |
michael@0 | 175 | */ |
michael@0 | 176 | char mEventType; |
michael@0 | 177 | |
michael@0 | 178 | /* |
michael@0 | 179 | ** Each event, foremost, has a chronologically increasing ID in |
michael@0 | 180 | ** relation to other allocation events. This is a time stamp |
michael@0 | 181 | ** of sorts. |
michael@0 | 182 | */ |
michael@0 | 183 | uint32_t mTimeval; |
michael@0 | 184 | |
michael@0 | 185 | /* |
michael@0 | 186 | ** Every event has a heap ID (pointer). |
michael@0 | 187 | ** In the event of a realloc, this is the new heap ID. |
michael@0 | 188 | ** In the event of a free, this is the previous heap ID value. |
michael@0 | 189 | */ |
michael@0 | 190 | uint32_t mHeapID; |
michael@0 | 191 | |
michael@0 | 192 | /* |
michael@0 | 193 | ** Every event, along with the heap ID, tells of the size. |
michael@0 | 194 | ** In the event of a realloc, this is the new size. |
michael@0 | 195 | ** In th event of a free, this is the previous size. |
michael@0 | 196 | */ |
michael@0 | 197 | uint32_t mHeapSize; |
michael@0 | 198 | |
michael@0 | 199 | /* |
michael@0 | 200 | ** Every event has a callsite/stack backtrace. |
michael@0 | 201 | ** In the event of a realloc, this is the new callsite. |
michael@0 | 202 | ** In the event of a free, this is the previous call site. |
michael@0 | 203 | */ |
michael@0 | 204 | tmcallsite* mCallsite; |
michael@0 | 205 | } STAllocEvent; |
michael@0 | 206 | |
michael@0 | 207 | /* |
michael@0 | 208 | ** STAllocation |
michael@0 | 209 | ** |
michael@0 | 210 | ** An allocation is a temporal entity in the heap. |
michael@0 | 211 | ** It possibly lives under different heap IDs (pointers) and different |
michael@0 | 212 | ** sizes during its given time. |
michael@0 | 213 | ** An allocation is defined by the events during its lifetime. |
michael@0 | 214 | ** An allocation's lifetime is defined by the range of event IDs it holds. |
michael@0 | 215 | */ |
michael@0 | 216 | typedef struct __struct_STAllocation |
michael@0 | 217 | { |
michael@0 | 218 | /* |
michael@0 | 219 | ** The array of events. |
michael@0 | 220 | */ |
michael@0 | 221 | uint32_t mEventCount; |
michael@0 | 222 | STAllocEvent* mEvents; |
michael@0 | 223 | |
michael@0 | 224 | /* |
michael@0 | 225 | ** The lifetime/lifespan of the allocation. |
michael@0 | 226 | */ |
michael@0 | 227 | uint32_t mMinTimeval; |
michael@0 | 228 | uint32_t mMaxTimeval; |
michael@0 | 229 | |
michael@0 | 230 | /* |
michael@0 | 231 | ** Index of this allocation in the global run. |
michael@0 | 232 | */ |
michael@0 | 233 | uint32_t mRunIndex; |
michael@0 | 234 | |
michael@0 | 235 | /* |
michael@0 | 236 | ** The runtime cost of heap events in this allocation. |
michael@0 | 237 | ** The cost is defined as the number of time units recorded as being |
michael@0 | 238 | ** spent in heap code (time of malloc, free, et al.). |
michael@0 | 239 | ** We do not track individual event cost in order to save space. |
michael@0 | 240 | */ |
michael@0 | 241 | uint32_t mHeapRuntimeCost; |
michael@0 | 242 | } STAllocation; |
michael@0 | 243 | |
michael@0 | 244 | /* |
michael@0 | 245 | ** STCallsiteStats |
michael@0 | 246 | ** |
michael@0 | 247 | ** Stats regarding a run, kept mainly for callsite runs. |
michael@0 | 248 | */ |
michael@0 | 249 | typedef struct __struct_STCallsiteStats |
michael@0 | 250 | { |
michael@0 | 251 | /* |
michael@0 | 252 | ** Sum timeval of the allocations. |
michael@0 | 253 | ** Callsite runs total all allocations below the callsite. |
michael@0 | 254 | */ |
michael@0 | 255 | uint64_t mTimeval64; |
michael@0 | 256 | |
michael@0 | 257 | /* |
michael@0 | 258 | ** Sum weight of the allocations. |
michael@0 | 259 | ** Callsite runs total all allocations below the callsite. |
michael@0 | 260 | */ |
michael@0 | 261 | uint64_t mWeight64; |
michael@0 | 262 | |
michael@0 | 263 | /* |
michael@0 | 264 | ** Sum size of the allocations. |
michael@0 | 265 | ** Callsite runs total all allocations below the callsite. |
michael@0 | 266 | */ |
michael@0 | 267 | uint32_t mSize; |
michael@0 | 268 | |
michael@0 | 269 | /* |
michael@0 | 270 | ** A stamp, indicated the relevance of the run. |
michael@0 | 271 | ** If the stamp does not match the origin value, the |
michael@0 | 272 | ** data contained here-in is considered invalid. |
michael@0 | 273 | */ |
michael@0 | 274 | uint32_t mStamp; |
michael@0 | 275 | |
michael@0 | 276 | /* |
michael@0 | 277 | ** A sum total of allocations (note, not sizes) below the callsite. |
michael@0 | 278 | ** This is NOT the same as STRun::mAllocationCount which |
michael@0 | 279 | ** tracks the STRun::mAllocations array size. |
michael@0 | 280 | */ |
michael@0 | 281 | uint32_t mCompositeCount; |
michael@0 | 282 | |
michael@0 | 283 | /* |
michael@0 | 284 | ** A sum total runtime cost of heap operations below the calliste. |
michael@0 | 285 | ** The cost is defined as the number of time units recorded as being |
michael@0 | 286 | ** spent in heap code (time of malloc, free, et al.). |
michael@0 | 287 | */ |
michael@0 | 288 | uint32_t mHeapRuntimeCost; |
michael@0 | 289 | } STCallsiteStats; |
michael@0 | 290 | |
michael@0 | 291 | /* |
michael@0 | 292 | ** STRun |
michael@0 | 293 | ** |
michael@0 | 294 | ** A run is a closed set of allocations. |
michael@0 | 295 | ** Given a run, we can deduce information about the contained allocations. |
michael@0 | 296 | ** We can also determine if an allocation lives beyond a run (leak). |
michael@0 | 297 | ** |
michael@0 | 298 | ** A run might be used to represent allocations for an entire application. |
michael@0 | 299 | ** A run might also be used to represent allocations from a single callstack. |
michael@0 | 300 | */ |
michael@0 | 301 | typedef struct __struct_STRun |
michael@0 | 302 | { |
michael@0 | 303 | /* |
michael@0 | 304 | ** The array of allocations. |
michael@0 | 305 | */ |
michael@0 | 306 | uint32_t mAllocationCount; |
michael@0 | 307 | STAllocation** mAllocations; |
michael@0 | 308 | |
michael@0 | 309 | /* |
michael@0 | 310 | ** Callsites like to keep some information. |
michael@0 | 311 | ** As callsites are possibly shared between all contexts, each |
michael@0 | 312 | ** different context needs to keep different stats. |
michael@0 | 313 | */ |
michael@0 | 314 | STCallsiteStats *mStats; |
michael@0 | 315 | |
michael@0 | 316 | } STRun; |
michael@0 | 317 | |
michael@0 | 318 | /* |
michael@0 | 319 | ** Categorize allocations |
michael@0 | 320 | ** |
michael@0 | 321 | ** The objective is to have a tree of categories with each leaf node of the tree |
michael@0 | 322 | ** matching a set of callsites that belong to the category. Each category can |
michael@0 | 323 | ** signify a functional area like say css and hence the user can browse this |
michael@0 | 324 | ** tree looking for how much of each of these are live at an instant. |
michael@0 | 325 | */ |
michael@0 | 326 | |
michael@0 | 327 | /* |
michael@0 | 328 | ** STCategoryNode |
michael@0 | 329 | */ |
michael@0 | 330 | |
michael@0 | 331 | struct __struct_STCategoryNode |
michael@0 | 332 | { |
michael@0 | 333 | /* |
michael@0 | 334 | ** Category name |
michael@0 | 335 | */ |
michael@0 | 336 | const char *categoryName; |
michael@0 | 337 | |
michael@0 | 338 | /* |
michael@0 | 339 | ** Pointer to parent node. NULL for Root. |
michael@0 | 340 | */ |
michael@0 | 341 | STCategoryNode *parent; |
michael@0 | 342 | |
michael@0 | 343 | /* |
michael@0 | 344 | ** For non-leaf nodes, an array of children node pointers. |
michael@0 | 345 | ** NULL if leaf node. |
michael@0 | 346 | */ |
michael@0 | 347 | STCategoryNode** children; |
michael@0 | 348 | uint32_t nchildren; |
michael@0 | 349 | |
michael@0 | 350 | /* |
michael@0 | 351 | ** The Run(s). Valid for both leaf and parent nodes. |
michael@0 | 352 | ** One run per --Context to handle multiple data sets. |
michael@0 | 353 | ** The relevant index for the particular request will be |
michael@0 | 354 | ** mIndex stored by the mContext of the request. |
michael@0 | 355 | */ |
michael@0 | 356 | STRun **runs; |
michael@0 | 357 | }; |
michael@0 | 358 | |
michael@0 | 359 | |
michael@0 | 360 | struct __struct_STCategoryRule |
michael@0 | 361 | { |
michael@0 | 362 | /* |
michael@0 | 363 | ** The pattern for the rule. Patterns are an array of strings. |
michael@0 | 364 | ** A callsite needs to pass substring match for all the strings. |
michael@0 | 365 | */ |
michael@0 | 366 | char* pats[ST_MAX_PATTERNS_PER_RULE]; |
michael@0 | 367 | uint32_t patlen[ST_MAX_PATTERNS_PER_RULE]; |
michael@0 | 368 | uint32_t npats; |
michael@0 | 369 | |
michael@0 | 370 | /* |
michael@0 | 371 | ** Category name that this rule belongs to |
michael@0 | 372 | */ |
michael@0 | 373 | const char* categoryName; |
michael@0 | 374 | |
michael@0 | 375 | /* |
michael@0 | 376 | ** The node this should be categorized into |
michael@0 | 377 | */ |
michael@0 | 378 | STCategoryNode* node; |
michael@0 | 379 | }; |
michael@0 | 380 | |
michael@0 | 381 | |
michael@0 | 382 | /* |
michael@0 | 383 | ** CategoryName to Node mapping table |
michael@0 | 384 | */ |
michael@0 | 385 | typedef struct __struct_STCategoryMapEntry { |
michael@0 | 386 | STCategoryNode* node; |
michael@0 | 387 | const char * categoryName; |
michael@0 | 388 | } STCategoryMapEntry; |
michael@0 | 389 | |
michael@0 | 390 | /* |
michael@0 | 391 | ** Option genres. |
michael@0 | 392 | ** |
michael@0 | 393 | ** This helps to determine what functionality each option effects. |
michael@0 | 394 | ** In specific, this will help use determine when and when not to |
michael@0 | 395 | ** totally recaclulate the sorted run and categories. |
michael@0 | 396 | ** Be very aware that adding things to a particular genre, or adding a genre, |
michael@0 | 397 | ** may completely screw up the caching algorithms of SpaceTrace. |
michael@0 | 398 | ** See contextLookup() or ask someone that knows if you are in doubt. |
michael@0 | 399 | */ |
michael@0 | 400 | typedef enum __enum_STOptionGenre |
michael@0 | 401 | { |
michael@0 | 402 | CategoryGenre = 0, |
michael@0 | 403 | DataSortGenre, |
michael@0 | 404 | DataSetGenre, |
michael@0 | 405 | DataSizeGenre, |
michael@0 | 406 | UIGenre, |
michael@0 | 407 | ServerGenre, |
michael@0 | 408 | BatchModeGenre, |
michael@0 | 409 | |
michael@0 | 410 | /* |
michael@0 | 411 | ** Last one please. |
michael@0 | 412 | */ |
michael@0 | 413 | MaxGenres |
michael@0 | 414 | } |
michael@0 | 415 | STOptionGenre; |
michael@0 | 416 | |
michael@0 | 417 | /* |
michael@0 | 418 | ** STOptions |
michael@0 | 419 | ** |
michael@0 | 420 | ** Structure containing the varios options for the code. |
michael@0 | 421 | ** The definition of these options exists in a different file. |
michael@0 | 422 | ** We access that definition via macros to inline our structure definition. |
michael@0 | 423 | */ |
michael@0 | 424 | #define ST_CMD_OPTION_BOOL(option_name, option_genre, option_help) PRBool m##option_name; |
michael@0 | 425 | #define ST_CMD_OPTION_STRING(option_name, option_genre, default_value, option_help) char m##option_name[ST_OPTION_STRING_MAX]; |
michael@0 | 426 | #define ST_CMD_OPTION_STRING_ARRAY(option_name, option_genre, array_size, option_help) char m##option_name[array_size][ST_OPTION_STRING_MAX]; |
michael@0 | 427 | #define ST_CMD_OPTION_STRING_PTR_ARRAY(option_name, option_genre, option_help) const char** m##option_name; uint32_t m##option_name##Count; |
michael@0 | 428 | #define ST_CMD_OPTION_UINT32(option_name, option_genre, default_value, multiplier, option_help) uint32_t m##option_name; |
michael@0 | 429 | #define ST_CMD_OPTION_UINT64(option_name, option_genre, default_value, multiplier, option_help) uint64_t m##option_name##64; |
michael@0 | 430 | |
michael@0 | 431 | typedef struct __struct_STOptions |
michael@0 | 432 | { |
michael@0 | 433 | #include "stoptions.h" |
michael@0 | 434 | } |
michael@0 | 435 | STOptions; |
michael@0 | 436 | |
michael@0 | 437 | typedef struct __struct_STContext |
michael@0 | 438 | /* |
michael@0 | 439 | ** A per request, thread safe, manner of accessing the contained members. |
michael@0 | 440 | ** A reader/writer lock ensures that the data is properly initialized before |
michael@0 | 441 | ** readers of the data begin their work. |
michael@0 | 442 | ** |
michael@0 | 443 | ** mRWLock reader/writer lock. |
michael@0 | 444 | ** writer lock is held to ensure initialization, though |
michael@0 | 445 | ** others can be attempting to acquire read locks |
michael@0 | 446 | ** at that time. |
michael@0 | 447 | ** writer lock is also used in destruction to make sure |
michael@0 | 448 | ** there are no more readers of data contained herein. |
michael@0 | 449 | ** reader lock is to allow multiple clients to read the |
michael@0 | 450 | ** data at the same time; implies is they must not |
michael@0 | 451 | ** write anything. |
michael@0 | 452 | ** mIndex Consider this much like thread private data or thread |
michael@0 | 453 | ** local storage in a few places. |
michael@0 | 454 | ** The index is specifically reserved for this context's |
michael@0 | 455 | ** usage in other data structure array's provided |
michael@0 | 456 | ** for the particular thread/client/context. |
michael@0 | 457 | ** This should not be modified after initialization. |
michael@0 | 458 | ** mSortedRun A pre sorted run taken from the global run, with our |
michael@0 | 459 | ** options applied. |
michael@0 | 460 | ** mImageLock An overly simplistic locking mechanism to protect the |
michael@0 | 461 | ** shared image cache. |
michael@0 | 462 | ** The proper implementation would have a reader/writer |
michael@0 | 463 | ** lock per cached image data. |
michael@0 | 464 | ** However, this will prove to be simpler for the time |
michael@0 | 465 | ** being. |
michael@0 | 466 | ** mFootprintCached Whether or not YData contains something useful. |
michael@0 | 467 | ** mTimevalCached Whether or not YData contains something useful. |
michael@0 | 468 | ** mLifespanCached Whether or not YData contains something useful. |
michael@0 | 469 | ** mWeightCached Whether or not YData contains something useful. |
michael@0 | 470 | ** mFootprintYData Precomputed cached graph data. |
michael@0 | 471 | ** mTimevalYData Precomputed cached graph data. |
michael@0 | 472 | ** mLifespanYData Precomputed cached graph data. |
michael@0 | 473 | ** mWeightYData Precomputed cached graph data. |
michael@0 | 474 | */ |
michael@0 | 475 | { |
michael@0 | 476 | PRRWLock* mRWLock; |
michael@0 | 477 | uint32_t mIndex; |
michael@0 | 478 | STRun* mSortedRun; |
michael@0 | 479 | #if ST_WANT_GRAPHS |
michael@0 | 480 | PRLock* mImageLock; |
michael@0 | 481 | PRBool mFootprintCached; |
michael@0 | 482 | PRBool mTimevalCached; |
michael@0 | 483 | PRBool mLifespanCached; |
michael@0 | 484 | PRBool mWeightCached; |
michael@0 | 485 | uint32_t mFootprintYData[STGD_SPACE_X]; |
michael@0 | 486 | uint32_t mTimevalYData[STGD_SPACE_X]; |
michael@0 | 487 | uint32_t mLifespanYData[STGD_SPACE_X]; |
michael@0 | 488 | uint64_t mWeightYData64[STGD_SPACE_X]; |
michael@0 | 489 | #endif |
michael@0 | 490 | } |
michael@0 | 491 | STContext; |
michael@0 | 492 | |
michael@0 | 493 | |
michael@0 | 494 | typedef struct __struct_STContextCacheItem |
michael@0 | 495 | /* |
michael@0 | 496 | ** This basically pools the common items that the context cache will |
michael@0 | 497 | ** want to track on a per context basis. |
michael@0 | 498 | ** |
michael@0 | 499 | ** mOptions What options this item represents. |
michael@0 | 500 | ** mContext State/data this cache item is wrapping. |
michael@0 | 501 | ** mReferenceCount A count of clients currently using this item. |
michael@0 | 502 | ** Should this item be 0, then the cache might |
michael@0 | 503 | ** decide to evict this context. |
michael@0 | 504 | ** Should this item not be 0, once it reaches |
michael@0 | 505 | ** zero a condition variable in the context cache |
michael@0 | 506 | ** will be signaled to notify the availability. |
michael@0 | 507 | ** mLastAccessed A timestamp of when this item was last accessed/released. |
michael@0 | 508 | ** Ignore this unless the reference count is 0, |
michael@0 | 509 | ** This is used to evict the oldest unused item from |
michael@0 | 510 | ** the context cache. |
michael@0 | 511 | ** mInUse Mainly PR_FALSE only at the beginning of the process, |
michael@0 | 512 | ** but this indicates that the item has not yet been |
michael@0 | 513 | ** used at all, and thus shouldn't be evaluated for |
michael@0 | 514 | ** a cache hit. |
michael@0 | 515 | */ |
michael@0 | 516 | { |
michael@0 | 517 | STOptions mOptions; |
michael@0 | 518 | STContext mContext; |
michael@0 | 519 | int32_t mReferenceCount; |
michael@0 | 520 | PRIntervalTime mLastAccessed; |
michael@0 | 521 | PRBool mInUse; |
michael@0 | 522 | } |
michael@0 | 523 | STContextCacheItem; |
michael@0 | 524 | |
michael@0 | 525 | |
michael@0 | 526 | typedef struct __struct_STContextCache |
michael@0 | 527 | /* |
michael@0 | 528 | ** A thread safe, possibly blocking, cache of context items. |
michael@0 | 529 | ** |
michael@0 | 530 | ** mLock Must hold the lock to read/access/write to this struct, as |
michael@0 | 531 | ** well as any items it holds. |
michael@0 | 532 | ** mCacheMiss All items are busy and there were no cache matches. |
michael@0 | 533 | ** This condition variable is used to wait until an item becomes |
michael@0 | 534 | ** "available" to be evicted from the cache. |
michael@0 | 535 | ** mItems Array of items. |
michael@0 | 536 | ** mItemCount Number of items in array. |
michael@0 | 537 | ** This is generally the same as the global option's command line |
michael@0 | 538 | ** mContexts.... |
michael@0 | 539 | */ |
michael@0 | 540 | { |
michael@0 | 541 | PRLock* mLock; |
michael@0 | 542 | PRCondVar* mCacheMiss; |
michael@0 | 543 | STContextCacheItem* mItems; |
michael@0 | 544 | uint32_t mItemCount; |
michael@0 | 545 | } |
michael@0 | 546 | STContextCache; |
michael@0 | 547 | |
michael@0 | 548 | |
michael@0 | 549 | /* |
michael@0 | 550 | ** STRequest |
michael@0 | 551 | ** |
michael@0 | 552 | ** Things specific to a request. |
michael@0 | 553 | */ |
michael@0 | 554 | typedef struct __struct_STRequest |
michael@0 | 555 | { |
michael@0 | 556 | /* |
michael@0 | 557 | ** Sink/where to output. |
michael@0 | 558 | */ |
michael@0 | 559 | PRFileDesc* mFD; |
michael@0 | 560 | |
michael@0 | 561 | /* |
michael@0 | 562 | ** The filename requested. |
michael@0 | 563 | */ |
michael@0 | 564 | const char* mGetFileName; |
michael@0 | 565 | |
michael@0 | 566 | /* |
michael@0 | 567 | ** The GET form data, if any. |
michael@0 | 568 | */ |
michael@0 | 569 | const FormData* mGetData; |
michael@0 | 570 | |
michael@0 | 571 | /* |
michael@0 | 572 | ** Options specific to this request. |
michael@0 | 573 | */ |
michael@0 | 574 | STOptions mOptions; |
michael@0 | 575 | |
michael@0 | 576 | /* |
michael@0 | 577 | ** The context/data/state of the request. |
michael@0 | 578 | */ |
michael@0 | 579 | STContext* mContext; |
michael@0 | 580 | } STRequest; |
michael@0 | 581 | |
michael@0 | 582 | |
michael@0 | 583 | /* |
michael@0 | 584 | ** STGlobals |
michael@0 | 585 | ** |
michael@0 | 586 | ** Various globals we keep around. |
michael@0 | 587 | */ |
michael@0 | 588 | typedef struct __struct_STGlobals |
michael@0 | 589 | { |
michael@0 | 590 | /* |
michael@0 | 591 | ** The string which identifies this program. |
michael@0 | 592 | */ |
michael@0 | 593 | const char* mProgramName; |
michael@0 | 594 | |
michael@0 | 595 | /* |
michael@0 | 596 | ** Options derived from the command line. |
michael@0 | 597 | ** These are used as defaults, and should remain static during |
michael@0 | 598 | ** the run of the application. |
michael@0 | 599 | */ |
michael@0 | 600 | STOptions mCommandLineOptions; |
michael@0 | 601 | |
michael@0 | 602 | /* |
michael@0 | 603 | ** Context cache. |
michael@0 | 604 | ** As clients come in, based on their options, a different context |
michael@0 | 605 | ** will be used to service them. |
michael@0 | 606 | */ |
michael@0 | 607 | STContextCache mContextCache; |
michael@0 | 608 | |
michael@0 | 609 | /* |
michael@0 | 610 | ** Various counters for different types of events. |
michael@0 | 611 | */ |
michael@0 | 612 | uint32_t mMallocCount; |
michael@0 | 613 | uint32_t mCallocCount; |
michael@0 | 614 | uint32_t mReallocCount; |
michael@0 | 615 | uint32_t mFreeCount; |
michael@0 | 616 | |
michael@0 | 617 | /* |
michael@0 | 618 | ** Total events, operation counter. |
michael@0 | 619 | */ |
michael@0 | 620 | uint32_t mOperationCount; |
michael@0 | 621 | |
michael@0 | 622 | /* |
michael@0 | 623 | ** The "run" of the input. |
michael@0 | 624 | */ |
michael@0 | 625 | STRun mRun; |
michael@0 | 626 | |
michael@0 | 627 | /* |
michael@0 | 628 | ** Operation minimum/maximum timevals. |
michael@0 | 629 | ** So that we can determine the overall timeval of the run. |
michael@0 | 630 | ** NOTE: These are NOT the options to control the data set. |
michael@0 | 631 | */ |
michael@0 | 632 | uint32_t mMinTimeval; |
michael@0 | 633 | uint32_t mMaxTimeval; |
michael@0 | 634 | |
michael@0 | 635 | /* |
michael@0 | 636 | ** Calculates peak allocation overall for all allocations. |
michael@0 | 637 | */ |
michael@0 | 638 | uint32_t mPeakMemoryUsed; |
michael@0 | 639 | uint32_t mMemoryUsed; |
michael@0 | 640 | |
michael@0 | 641 | /* |
michael@0 | 642 | ** A list of rules for categorization read in from the mCategoryFile |
michael@0 | 643 | */ |
michael@0 | 644 | STCategoryRule** mCategoryRules; |
michael@0 | 645 | uint32_t mNRules; |
michael@0 | 646 | |
michael@0 | 647 | /* |
michael@0 | 648 | ** CategoryName to Node mapping table |
michael@0 | 649 | */ |
michael@0 | 650 | STCategoryMapEntry** mCategoryMap; |
michael@0 | 651 | uint32_t mNCategoryMap; |
michael@0 | 652 | |
michael@0 | 653 | /* |
michael@0 | 654 | ** Categorized allocations. For now we support only one tree. |
michael@0 | 655 | */ |
michael@0 | 656 | STCategoryNode mCategoryRoot; |
michael@0 | 657 | |
michael@0 | 658 | /* |
michael@0 | 659 | ** tmreader hash tables. |
michael@0 | 660 | ** Moved into globals since we need to destroy these only after all |
michael@0 | 661 | ** client threads are finishes (after PR_Cleanup). |
michael@0 | 662 | */ |
michael@0 | 663 | tmreader* mTMR; |
michael@0 | 664 | } STGlobals; |
michael@0 | 665 | |
michael@0 | 666 | |
michael@0 | 667 | /* |
michael@0 | 668 | ** Function prototypes |
michael@0 | 669 | */ |
michael@0 | 670 | extern STRun* createRun(STContext* inContext, uint32_t aStamp); |
michael@0 | 671 | extern void freeRun(STRun* aRun); |
michael@0 | 672 | extern int initCategories(STGlobals* g); |
michael@0 | 673 | extern int categorizeRun(STOptions* inOptions, STContext* inContext, const STRun* aRun, STGlobals* g); |
michael@0 | 674 | extern STCategoryNode* findCategoryNode(const char *catName, STGlobals *g); |
michael@0 | 675 | extern int freeCategories(STGlobals* g); |
michael@0 | 676 | extern int displayCategoryReport(STRequest* inRequest, STCategoryNode *root, int depth); |
michael@0 | 677 | |
michael@0 | 678 | extern int recalculateAllocationCost(STOptions* inOptions, STContext* inContext, STRun* aRun, STAllocation* aAllocation, PRBool updateParent); |
michael@0 | 679 | extern void htmlHeader(STRequest* inRequest, const char* aTitle); |
michael@0 | 680 | extern void htmlFooter(STRequest* inRequest); |
michael@0 | 681 | extern void htmlAnchor(STRequest* inRequest, |
michael@0 | 682 | const char* aHref, |
michael@0 | 683 | const char* aText, |
michael@0 | 684 | const char* aTarget, |
michael@0 | 685 | const char* aClass, |
michael@0 | 686 | STOptions* inOptions); |
michael@0 | 687 | extern char *FormatNumber(int32_t num); |
michael@0 | 688 | |
michael@0 | 689 | /* |
michael@0 | 690 | ** shared globals |
michael@0 | 691 | */ |
michael@0 | 692 | extern STGlobals globals; |
michael@0 | 693 | |
michael@0 | 694 | #endif /* spacetrace_h__ */ |