1 // © 2019 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 #include "unicode/utypes.h"
18 ResourceTracer::~ResourceTracer() = default;
20 void ResourceTracer::trace(const char* resType
) const {
21 U_ASSERT(fResB
|| fParent
);
22 UTRACE_ENTRY(UTRACE_UDATA_RESOURCE
);
23 UErrorCode status
= U_ZERO_ERROR
;
26 getFilePath(filePath
, status
);
29 getResPath(resPath
, status
);
31 // The longest type ("intvector") is 9 chars
32 const char kSpaces
[] = " ";
34 format
.append(kSpaces
, sizeof(kSpaces
) - 1 - uprv_strlen(resType
), status
);
35 format
.append("(%s) %s @ %s", status
);
37 UTRACE_DATA3(UTRACE_VERBOSE
,
42 UTRACE_EXIT_STATUS(status
);
45 void ResourceTracer::traceOpen() const {
47 UTRACE_ENTRY(UTRACE_UDATA_BUNDLE
);
48 UErrorCode status
= U_ZERO_ERROR
;
51 UTRACE_DATA1(UTRACE_VERBOSE
, "%s", getFilePath(filePath
, status
).data());
52 UTRACE_EXIT_STATUS(status
);
55 CharString
& ResourceTracer::getFilePath(CharString
& output
, UErrorCode
& status
) const {
57 output
.append(fResB
->fData
->fPath
, status
);
58 output
.append('/', status
);
59 output
.append(fResB
->fData
->fName
, status
);
60 output
.append(".res", status
);
62 fParent
->getFilePath(output
, status
);
67 CharString
& ResourceTracer::getResPath(CharString
& output
, UErrorCode
& status
) const {
69 output
.append('/', status
);
70 output
.append(fResB
->fResPath
, status
);
71 // removing the trailing /
72 U_ASSERT(output
[output
.length()-1] == '/');
73 output
.truncate(output
.length()-1);
75 fParent
->getResPath(output
, status
);
78 output
.append('/', status
);
79 output
.append(fKey
, status
);
82 output
.append('[', status
);
83 UnicodeString indexString
;
84 ICU_Utility::appendNumber(indexString
, fIndex
);
85 output
.appendInvariantChars(indexString
, status
);
86 output
.append(']', status
);
91 void FileTracer::traceOpen(const char* path
, const char* type
, const char* name
) {
92 if (uprv_strcmp(type
, "res") == 0) {
93 traceOpenResFile(path
, name
);
95 traceOpenDataFile(path
, type
, name
);
99 void FileTracer::traceOpenDataFile(const char* path
, const char* type
, const char* name
) {
100 UTRACE_ENTRY(UTRACE_UDATA_DATA_FILE
);
101 UErrorCode status
= U_ZERO_ERROR
;
104 filePath
.append(path
, status
);
105 filePath
.append('/', status
);
106 filePath
.append(name
, status
);
107 filePath
.append('.', status
);
108 filePath
.append(type
, status
);
110 UTRACE_DATA1(UTRACE_VERBOSE
, "%s", filePath
.data());
111 UTRACE_EXIT_STATUS(status
);
114 void FileTracer::traceOpenResFile(const char* path
, const char* name
) {
115 UTRACE_ENTRY(UTRACE_UDATA_RES_FILE
);
116 UErrorCode status
= U_ZERO_ERROR
;
119 filePath
.append(path
, status
);
120 filePath
.append('/', status
);
121 filePath
.append(name
, status
);
122 filePath
.append(".res", status
);
124 UTRACE_DATA1(UTRACE_VERBOSE
, "%s", filePath
.data());
125 UTRACE_EXIT_STATUS(status
);
130 #endif // U_ENABLE_TRACING