blob: 35c451f3e4d87e6e1cc1397e17af8b361ec6e274 [file] [log] [blame]
weidendoa17f2a32006-03-20 10:27:30 +00001/*--------------------------------------------------------------------*/
2/*--- Callgrind ---*/
3/*--- ct_costs.c ---*/
4/*--------------------------------------------------------------------*/
5
6/*
7 This file is part of Callgrind, a Valgrind tool for call tracing.
8
sewardj0f157dd2013-10-18 14:27:36 +00009 Copyright (C) 2002-2013, Josef Weidendorfer (Josef.Weidendorfer@gmx.de)
weidendoa17f2a32006-03-20 10:27:30 +000010
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 02111-1307, USA.
25
26 The GNU General Public License is contained in the file COPYING.
27*/
28
29#include "global.h"
30
sewardje7a50822011-04-20 11:54:32 +000031#include "pub_tool_mallocfree.h"
weidendoa17f2a32006-03-20 10:27:30 +000032
33#define COSTCHUNK_SIZE 100000
34
35UInt CLG_(costarray_entries) = 0;
36UInt CLG_(costarray_chunks) = 0;
37static CostChunk* cost_chunk_base = 0;
38static CostChunk* cost_chunk_current = 0;
39
40ULong* CLG_(get_costarray)(Int size)
41{
42 ULong* ptr;
43
44 if (!cost_chunk_current ||
45 (cost_chunk_current->size - cost_chunk_current->used < size)) {
sewardj9c606bd2008-09-18 18:12:50 +000046 CostChunk* cc = (CostChunk*) CLG_MALLOC("cl.costs.gc.1",
47 sizeof(CostChunk) +
weidendoa17f2a32006-03-20 10:27:30 +000048 COSTCHUNK_SIZE * sizeof(ULong));
49 cc->size = COSTCHUNK_SIZE;
50 cc->used = 0;
51 cc->next = 0;
52
53 if (cost_chunk_current)
54 cost_chunk_current->next = cc;
55 cost_chunk_current = cc;
56
57 if (!cost_chunk_base) cost_chunk_base = cc;
58
59 CLG_(costarray_chunks)++;
60 }
61
62 ptr = &(cost_chunk_current->data[cost_chunk_current->used]);
63 cost_chunk_current->used += size;
64
65 CLG_(costarray_entries) += size;
66
67 return ptr;
68}
69
70void CLG_(free_costarrays)()
71{
72 CostChunk* cc = cost_chunk_base, *cc_next;
73 while(cc) {
74 cc_next = cc->next;
75 VG_(free)(cc);
76 cc = cc_next;
77 }
78 cost_chunk_base = 0;
79 cost_chunk_current = 0;
80}