Avoid potential negative array index access to cached text.
[LibreOffice.git] / solenv / gbuild / Trace.mk
bloba92f842e1dec45afb266cd124ffd2641fe7fa2d6
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
20 # to build
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)
25 gb_TRACE :=
26 ifneq ($(GBUILD_TRACE),)
27 gb_TRACE := $(abspath $(GBUILD_TRACE))
28 ifeq ($(OS),WNT)
29 # abspath turns it into a windows-style path, but the build needs unix-style
30 gb_TRACE := $(shell cygpath -u $(gb_TRACE))
31 endif
32 endif
34 ifneq ($(gb_TRACE),)
35 # macOS date doesn't know about nanoseconds switch, and instead of resorting to perl or python
36 # to create a millisecond timestamp, just avoid the overhead and live with seconds-only accuracy
37 gb_Trace_Timestamp := $(if $(filter MACOSX,$(OS)),$$(date +%s)000000000,$$(date +%s%N))
38 # macOS also doesn't provide flock, so skip that part on mac
39 # The (flock;cat) part is to minimize lock time.
40 gb_Trace_Flock := $(if $(filter MACOSX,$(OS)),,| ( flock 1; cat ))
41 # call gb_Trace_AddMark,marktype,detail,type,extra
42 define gb_Trace__AddMark
43 echo "{\"name\": \"$(3)\", \"ph\": \"$(1)\", \"pid\": 1, \"tid\": 1, \"ts\": $(gb_Trace_Timestamp),\"args\":{\"message\":\"[$(3)]: $(2)\"}}," $(gb_Trace_Flock) >>$(gb_TRACE)
44 endef
46 # call gb_Trace_StartRange,detail,type
47 define gb_Trace_StartRange
48 $(call gb_Trace__AddMark,B,$(1),$(2))
49 endef
51 # call gb_Trace_EndRange,detail,type
52 define gb_Trace_EndRange
53 $(call gb_Trace__AddMark,E,$(1),$(2))
54 endef
56 # call gb_Trace_MakeMark,detail,type
57 define gb_Trace_MakeMark
58 $(call gb_Trace__AddMark,i,$(1),$(2))
59 endef
61 ifeq ($(MAKE_RESTARTS),)
62 $(shell rm -f $(gb_TRACE) 2>/dev/null)
63 else
64 $(shell $(call gb_Trace__AddMark,i,make restart,MAKE))
65 endif
67 endif
69 # vim: set noet sw=4 ts=4: