Line | % of fetches | Source |
---|---|---|
1 | // Copyright (c) 2007-2016 Hartmut Kaiser | |
2 | // | |
3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | #pragma once // prevent multiple inclusions of this header file. | |
7 | ||
8 | #include <hpx/config.hpp> | |
9 | #include <hpx/runtime/get_locality_id.hpp> | |
10 | #include <hpx/util/thread_description.hpp> | |
11 | #include <hpx/runtime/get_num_localities.hpp> | |
12 | #include <hpx/runtime/startup_function.hpp> | |
13 | ||
14 | #ifdef HPX_HAVE_APEX | |
15 | #include "apex_api.hpp" | |
16 | #endif | |
17 | ||
18 | namespace hpx { namespace util | |
19 | { | |
20 | #ifdef HPX_HAVE_APEX | |
21 | static void hpx_util_apex_init_startup(void) | |
22 | { | |
23 | apex::init(nullptr, hpx::get_locality_id(), | |
24 | hpx::get_initial_num_localities()); | |
25 | } | |
26 | ||
27 | inline void apex_init() | |
28 | { | |
29 | hpx_util_apex_init_startup(); | |
30 | //hpx::register_pre_startup_function(&hpx_util_apex_init_startup); | |
31 | } | |
32 | ||
33 | inline void apex_finalize() | |
34 | { | |
35 | apex::finalize(); | |
36 | } | |
37 | ||
38 | struct apex_wrapper | |
39 | { | |
40 | apex_wrapper(thread_description const& name) | |
41 | : name_(name), stopped(false), profiler_(nullptr) | |
42 | { | |
43 | if (name_.kind() == thread_description::data_type_description) | |
44 | { | |
45 | profiler_ = apex::start(name_.get_description()); | |
46 | } | |
47 | else | |
48 | { | |
49 | profiler_ = apex::start( | |
50 | apex_function_address(name_.get_address())); | |
51 | } | |
52 | } | |
53 | ~apex_wrapper() | |
54 | { | |
55 | stop(); | |
56 | } | |
57 | ||
58 | void stop() { | |
59 | if(!stopped) { | |
60 | stopped = true; | |
61 | apex::stop(profiler_); | |
62 | } | |
63 | } | |
64 | ||
65 | void yield() { | |
66 | if(!stopped) { | |
67 | stopped = true; | |
68 | apex::yield(profiler_); | |
69 | } | |
70 | } | |
71 | ||
72 | thread_description name_; | |
73 | bool stopped; | |
74 | apex::profiler * profiler_; | |
75 | }; | |
76 | ||
77 | struct apex_wrapper_init | |
78 | { | |
79 | apex_wrapper_init(int argc, char **argv) | |
80 | { | |
81 | //apex::init(nullptr, hpx::get_locality_id(), | |
82 | // hpx::get_initial_num_localities()); | |
83 | hpx::register_pre_startup_function(&hpx_util_apex_init_startup); | |
84 | } | |
85 | ~apex_wrapper_init() | |
86 | { | |
87 | apex::finalize(); | |
88 | } | |
89 | }; | |
90 | #else | |
91 | inline void apex_init() {} | |
92 | inline void apex_finalize() {} | |
93 | ||
94 | struct apex_wrapper | |
95 | { | |
96 | apex_wrapper(thread_description const& name) {} | |
97 | ~apex_wrapper() {} | |
98 | }; | |
99 | ||
100 | struct apex_wrapper_init | |
101 | { | |
102 | apex_wrapper_init(int argc, char **argv) {} | |
103 | ~apex_wrapper_init() {} | |
104 | }; | |
105 | #endif | |
106 | }} | |
107 | ||
108 |
Copyright (c) 2006-2012 Rogue Wave Software, Inc. All Rights Reserved.
Patents pending.