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 StartTrace(HITRACE_TAG_ZIMAGE, title);
26 }
27
~ImageTrace()28 ImageTrace::~ImageTrace()
29 {
30 FinishTrace(HITRACE_TAG_ZIMAGE);
31 }
32
ImageTrace(const char * fmt,...)33 ImageTrace::ImageTrace(const char *fmt, ...)
34 {
35 if (fmt == nullptr) {
36 title_ = "ImageTraceFmt Param invalid";
37 } else {
38 char buf[FORMAT_BUF_SIZE] = { 0 };
39 va_list args;
40 va_start(args, fmt);
41 int32_t ret = vsprintf_s(buf, FORMAT_BUF_SIZE, fmt, args);
42 va_end(args);
43 if (ret != -1) {
44 title_ = buf;
45 } else {
46 title_ = "ImageTraceFmt Format Error";
47 }
48 }
49 StartTrace(HITRACE_TAG_ZIMAGE, title_);
50 }
51 } // namespace Media
52 } // namespace OHOS
53