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 "src/trace_processor/importers/art_method/art_method_parser_impl.h"
18
19 #include <cstdint>
20
21 #include "src/trace_processor/importers/art_method/art_method_event.h"
22 #include "src/trace_processor/importers/common/args_tracker.h"
23 #include "src/trace_processor/importers/common/process_tracker.h"
24 #include "src/trace_processor/importers/common/slice_tracker.h"
25 #include "src/trace_processor/importers/common/stack_profile_tracker.h"
26 #include "src/trace_processor/importers/common/track_tracker.h"
27 #include "src/trace_processor/storage/trace_storage.h"
28 #include "src/trace_processor/types/trace_processor_context.h"
29 #include "src/trace_processor/types/variadic.h"
30
31 namespace perfetto::trace_processor::art_method {
32
ArtMethodParserImpl(TraceProcessorContext * context)33 ArtMethodParserImpl::ArtMethodParserImpl(TraceProcessorContext* context)
34 : context_(context),
35 pathname_id_(context->storage->InternString("pathname")),
36 line_number_id_(context->storage->InternString("line_number")) {}
37
38 ArtMethodParserImpl::~ArtMethodParserImpl() = default;
39
ParseArtMethodEvent(int64_t ts,ArtMethodEvent e)40 void ArtMethodParserImpl::ParseArtMethodEvent(int64_t ts, ArtMethodEvent e) {
41 UniqueTid utid = context_->process_tracker->GetOrCreateThread(e.tid);
42 if (e.comm) {
43 context_->process_tracker->UpdateThreadNameAndMaybeProcessName(
44 e.tid, *e.comm, ThreadNamePriority::kOther);
45 }
46 TrackId track_id = context_->track_tracker->InternThreadTrack(utid);
47 switch (e.action) {
48 case ArtMethodEvent::kEnter:
49 context_->slice_tracker->Begin(
50 ts, track_id, kNullStringId, e.method,
51 [this, &e](ArgsTracker::BoundInserter* i) {
52 if (e.pathname) {
53 i->AddArg(pathname_id_, Variadic::String(*e.pathname));
54 }
55 if (e.line_number) {
56 i->AddArg(line_number_id_, Variadic::Integer(*e.line_number));
57 }
58 });
59 break;
60 case ArtMethodEvent::kExit:
61 context_->slice_tracker->End(ts, track_id);
62 break;
63 }
64 }
65
66 } // namespace perfetto::trace_processor::art_method
67