HPCToolkit
cct_bundle.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 #include <stdbool.h>
48 
49 #include "cct_bundle.h"
51 #include <cct/cct.h>
52 #include <messages/messages.h>
54 
55 
56 //
57 // Private Operations
58 //
59 
60 //
61 // "Special" routine to serve as a placeholder for "idle" resource
62 //
63 
64 static void
65 GPU_IDLE(void)
66 {
67 }
68 
69 // special routine for datacentric resource
70 static void
72 {}
73 
74 
75 void
76 NO_THREAD(void)
77 {
78 }
79 
80 //
81 // Interface procedures
82 //
83 
84 void
86 {
87  bundle->top = hpcrun_cct_new();
88  bundle->tree_root = bundle->top;
89 
90  bundle->thread_root = bundle->tree_root;
91  bundle->ctxt = ctxt;
92  bundle->num_nodes = 0;
93  // FIXME: change to omp style here
94  //
95  // If there is a creation context (ie, this is a pthread),
96  // then the creation context gets special treatment.
97  //
98  // If the -dd flag ATTACH_THREAD_CTXT is *set*, then
99  // attach all thread-stopped call paths
100  // to the call context prefix node instead of the top of the tree.
101  //
102  // By default (ATTACH_THREAD_CTXT is *cleared*), then attach
103  // all thread-stopped call paths to thread root.
104  //
105  if (ENABLED(ATTACH_THREAD_CTXT) && ctxt) {
106  hpcrun_cct_insert_path(&(bundle->thread_root), ctxt->context);
107  }
112 }
113 
114 //
115 // Write to file for cct bundle:
116 //
117 int
119  cct2metrics_t* cct2metrics_map)
120 {
121  if (!fs) { return HPCRUN_ERR; }
122 
123  cct_node_t* final = bndl->tree_root;
124  cct_node_t* partial_insert = final;
125 
126 
127  //
128  // attach partial unwinds at appointed slot
129  //
130  hpcrun_cct_insert_node(partial_insert, bndl->partial_unw_root);
131 
132  //
133  //
134  //
135 
136  // write out newly constructed cct
137 
138  return hpcrun_cct_fwrite(cct2metrics_map, bndl->top, fs, flags);
139 }
140 
141 //
142 // cct_fwrite helpers
143 //
144 
145 //
146 // utility functions
147 //
148 bool
150 {
151  bool rv = (cct->num_nodes <= 1);
152  if (rv) {
153  TMSG(CCT, "cct %p is empty", cct);
154  }
155  return rv;
156 }
157 
158 cct_node_t*
160  // attach special node to root if not already attached
161 {
164 
165  return cct->special_idle_node;
166 }
167 
168 
169 cct_node_t*
171 {
175  }
176  return cct->special_datacentric_node;
177 }
178 
179 cct_node_t*
181  // attach special node to root if not already attached
182 {
185 
186  return cct->special_no_thread_node;
187 }
cct_node_t * hpcrun_cct_new_special(void *addr)
Definition: cct.c:338
cct_node_t * special_no_thread_node
Definition: cct_bundle.h:80
static void GPU_IDLE(void)
Definition: cct_bundle.c:65
cct_node_t * special_datacentric_node
Definition: cct_bundle.h:78
void hpcrun_cct_insert_path(cct_node_t **root, cct_node_t *path)
Definition: cct.c:662
cct_ctxt_t * ctxt
Definition: cct_bundle.h:82
cct_node_t * tree_root
Definition: cct_bundle.h:65
void NO_THREAD(void)
Definition: cct_bundle.c:76
cct_node_t * hpcrun_cct_parent(cct_node_t *x)
Definition: cct.c:357
void hpcrun_cct_bundle_init(cct_bundle_t *bundle, cct_ctxt_t *ctxt)
Definition: cct_bundle.c:85
#define HPCRUN_ERR
cct_node_t * hpcrun_cct_bundle_get_idle_node(cct_bundle_t *cct)
Definition: cct_bundle.c:159
int hpcrun_cct_fwrite(cct2metrics_t *cct2metrics_map, cct_node_t *cct, FILE *fs, epoch_flags_t flags)
Definition: cct.c:672
cct_node_t * hpcrun_cct_new(void)
Definition: cct.c:326
bool hpcrun_empty_cct(cct_bundle_t *cct)
Definition: cct_bundle.c:149
cct_node_t * hpcrun_cct_bundle_get_nothread_node(cct_bundle_t *cct)
Definition: cct_bundle.c:180
static void DATACENTRIC()
Definition: cct_bundle.c:71
cct_node_t * partial_unw_root
Definition: cct_bundle.h:74
cct_node_t * hpcrun_cct_new_partial(void)
Definition: cct.c:332
#define TMSG(f,...)
Definition: messages.h:93
cct_node_t * top
Definition: cct_bundle.h:63
cct_node_t * hpcrun_cct_bundle_init_datacentric_node(cct_bundle_t *cct)
Definition: cct_bundle.c:170
void hpcrun_cct_set_node_root(cct_node_t *root)
Definition: cct.c:513
cct_node_t * special_idle_node
Definition: cct_bundle.h:76
cct_node_t * thread_root
Definition: cct_bundle.h:72
Definition: cct.c:96
unsigned long num_nodes
Definition: cct_bundle.h:84
cct_node_t * context
Definition: cct_ctxt.h:67
int hpcrun_cct_bundle_fwrite(FILE *fs, epoch_flags_t flags, cct_bundle_t *bndl, cct2metrics_t *cct2metrics_map)
Definition: cct_bundle.c:118
cct_node_t * hpcrun_cct_insert_node(cct_node_t *target, cct_node_t *src)
Definition: cct.c:537
#define ENABLED(f)
Definition: debug-flag.h:76