Skip to content

Commit ffaa912

Browse files
committed
Simpleperf: support build for windows.
Change-Id: I31554f36ee97eb0ae27bda9b77e29410776925e2
1 parent f1b30da commit ffaa912

19 files changed

+175
-180
lines changed

Diff for: simpleperf/Android.mk

+72-111
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616

1717
LOCAL_PATH := $(call my-dir)
1818

19-
simpleperf_common_cppflags := -Wall -Wextra -Werror -Wunused \
19+
simpleperf_common_cppflags := -Wextra -Wunused -Wno-unknown-pragmas
2020

21-
simpleperf_cppflags_target := $(simpleperf_common_cppflags) \
21+
simpleperf_cppflags_target := $(simpleperf_common_cppflags)
2222

2323
simpleperf_cppflags_host := $(simpleperf_common_cppflags) \
2424
-DUSE_BIONIC_UAPI_HEADERS -I bionic/libc/kernel \
2525

26-
simpleperf_cppflags_host_linux := $(simpleperf_cppflags_host) \
26+
simpleperf_cppflags_host_darwin := -I $(LOCAL_PATH)/nonlinux_support/include
27+
simpleperf_cppflags_host_windows := -I $(LOCAL_PATH)/nonlinux_support/include
2728

28-
simpleperf_cppflags_host_darwin := $(simpleperf_cppflags_host) \
29-
-I $(LOCAL_PATH)/darwin_support/include \
3029

3130
LLVM_ROOT_PATH := external/llvm
3231
include $(LLVM_ROOT_PATH)/llvm.mk
@@ -36,15 +35,15 @@ simpleperf_shared_libraries_target := \
3635
libbase \
3736
libLLVM \
3837

39-
simpleperf_shared_libraries_host_linux := \
40-
libbacktrace \
41-
libbase \
38+
simpleperf_shared_libraries_host := libbase
4239

43-
simpleperf_shared_libraries_host_darwin := \
44-
libbase \
45-
libLLVM \
40+
simpleperf_shared_libraries_host_linux := libbacktrace
41+
42+
simpleperf_shared_libraries_host_darwin := libLLVM
4643

47-
simpleperf_ldlibs_host_linux := -lrt \
44+
simpleperf_shared_libraries_host_windows := libLLVM
45+
46+
simpleperf_ldlibs_host_linux := -lrt
4847

4948

5049
# libsimpleperf
@@ -78,58 +77,48 @@ libsimpleperf_src_files_linux := \
7877
workload.cpp \
7978

8079
libsimpleperf_src_files_darwin := \
81-
darwin_support/darwin_support.cpp \
80+
nonlinux_support/nonlinux_support.cpp \
81+
82+
libsimpleperf_src_files_windows := \
83+
nonlinux_support/nonlinux_support.cpp \
8284

8385
# libsimpleperf target
8486
include $(CLEAR_VARS)
8587
LOCAL_CLANG := true
88+
LOCAL_MODULE := libsimpleperf
89+
LOCAL_MODULE_TAGS := debug
90+
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
8691
LOCAL_CPPFLAGS := $(simpleperf_cppflags_target)
8792
LOCAL_SRC_FILES := \
8893
$(libsimpleperf_src_files) \
8994
$(libsimpleperf_src_files_linux) \
9095

9196
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_target)
9297
LOCAL_MULTILIB := first
93-
LOCAL_MODULE := libsimpleperf
94-
LOCAL_MODULE_TAGS := debug
95-
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
9698
include $(LLVM_DEVICE_BUILD_MK)
9799
include $(BUILD_STATIC_LIBRARY)
98100

99-
# libsimpleperf linux host
100-
ifeq ($(HOST_OS),linux)
101+
# libsimpleperf host
101102
include $(CLEAR_VARS)
102-
LOCAL_CLANG := true
103-
LOCAL_CPPFLAGS := $(simpleperf_cppflags_host_linux)
104-
LOCAL_SRC_FILES := \
105-
$(libsimpleperf_src_files) \
106-
$(libsimpleperf_src_files_linux) \
107-
108-
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_host_linux)
109-
LOCAL_LDLIBS := $(simpleperf_ldlibs_host_linux)
110-
LOCAL_MULTILIB := first
103+
#LOCAL_CLANG := true # Comment it to build on windows.
111104
LOCAL_MODULE := libsimpleperf
112-
LOCAL_MODULE_TAGS := optional
113-
include $(LLVM_HOST_BUILD_MK)
114-
include $(BUILD_HOST_STATIC_LIBRARY)
115-
endif
116-
117-
# libsimpleperf darwin host
118-
ifeq ($(HOST_OS),darwin)
119-
include $(CLEAR_VARS)
120-
LOCAL_CLANG := true
121-
LOCAL_CPPFLAGS := $(simpleperf_cppflags_host_darwin)
122-
LOCAL_SRC_FILES := \
123-
$(libsimpleperf_src_files) \
124-
$(libsimpleperf_src_files_darwin) \
125-
126-
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_host_darwin)
105+
LOCAL_MODULE_HOST_OS := darwin linux windows
106+
LOCAL_CPPFLAGS := $(simpleperf_cppflags_host)
107+
LOCAL_CPPFLAGS_darwin := $(simpleperf_cppflags_host_darwin)
108+
LOCAL_CPPFLAGS_linux := $(simpleperf_cppflags_host_linux)
109+
LOCAL_CPPFLAGS_windows := $(simpleperf_cppflags_host_windows)
110+
LOCAL_SRC_FILES := $(libsimpleperf_src_files)
111+
LOCAL_SRC_FILES_darwin := $(libsimpleperf_src_files_darwin)
112+
LOCAL_SRC_FILES_linux := $(libsimpleperf_src_files_linux)
113+
LOCAL_SRC_FILES_windows := $(libsimpleperf_src_files_windows)
114+
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_host)
115+
LOCAL_SHARED_LIBRARIES_darwin := $(simpleperf_shared_libraries_host_darwin)
116+
LOCAL_SHARED_LIBRARIES_linux := $(simpleperf_shared_libraries_host_linux)
117+
LOCAL_SHARED_LIBRARIES_windows := $(simpleperf_shared_libraries_host_windows)
118+
LOCAL_LDLIBS_linux := $(simpleperf_ldlibs_host_linux)
127119
LOCAL_MULTILIB := first
128-
LOCAL_MODULE := libsimpleperf
129-
LOCAL_MODULE_TAGS := optional
130120
include $(LLVM_HOST_BUILD_MK)
131-
include $(BUILD_HOST_SHARED_LIBRARY)
132-
endif
121+
include $(BUILD_HOST_STATIC_LIBRARY)
133122

134123

135124
# simpleperf
@@ -138,46 +127,33 @@ endif
138127
# simpleperf target
139128
include $(CLEAR_VARS)
140129
LOCAL_CLANG := true
130+
LOCAL_MODULE := simpleperf
131+
LOCAL_MODULE_TAGS := debug
132+
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
141133
LOCAL_CPPFLAGS := $(simpleperf_cppflags_target)
142134
LOCAL_SRC_FILES := main.cpp
143135
LOCAL_WHOLE_STATIC_LIBRARIES := libsimpleperf
144136
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_target)
145137
LOCAL_MULTILIB := first
146-
LOCAL_MODULE := simpleperf
147-
LOCAL_MODULE_TAGS := debug
148-
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
149138
include $(BUILD_EXECUTABLE)
150139

151-
# simpleperf linux host
152-
ifeq ($(HOST_OS),linux)
140+
# simpleperf host
153141
include $(CLEAR_VARS)
154-
LOCAL_CLANG := true
155-
LOCAL_CPPFLAGS := $(simpleperf_cppflags_host_linux)
156-
LOCAL_SRC_FILES := main.cpp
157-
LOCAL_WHOLE_STATIC_LIBRARIES := libsimpleperf
158-
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_host_linux)
159-
LOCAL_MULTILIB := first
160-
LOCAL_LDLIBS := $(simpleperf_ldlibs_host_linux)
161142
LOCAL_MODULE := simpleperf
162-
LOCAL_MODULE_TAGS := optional
163-
include $(BUILD_HOST_EXECUTABLE)
164-
endif
165-
166-
# simpleperf darwin host
167-
ifeq ($(HOST_OS),darwin)
168-
include $(CLEAR_VARS)
169-
LOCAL_CLANG := true
170-
LOCAL_CPPFLAGS := $(simpleperf_cppflags_host_darwin)
143+
LOCAL_MODULE_HOST_OS := darwin linux windows
144+
LOCAL_CPPFLAGS := $(simpleperf_cppflags_host)
145+
LOCAL_CPPFLAGS_darwin := $(simpleperf_cppflags_host_darwin)
146+
LOCAL_CPPFLAGS_linux := $(simpleperf_cppflags_host_linux)
147+
LOCAL_CPPFLAGS_windows := $(simpleperf_cppflags_host_windows)
171148
LOCAL_SRC_FILES := main.cpp
172-
LOCAL_SHARED_LIBRARIES := \
173-
libsimpleperf \
174-
$(simpleperf_shared_libraries_host_darwin) \
175-
149+
LOCAL_WHOLE_STATIC_LIBRARIES := libsimpleperf
150+
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_host)
151+
LOCAL_SHARED_LIBRARIES_darwin := $(simpleperf_shared_libraries_host_darwin)
152+
LOCAL_SHARED_LIBRARIES_linux := $(simpleperf_shared_libraries_host_linux)
153+
LOCAL_SHARED_LIBRARIES_windows := $(simpleperf_shared_libraries_host_windows)
154+
LOCAL_LDLIBS_linux := $(simpleperf_ldlibs_host_linux)
176155
LOCAL_MULTILIB := first
177-
LOCAL_MODULE := simpleperf
178-
LOCAL_MODULE_TAGS := optional
179156
include $(BUILD_HOST_EXECUTABLE)
180-
endif
181157

182158

183159
# simpleperf_unit_test
@@ -202,6 +178,7 @@ simpleperf_unit_test_src_files_linux := \
202178
# simpleperf_unit_test target
203179
include $(CLEAR_VARS)
204180
LOCAL_CLANG := true
181+
LOCAL_MODULE := simpleperf_unit_test
205182
LOCAL_CPPFLAGS := $(simpleperf_cppflags_target)
206183
LOCAL_SRC_FILES := \
207184
$(simpleperf_unit_test_src_files) \
@@ -210,42 +187,26 @@ LOCAL_SRC_FILES := \
210187
LOCAL_WHOLE_STATIC_LIBRARIES := libsimpleperf
211188
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_target)
212189
LOCAL_MULTILIB := first
213-
LOCAL_MODULE := simpleperf_unit_test
214-
LOCAL_MODULE_TAGS := optional
215190
include $(BUILD_NATIVE_TEST)
216191

217-
# simpleperf_unit_test linux host
218-
ifeq ($(HOST_OS),linux)
192+
# simpleperf_unit_test host
219193
include $(CLEAR_VARS)
220-
LOCAL_CLANG := true
221-
LOCAL_CPPFLAGS := $(simpleperf_cppflags_host_linux)
222-
LOCAL_SRC_FILES := \
223-
$(simpleperf_unit_test_src_files) \
224-
$(simpleperf_unit_test_src_files_linux) \
225-
226-
LOCAL_WHOLE_STATIC_LIBRARIES := libsimpleperf
227-
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_host_linux)
228-
LOCAL_MULTILIB := first
229194
LOCAL_MODULE := simpleperf_unit_test
230-
LOCAL_MODULE_TAGS := optional
231-
include $(BUILD_HOST_NATIVE_TEST)
232-
endif
233-
234-
# simpleperf_unit_test darwin host
235-
ifeq ($(HOST_OS),darwin)
236-
include $(CLEAR_VARS)
237-
LOCAL_CLANG := true
238-
LOCAL_CPPFLAGS := $(simpleperf_cppflags_host_darwin)
195+
LOCAL_MODULE_HOST_OS := darwin linux windows
196+
LOCAL_CPPFLAGS := $(simpleperf_cppflags_host)
197+
LOCAL_CPPFLAGS_darwin := $(simpleperf_cppflags_host_darwin)
198+
LOCAL_CPPFLAGS_linux := $(simpleperf_cppflags_host_linux)
199+
LOCAL_CPPFLAGS_windows := $(simpleperf_cppflags_host_windows)
239200
LOCAL_SRC_FILES := $(simpleperf_unit_test_src_files)
240-
LOCAL_SHARED_LIBRARIES := \
241-
libsimpleperf \
242-
$(simpleperf_shared_libraries_host_darwin) \
243-
201+
LOCAL_SRC_FILES_linux := $(simpleperf_unit_test_src_files_linux)
202+
LOCAL_WHOLE_STATIC_LIBRARIES := libsimpleperf
203+
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_host)
204+
LOCAL_SHARED_LIBRARIES_darwin := $(simpleperf_shared_libraries_host_darwin)
205+
LOCAL_SHARED_LIBRARIES_linux := $(simpleperf_shared_libraries_host_linux)
206+
LOCAL_SHARED_LIBRARIES_windows := $(simpleperf_shared_libraries_host_windows)
207+
LOCAL_LDLIBS_linux := $(simpleperf_ldlibs_host_linux)
244208
LOCAL_MULTILIB := first
245-
LOCAL_MODULE := simpleperf_unit_test
246-
LOCAL_MODULE_TAGS := optional
247209
include $(BUILD_HOST_NATIVE_TEST)
248-
endif
249210

250211

251212
# simpleperf_cpu_hotplug_test
@@ -257,27 +218,27 @@ simpleperf_cpu_hotplug_test_src_files := \
257218
# simpleperf_cpu_hotplug_test target
258219
include $(CLEAR_VARS)
259220
LOCAL_CLANG := true
221+
LOCAL_MODULE := simpleperf_cpu_hotplug_test
260222
LOCAL_CPPFLAGS := $(simpleperf_cppflags_target)
261223
LOCAL_SRC_FILES := $(simpleperf_cpu_hotplug_test_src_files)
262224
LOCAL_WHOLE_STATIC_LIBRARIES := libsimpleperf
263225
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_target)
264226
LOCAL_MULTILIB := first
265-
LOCAL_MODULE := simpleperf_cpu_hotplug_test
266-
LOCAL_MODULE_TAGS := optional
267227
include $(BUILD_NATIVE_TEST)
268228

269229
# simpleperf_cpu_hotplug_test linux host
270-
ifeq ($(HOST_OS),linux)
271230
include $(CLEAR_VARS)
272231
LOCAL_CLANG := true
273-
LOCAL_CPPFLAGS := $(simpleperf_cppflags_host_linux)
232+
LOCAL_MODULE := simpleperf_cpu_hotplug_test
233+
LOCAL_MODULE_HOST_OS := linux
234+
LOCAL_CPPFLAGS := $(simpleperf_cppflags_host)
235+
LOCAL_CPPFLAGS_linux := $(simpleperf_cppflags_host_linux)
274236
LOCAL_SRC_FILES := $(simpleperf_cpu_hotplug_test_src_files)
275237
LOCAL_WHOLE_STATIC_LIBRARIES := libsimpleperf
276-
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_host_linux)
238+
LOCAL_SHARED_LIBRARIES := $(simpleperf_shared_libraries_host)
239+
LOCAL_SHARED_LIBRARIES_linux := $(simpleperf_shared_libraries_host_linux)
240+
LOCAL_LDLIBS_linux := $(simpleperf_ldlibs_host_linux)
277241
LOCAL_MULTILIB := first
278-
LOCAL_MODULE := simpleperf_cpu_hotplug_test
279-
LOCAL_MODULE_TAGS := optional
280242
include $(BUILD_HOST_NATIVE_TEST)
281-
endif
282243

283244
include $(call first-makefiles-under,$(LOCAL_PATH))

Diff for: simpleperf/cmd_record.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "read_elf.h"
3636
#include "record.h"
3737
#include "record_file.h"
38+
#include "scoped_signal_handler.h"
3839
#include "thread_tree.h"
3940
#include "utils.h"
4041
#include "workload.h"
@@ -123,8 +124,8 @@ class RecordCommand : public Command {
123124
perf_mmap_pages_(256),
124125
record_filename_("perf.data") {
125126
signaled = false;
126-
signal_handler_register_.reset(
127-
new SignalHandlerRegister({SIGCHLD, SIGINT, SIGTERM}, signal_handler));
127+
scoped_signal_handler_.reset(
128+
new ScopedSignalHandler({SIGCHLD, SIGINT, SIGTERM}, signal_handler));
128129
}
129130

130131
bool Run(const std::vector<std::string>& args);
@@ -175,7 +176,7 @@ class RecordCommand : public Command {
175176
std::set<std::string> hit_kernel_modules_;
176177
std::set<std::string> hit_user_files_;
177178

178-
std::unique_ptr<SignalHandlerRegister> signal_handler_register_;
179+
std::unique_ptr<ScopedSignalHandler> scoped_signal_handler_;
179180
};
180181

181182
bool RecordCommand::Run(const std::vector<std::string>& args) {

Diff for: simpleperf/cmd_stat.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "event_fd.h"
3535
#include "event_selection_set.h"
3636
#include "event_type.h"
37+
#include "scoped_signal_handler.h"
3738
#include "utils.h"
3839
#include "workload.h"
3940

@@ -75,8 +76,8 @@ class StatCommand : public Command {
7576
system_wide_collection_(false),
7677
child_inherit_(true) {
7778
signaled = false;
78-
signal_handler_register_.reset(
79-
new SignalHandlerRegister({SIGCHLD, SIGINT, SIGTERM}, signal_handler));
79+
scoped_signal_handler_.reset(
80+
new ScopedSignalHandler({SIGCHLD, SIGINT, SIGTERM}, signal_handler));
8081
}
8182

8283
bool Run(const std::vector<std::string>& args);
@@ -96,7 +97,7 @@ class StatCommand : public Command {
9697
std::vector<EventTypeAndModifier> measured_event_types_;
9798
EventSelectionSet event_selection_set_;
9899

99-
std::unique_ptr<SignalHandlerRegister> signal_handler_register_;
100+
std::unique_ptr<ScopedSignalHandler> scoped_signal_handler_;
100101
};
101102

102103
bool StatCommand::Run(const std::vector<std::string>& args) {

Diff for: simpleperf/environment.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,33 @@
3333
#include "read_elf.h"
3434
#include "utils.h"
3535

36+
class LineReader {
37+
public:
38+
LineReader(FILE* fp) : fp_(fp), buf_(nullptr), bufsize_(0) {
39+
}
40+
41+
~LineReader() {
42+
free(buf_);
43+
fclose(fp_);
44+
}
45+
46+
char* ReadLine() {
47+
if (getline(&buf_, &bufsize_, fp_) != -1) {
48+
return buf_;
49+
}
50+
return nullptr;
51+
}
52+
53+
size_t MaxLineSize() {
54+
return bufsize_;
55+
}
56+
57+
private:
58+
FILE* fp_;
59+
char* buf_;
60+
size_t bufsize_;
61+
};
62+
3663
std::vector<int> GetOnlineCpus() {
3764
std::vector<int> result;
3865
FILE* fp = fopen("/sys/devices/system/cpu/online", "re");

Diff for: simpleperf/event_type.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <android-base/logging.h>
2626

2727
#include "event_attr.h"
28-
#include "event_fd.h"
2928
#include "utils.h"
3029

3130
#define EVENT_TYPE_TABLE_ENTRY(name, type, config) {name, type, config},

0 commit comments

Comments
 (0)