|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 /* |
|
8 * Functions for controlling profilers from within JS: Valgrind, Perf, |
|
9 * Shark, etc. |
|
10 */ |
|
11 #ifndef builtin_Profilers_h |
|
12 #define builtin_Profilers_h |
|
13 |
|
14 #include "jstypes.h" |
|
15 |
|
16 #ifdef _MSC_VER |
|
17 typedef int pid_t; |
|
18 #else |
|
19 #include <unistd.h> |
|
20 #endif |
|
21 |
|
22 /** |
|
23 * Start any profilers that are available and have been configured on for this |
|
24 * platform. This is NOT thread safe. |
|
25 * |
|
26 * The profileName is used by some profilers to describe the current profiling |
|
27 * run. It may be used for part of the filename of the output, but the |
|
28 * specifics depend on the profiler. Many profilers will ignore it. Passing in |
|
29 * nullptr is legal; some profilers may use it to output to stdout or similar. |
|
30 * |
|
31 * Returns true if no profilers fail to start. |
|
32 */ |
|
33 extern JS_PUBLIC_API(bool) |
|
34 JS_StartProfiling(const char *profileName, pid_t pid); |
|
35 |
|
36 /** |
|
37 * Stop any profilers that were previously started with JS_StartProfiling. |
|
38 * Returns true if no profilers fail to stop. |
|
39 */ |
|
40 extern JS_PUBLIC_API(bool) |
|
41 JS_StopProfiling(const char *profileName); |
|
42 |
|
43 /** |
|
44 * Write the current profile data to the given file, if applicable to whatever |
|
45 * profiler is being used. |
|
46 */ |
|
47 extern JS_PUBLIC_API(bool) |
|
48 JS_DumpProfile(const char *outfile, const char *profileName); |
|
49 |
|
50 /** |
|
51 * Pause currently active profilers (only supported by some profilers). Returns |
|
52 * whether any profilers failed to pause. (Profilers that do not support |
|
53 * pause/resume do not count.) |
|
54 */ |
|
55 extern JS_PUBLIC_API(bool) |
|
56 JS_PauseProfilers(const char *profileName); |
|
57 |
|
58 /** |
|
59 * Resume suspended profilers |
|
60 */ |
|
61 extern JS_PUBLIC_API(bool) |
|
62 JS_ResumeProfilers(const char *profileName); |
|
63 |
|
64 /** |
|
65 * The profiling API calls are not able to report errors, so they use a |
|
66 * thread-unsafe global memory buffer to hold the last error encountered. This |
|
67 * should only be called after something returns false. |
|
68 */ |
|
69 JS_PUBLIC_API(const char *) |
|
70 JS_UnsafeGetLastProfilingError(); |
|
71 |
|
72 #ifdef MOZ_CALLGRIND |
|
73 |
|
74 extern JS_FRIEND_API(bool) |
|
75 js_StopCallgrind(); |
|
76 |
|
77 extern JS_FRIEND_API(bool) |
|
78 js_StartCallgrind(); |
|
79 |
|
80 extern JS_FRIEND_API(bool) |
|
81 js_DumpCallgrind(const char *outfile); |
|
82 |
|
83 #endif /* MOZ_CALLGRIND */ |
|
84 |
|
85 #ifdef __linux__ |
|
86 |
|
87 extern JS_FRIEND_API(bool) |
|
88 js_StartPerf(); |
|
89 |
|
90 extern JS_FRIEND_API(bool) |
|
91 js_StopPerf(); |
|
92 |
|
93 #endif /* __linux__ */ |
|
94 |
|
95 #endif /* builtin_Profilers_h */ |