1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "image_trace.h"
16 #include "hitrace_meter.h"
17 #include "securec.h"
18
19 namespace OHOS {
20 namespace Media {
21 static constexpr int32_t FORMAT_BUF_SIZE = 128;
22
ImageTrace(const std::string & title)23 ImageTrace::ImageTrace(const std::string &title) : title_(title)
24 {
25 #if !defined(_WIN32) && !defined(_APPLE)
26 StartTrace(HITRACE_TAG_ZIMAGE, title);
27 #endif
28 }
29
~ImageTrace()30 ImageTrace::~ImageTrace()
31 {
32 #if !defined(_WIN32) && !defined(_APPLE)
33 FinishTrace(HITRACE_TAG_ZIMAGE);
34 #endif
35 }
36
ImageTrace(const char * fmt,...)37 ImageTrace::ImageTrace(const char *fmt, ...)
38 {
39 #if !defined(_WIN32) && !defined(_APPLE)
40 if (fmt == nullptr) {
41 title_ = "ImageTraceFmt Param invalid";
42 } else {
43 char buf[FORMAT_BUF_SIZE] = { 0 };
44 va_list args;
45 va_start(args, fmt);
46 int32_t ret = vsprintf_s(buf, FORMAT_BUF_SIZE, fmt, args);
47 va_end(args);
48 if (ret != -1) {
49 title_ = buf;
50 } else {
51 title_ = "ImageTraceFmt Format Error";
52 }
53 }
54 StartTrace(HITRACE_TAG_ZIMAGE, title_);
55 #endif
56 }
57 } // namespace Media
58 } // namespace OHOS
59