1 # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # Support for tracing what gbuild does.
11 # Run 'make GBUILD_TRACE=/somewhere/log.json', process the file
12 # using solenv/bin/finish-gbuild-trace.py, and then view it in Chromium
13 # using the chrome://tracing URL:
14 # - the '?' icon in the top-right is the help
15 # - 'gbuild' rows represent per-parallelism (per-CPU) usage in time
16 # - 'totals' rows represent sums for reach build type
17 # - note that 'EXTERNAL' targets do not detect whether the external package
18 # is built with parallelism or not, so the actual CPU time may be higher
19 # - vertical lines represent targets that themselves do not take any time
21 # - any target can be found using the search field in the top right corner
22 # (just type e.g. '[MOD]: sal' and hit the '->' button, if you cannot see
23 # it pressing 'm' or 'f' can help)
26 ifneq ($(GBUILD_TRACE
),)
27 gb_TRACE
:= $(abspath
$(GBUILD_TRACE
))
31 # macOS date doesn't know about nanoseconds switch, and instead of resorting to perl or python
32 # to create a millisecond timestamp, just avoid the overhead and live with seconds-only accuracy
33 gb_Trace_Timestamp
:= $(if
$(filter MACOSX
,$(OS
)),$$(date
+%s
)000000000,$(date
+%s
%N
))
34 # macOS also doesn't provide flock, so skip that part on mac
35 # The (flock;cat) part is to minimize lock time.
36 gb_Trace_Flock
:= $(if
$(filter MACOSX
,$(OS
)),,|
( flock
1; cat
))
37 # call gb_Trace_AddMark,marktype,detail,type,extra
38 define gb_Trace__AddMark
39 echo
"{\"name\": \"$(3)\", \"ph\": \"$(1)\", \"pid\": 1, \"tid\": 1, \"ts\": $(gb_Trace_Timestamp),\"args\":{\"message\":\"[$(3)]: $(2)\"}}," $(gb_Trace_Flock
) >>$(gb_TRACE
)
42 # call gb_Trace_StartRange,detail,type
43 define gb_Trace_StartRange
44 $(call gb_Trace__AddMark
,B
,$(1),$(2))
47 # call gb_Trace_EndRange,detail,type
48 define gb_Trace_EndRange
49 $(call gb_Trace__AddMark
,E
,$(1),$(2))
52 # call gb_Trace_MakeMark,detail,type
53 define gb_Trace_MakeMark
54 $(call gb_Trace__AddMark
,i
,$(1),$(2))
57 ifeq ($(MAKE_RESTARTS
),)
58 $(shell rm -f
$(gb_TRACE
) 2>/dev
/null
)
60 $(shell $(call gb_Trace__AddMark
,i
,make restart
,MAKE
))
65 # vim: set noet sw=4 ts=4: