tools/profiler/GeckoProfiler.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /* *************** SPS Sampler Information ****************
michael@0 7 *
michael@0 8 * SPS is an always on profiler that takes fast and low overheads samples
michael@0 9 * of the program execution using only userspace functionity for portability.
michael@0 10 * The goal of this module is to provide performance data in a generic
michael@0 11 * cross platform way without requiring custom tools or kernel support.
michael@0 12 *
michael@0 13 * Non goals: Support features that are platform specific or replace
michael@0 14 * platform specific profilers.
michael@0 15 *
michael@0 16 * Samples are collected to form a timeline with optional timeline event (markers)
michael@0 17 * used for filtering.
michael@0 18 *
michael@0 19 * SPS collects samples in a platform independant way by using a speudo stack abstraction
michael@0 20 * of the real program stack by using 'sample stack frames'. When a sample is collected
michael@0 21 * all active sample stack frames and the program counter are recorded.
michael@0 22 */
michael@0 23
michael@0 24 /* *************** SPS Sampler File Format ****************
michael@0 25 *
michael@0 26 * Simple new line seperated tag format:
michael@0 27 * S -> BOF tags EOF
michael@0 28 * tags -> tag tags
michael@0 29 * tag -> CHAR - STRING
michael@0 30 *
michael@0 31 * Tags:
michael@0 32 * 's' - Sample tag followed by the first stack frame followed by 0 or more 'c' tags.
michael@0 33 * 'c' - Continue Sample tag gives remaining tag element. If a 'c' tag is seen without
michael@0 34 * a preceding 's' tag it should be ignored. This is to support the behavior
michael@0 35 * of circular buffers.
michael@0 36 * If the 'stackwalk' feature is enabled this tag will have the format
michael@0 37 * 'l-<library name>@<hex address>' and will expect an external tool to translate
michael@0 38 * the tag into something readable through a symbolication processing step.
michael@0 39 * 'm' - Timeline marker. Zero or more may appear before a 's' tag.
michael@0 40 * 'l' - Information about the program counter library and address. Post processing
michael@0 41 * can include function and source line. If built with leaf data enabled
michael@0 42 * this tag will describe the last 'c' tag.
michael@0 43 * 'r' - Responsiveness tag following an 's' tag. Gives an indication on how well the
michael@0 44 * application is responding to the event loop. Lower is better.
michael@0 45 * 't' - Elapse time since recording started.
michael@0 46 *
michael@0 47 */
michael@0 48
michael@0 49 #ifndef SAMPLER_H
michael@0 50 #define SAMPLER_H
michael@0 51
michael@0 52 #include "mozilla/NullPtr.h"
michael@0 53 #include "js/TypeDecls.h"
michael@0 54
michael@0 55 namespace mozilla {
michael@0 56 class TimeStamp;
michael@0 57 }
michael@0 58
michael@0 59 enum TracingMetadata {
michael@0 60 TRACING_DEFAULT,
michael@0 61 TRACING_INTERVAL_START,
michael@0 62 TRACING_INTERVAL_END
michael@0 63 };
michael@0 64
michael@0 65 #ifndef MOZ_ENABLE_PROFILER_SPS
michael@0 66
michael@0 67 #include <stdint.h>
michael@0 68
michael@0 69 // Insert a RAII in this scope to active a pseudo label. Any samples collected
michael@0 70 // in this scope will contain this annotation. For dynamic strings use
michael@0 71 // PROFILER_LABEL_PRINTF. Arguments must be string literals.
michael@0 72 #define PROFILER_LABEL(name_space, info) do {} while (0)
michael@0 73
michael@0 74 // Format a dynamic string as a pseudo label. These labels will a considerable
michael@0 75 // storage size in the circular buffer compared to regular labels. This function
michael@0 76 // can be used to annotate custom information such as URL for the resource being
michael@0 77 // decoded or the size of the paint.
michael@0 78 #define PROFILER_LABEL_PRINTF(name_space, info, format, ...) do {} while (0)
michael@0 79
michael@0 80 // Insert a marker in the profile timeline. This is useful to delimit something
michael@0 81 // important happening such as the first paint. Unlike profiler_label that are
michael@0 82 // only recorded if a sample is collected while it is active, marker will always
michael@0 83 // be collected.
michael@0 84 #define PROFILER_MARKER(info) do {} while (0)
michael@0 85 #define PROFILER_MARKER_PAYLOAD(info, payload) do {} while (0)
michael@0 86
michael@0 87 // Main thread specilization to avoid TLS lookup for performance critical use.
michael@0 88 #define PROFILER_MAIN_THREAD_LABEL(name_space, info) do {} while (0)
michael@0 89 #define PROFILER_MAIN_THREAD_LABEL_PRINTF(name_space, info, format, ...) do {} while (0)
michael@0 90
michael@0 91 static inline void profiler_tracing(const char* aCategory, const char* aInfo,
michael@0 92 TracingMetadata metaData = TRACING_DEFAULT) {}
michael@0 93
michael@0 94 // Initilize the profiler TLS, signal handlers on linux. If MOZ_PROFILER_STARTUP
michael@0 95 // is set the profiler will be started. This call must happen before any other
michael@0 96 // sampler calls. Particularly sampler_label/sampler_marker.
michael@0 97 static inline void profiler_init(void* stackTop) {};
michael@0 98
michael@0 99 // Clean up the profiler module, stopping it if required. This function may
michael@0 100 // also save a shutdown profile if requested. No profiler calls should happen
michael@0 101 // after this point and all pseudo labels should have been popped.
michael@0 102 static inline void profiler_shutdown() {};
michael@0 103
michael@0 104 // Start the profiler with the selected options. The samples will be
michael@0 105 // recorded in a circular buffer.
michael@0 106 // "aProfileEntries" is an abstract size indication of how big
michael@0 107 // the profile's circular buffer should be. Multiply by 4
michael@0 108 // words to get the cost.
michael@0 109 // "aInterval" the sampling interval. The profiler will do its
michael@0 110 // best to sample at this interval. The profiler visualization
michael@0 111 // should represent the actual sampling accuracy.
michael@0 112 static inline void profiler_start(int aProfileEntries, double aInterval,
michael@0 113 const char** aFeatures, uint32_t aFeatureCount,
michael@0 114 const char** aThreadNameFilters, uint32_t aFilterCount) {}
michael@0 115
michael@0 116 // Stop the profiler and discard the profile. Call 'profiler_save' before this
michael@0 117 // to retrieve the profile.
michael@0 118 static inline void profiler_stop() {}
michael@0 119
michael@0 120 // These functions pause and resume the profiler. While paused the profile will not
michael@0 121 // take any samples and will not record any data into its buffers. The profiler
michael@0 122 // remains fully initialized in this state. Timeline markers will still be stored.
michael@0 123 // This feature will keep javascript profiling enabled, thus allowing toggling the
michael@0 124 // profiler without invalidating the JIT.
michael@0 125 static inline bool profiler_is_paused() { return false; }
michael@0 126 static inline void profiler_pause() {}
michael@0 127 static inline void profiler_resume() {}
michael@0 128
michael@0 129 class ProfilerBacktrace;
michael@0 130
michael@0 131 // Immediately capture the current thread's call stack and return it
michael@0 132 static inline ProfilerBacktrace* profiler_get_backtrace() { return nullptr; }
michael@0 133
michael@0 134 // Free a ProfilerBacktrace returned by profiler_get_backtrace()
michael@0 135 static inline void profiler_free_backtrace(ProfilerBacktrace* aBacktrace) {}
michael@0 136
michael@0 137 static inline bool profiler_is_active() { return false; }
michael@0 138
michael@0 139 // Internal-only. Used by the event tracer.
michael@0 140 static inline void profiler_responsiveness(const mozilla::TimeStamp& aTime) {}
michael@0 141
michael@0 142 // Internal-only. Used by the event tracer.
michael@0 143 static inline double* profiler_get_responsiveness() { return nullptr; }
michael@0 144
michael@0 145 // Internal-only.
michael@0 146 static inline void profiler_set_frame_number(int frameNumber) {}
michael@0 147
michael@0 148 // Get the profile encoded as a JSON string.
michael@0 149 static inline char* profiler_get_profile() { return nullptr; }
michael@0 150
michael@0 151 // Get the profile encoded as a JSON object.
michael@0 152 static inline JSObject* profiler_get_profile_jsobject(JSContext* aCx) { return nullptr; }
michael@0 153
michael@0 154 // Get the profile and write it into a file
michael@0 155 static inline void profiler_save_profile_to_file(char* aFilename) { }
michael@0 156
michael@0 157 // Get the features supported by the profiler that are accepted by profiler_init.
michael@0 158 // Returns a null terminated char* array.
michael@0 159 static inline char** profiler_get_features() { return nullptr; }
michael@0 160
michael@0 161 // Print the current location to the console. This functill will do it best effort
michael@0 162 // to show the profiler's combined js/c++ if the profiler is running. Note that
michael@0 163 // printing the location require symbolicating which is very slow.
michael@0 164 static inline void profiler_print_location() {}
michael@0 165
michael@0 166 // Discard the profile, throw away the profile and notify 'profiler-locked'.
michael@0 167 // This function is to be used when entering private browsing to prevent
michael@0 168 // the profiler from collecting sensitive data.
michael@0 169 static inline void profiler_lock() {}
michael@0 170
michael@0 171 // Re-enable the profiler and notify 'profiler-unlocked'.
michael@0 172 static inline void profiler_unlock() {}
michael@0 173
michael@0 174 static inline void profiler_register_thread(const char* name, void* stackTop) {}
michael@0 175 static inline void profiler_unregister_thread() {}
michael@0 176
michael@0 177 // These functions tell the profiler that a thread went to sleep so that we can avoid
michael@0 178 // sampling it while it's sleeping. Calling profiler_sleep_start() twice without
michael@0 179 // profiler_sleep_end() is an error.
michael@0 180 static inline void profiler_sleep_start() {}
michael@0 181 static inline void profiler_sleep_end() {}
michael@0 182
michael@0 183 // Call by the JSRuntime's operation callback. This is used to enable
michael@0 184 // profiling on auxilerary threads.
michael@0 185 static inline void profiler_js_operation_callback() {}
michael@0 186
michael@0 187 static inline double profiler_time() { return 0; }
michael@0 188 static inline double profiler_time(const mozilla::TimeStamp& aTime) { return 0; }
michael@0 189
michael@0 190 static inline bool profiler_in_privacy_mode() { return false; }
michael@0 191
michael@0 192 #else
michael@0 193
michael@0 194 #include "GeckoProfilerImpl.h"
michael@0 195
michael@0 196 #endif
michael@0 197
michael@0 198 class GeckoProfilerInitRAII {
michael@0 199 public:
michael@0 200 GeckoProfilerInitRAII(void* stackTop) {
michael@0 201 profiler_init(stackTop);
michael@0 202 }
michael@0 203 ~GeckoProfilerInitRAII() {
michael@0 204 profiler_shutdown();
michael@0 205 }
michael@0 206 };
michael@0 207
michael@0 208 class GeckoProfilerSleepRAII {
michael@0 209 public:
michael@0 210 GeckoProfilerSleepRAII() {
michael@0 211 profiler_sleep_start();
michael@0 212 }
michael@0 213 ~GeckoProfilerSleepRAII() {
michael@0 214 profiler_sleep_end();
michael@0 215 }
michael@0 216 };
michael@0 217
michael@0 218 #endif // ifndef SAMPLER_H

mercurial