Source code

Revision control

Other Tools

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