Line data Source code
1 : // Copyright (c) 2006-2011 The Chromium Authors. All rights reserved.
2 : //
3 : // Redistribution and use in source and binary forms, with or without
4 : // modification, are permitted provided that the following conditions
5 : // are met:
6 : // * Redistributions of source code must retain the above copyright
7 : // notice, this list of conditions and the following disclaimer.
8 : // * Redistributions in binary form must reproduce the above copyright
9 : // notice, this list of conditions and the following disclaimer in
10 : // the documentation and/or other materials provided with the
11 : // distribution.
12 : // * Neither the name of Google, Inc. nor the names of its contributors
13 : // may be used to endorse or promote products derived from this
14 : // software without specific prior written permission.
15 : //
16 : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 : // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 : // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 : // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 : // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21 : // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 : // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23 : // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 : // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 : // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 : // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 : // SUCH DAMAGE.
28 :
29 : #ifndef TOOLS_PLATFORM_H_
30 : #define TOOLS_PLATFORM_H_
31 :
32 : #include <stdint.h>
33 : #include <math.h>
34 : #include "MainThreadUtils.h"
35 : #include "ThreadResponsiveness.h"
36 : #include "mozilla/Logging.h"
37 : #include "mozilla/MemoryReporting.h"
38 : #include "mozilla/StaticMutex.h"
39 : #include "mozilla/TimeStamp.h"
40 : #include "mozilla/UniquePtr.h"
41 : #include "mozilla/Unused.h"
42 : #include "PlatformMacros.h"
43 : #include <vector>
44 : #include "StackTop.h"
45 :
46 : // We need a definition of gettid(), but glibc doesn't provide a
47 : // wrapper for it.
48 : #if defined(__GLIBC__)
49 : #include <unistd.h>
50 : #include <sys/syscall.h>
51 151 : static inline pid_t gettid()
52 : {
53 151 : return (pid_t) syscall(SYS_gettid);
54 : }
55 : #elif defined(GP_OS_darwin)
56 : #include <unistd.h>
57 : #include <sys/syscall.h>
58 : static inline pid_t gettid()
59 : {
60 : return (pid_t) syscall(SYS_thread_selfid);
61 : }
62 : #elif defined(GP_OS_android)
63 : #include <unistd.h>
64 : #elif defined(GP_OS_windows)
65 : #include <windows.h>
66 : #include <process.h>
67 : #ifndef getpid
68 : #define getpid _getpid
69 : #endif
70 : #endif
71 :
72 : extern mozilla::LazyLogModule gProfilerLog;
73 :
74 : // These are for MOZ_LOG="prof:3" or higher. It's the default logging level for
75 : // the profiler, and should be used sparingly.
76 : #define LOG_TEST \
77 : MOZ_LOG_TEST(gProfilerLog, mozilla::LogLevel::Info)
78 : #define LOG(arg, ...) \
79 : MOZ_LOG(gProfilerLog, mozilla::LogLevel::Info, \
80 : ("[%d] " arg, getpid(), ##__VA_ARGS__))
81 :
82 : // These are for MOZ_LOG="prof:4" or higher. It should be used for logging that
83 : // is somewhat more verbose than LOG.
84 : #define DEBUG_LOG_TEST \
85 : MOZ_LOG_TEST(gProfilerLog, mozilla::LogLevel::Debug)
86 : #define DEBUG_LOG(arg, ...) \
87 : MOZ_LOG(gProfilerLog, mozilla::LogLevel::Debug, \
88 : ("[%d] " arg, getpid(), ##__VA_ARGS__))
89 :
90 : typedef uint8_t* Address;
91 :
92 : // ----------------------------------------------------------------------------
93 : // Thread
94 : //
95 : // This class has static methods for the different platform specific
96 : // functions. Add methods here to cope with differences between the
97 : // supported platforms.
98 :
99 : class Thread {
100 : public:
101 : #if defined(GP_OS_windows)
102 : typedef DWORD tid_t;
103 : #else
104 : typedef ::pid_t tid_t;
105 : #endif
106 :
107 : static tid_t GetCurrentId();
108 : };
109 :
110 : // ----------------------------------------------------------------------------
111 : // Miscellaneous
112 :
113 : class PlatformData;
114 :
115 : // We can't new/delete the type safely without defining it
116 : // (-Wdelete-incomplete). Use these to hide the details from clients.
117 : struct PlatformDataDestructor {
118 : void operator()(PlatformData*);
119 : };
120 :
121 : typedef mozilla::UniquePtr<PlatformData, PlatformDataDestructor>
122 : UniquePlatformData;
123 : UniquePlatformData AllocPlatformData(int aThreadId);
124 :
125 : namespace mozilla {
126 : class JSONWriter;
127 : }
128 : void AppendSharedLibraries(mozilla::JSONWriter& aWriter);
129 :
130 : #endif /* ndef TOOLS_PLATFORM_H_ */
|