js/src/builtin/Profilers.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/builtin/Profilers.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,95 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +/*
    1.11 + * Functions for controlling profilers from within JS: Valgrind, Perf,
    1.12 + * Shark, etc.
    1.13 + */
    1.14 +#ifndef builtin_Profilers_h
    1.15 +#define builtin_Profilers_h
    1.16 +
    1.17 +#include "jstypes.h"
    1.18 +
    1.19 +#ifdef _MSC_VER
    1.20 +typedef int pid_t;
    1.21 +#else
    1.22 +#include <unistd.h>
    1.23 +#endif
    1.24 +
    1.25 +/**
    1.26 + * Start any profilers that are available and have been configured on for this
    1.27 + * platform. This is NOT thread safe.
    1.28 + *
    1.29 + * The profileName is used by some profilers to describe the current profiling
    1.30 + * run. It may be used for part of the filename of the output, but the
    1.31 + * specifics depend on the profiler. Many profilers will ignore it. Passing in
    1.32 + * nullptr is legal; some profilers may use it to output to stdout or similar.
    1.33 + *
    1.34 + * Returns true if no profilers fail to start.
    1.35 + */
    1.36 +extern JS_PUBLIC_API(bool)
    1.37 +JS_StartProfiling(const char *profileName, pid_t pid);
    1.38 +
    1.39 +/**
    1.40 + * Stop any profilers that were previously started with JS_StartProfiling.
    1.41 + * Returns true if no profilers fail to stop.
    1.42 + */
    1.43 +extern JS_PUBLIC_API(bool)
    1.44 +JS_StopProfiling(const char *profileName);
    1.45 +
    1.46 +/**
    1.47 + * Write the current profile data to the given file, if applicable to whatever
    1.48 + * profiler is being used.
    1.49 + */
    1.50 +extern JS_PUBLIC_API(bool)
    1.51 +JS_DumpProfile(const char *outfile, const char *profileName);
    1.52 +
    1.53 +/**
    1.54 + * Pause currently active profilers (only supported by some profilers). Returns
    1.55 + * whether any profilers failed to pause. (Profilers that do not support
    1.56 + * pause/resume do not count.)
    1.57 + */
    1.58 +extern JS_PUBLIC_API(bool)
    1.59 +JS_PauseProfilers(const char *profileName);
    1.60 +
    1.61 +/**
    1.62 + * Resume suspended profilers
    1.63 + */
    1.64 +extern JS_PUBLIC_API(bool)
    1.65 +JS_ResumeProfilers(const char *profileName);
    1.66 +
    1.67 +/**
    1.68 + * The profiling API calls are not able to report errors, so they use a
    1.69 + * thread-unsafe global memory buffer to hold the last error encountered. This
    1.70 + * should only be called after something returns false.
    1.71 + */
    1.72 +JS_PUBLIC_API(const char *)
    1.73 +JS_UnsafeGetLastProfilingError();
    1.74 +
    1.75 +#ifdef MOZ_CALLGRIND
    1.76 +
    1.77 +extern JS_FRIEND_API(bool)
    1.78 +js_StopCallgrind();
    1.79 +
    1.80 +extern JS_FRIEND_API(bool)
    1.81 +js_StartCallgrind();
    1.82 +
    1.83 +extern JS_FRIEND_API(bool)
    1.84 +js_DumpCallgrind(const char *outfile);
    1.85 +
    1.86 +#endif /* MOZ_CALLGRIND */
    1.87 +
    1.88 +#ifdef __linux__
    1.89 +
    1.90 +extern JS_FRIEND_API(bool)
    1.91 +js_StartPerf();
    1.92 +
    1.93 +extern JS_FRIEND_API(bool)
    1.94 +js_StopPerf();
    1.95 +
    1.96 +#endif /* __linux__ */
    1.97 +
    1.98 +#endif /* builtin_Profilers_h */

mercurial