xref: /aosp_15_r20/system/chre/platform/shared/tokenized_log.cc (revision 84e339476a462649f82315436d70fd732297a399)
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "chre/platform/shared/nanoapp/tokenized_log.h"
18 #include "chre/core/event_loop_manager.h"
19 #include "chre/platform/log.h"
20 #include "chre/platform/shared/log_buffer_manager.h"
21 #include "chre_api/chre/re.h"
22 
23 #include "pw_log_tokenized/config.h"
24 #include "pw_tokenizer/encode_args.h"
25 #include "pw_tokenizer/tokenize.h"
26 
platform_chrePwTokenizedLog(enum chreLogLevel level,uint32_t token,uint64_t types,...)27 void platform_chrePwTokenizedLog(enum chreLogLevel level, uint32_t token,
28                                  uint64_t types, ...) {
29   va_list args;
30   va_start(args, types);
31   pw::tokenizer::EncodedMessage<pw::log_tokenized::kEncodingBufferSizeBytes>
32       encodedMessage(token, types, args);
33   va_end(args);
34 
35   chre::LogBufferManagerSingleton::get()->logNanoappTokenized(
36       level,
37       chre::EventLoopManagerSingleton::get()
38           ->getEventLoop()
39           .getCurrentNanoapp()
40           ->getInstanceId(),
41       encodedMessage.data_as_uint8(), encodedMessage.size());
42 }
43