• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #ifndef INCLUDE_PERFETTO_EXT_TRACING_CORE_CLIENT_IDENTITY_H_
18 #define INCLUDE_PERFETTO_EXT_TRACING_CORE_CLIENT_IDENTITY_H_
19 
20 #include "perfetto/ext/base/sys_types.h"
21 #include "perfetto/ext/tracing/core/basic_types.h"
22 
23 namespace perfetto {
24 
25 // This class groups data fields of a connected client that can get passed in
26 // the tracing core to be emitted to trace packets.
27 class ClientIdentity {
28  public:
29   ClientIdentity() = default;
30   ClientIdentity(uid_t uid, pid_t pid, MachineID machine_id = kDefaultMachineID)
uid_(uid)31       : uid_(uid), pid_(pid), machine_id_(machine_id) {}
32 
has_uid()33   bool has_uid() const { return uid_ != base::kInvalidUid; }
uid()34   uid_t uid() const { return uid_; }
35 
has_pid()36   bool has_pid() const { return pid_ != base::kInvalidPid; }
pid()37   pid_t pid() const { return pid_; }
38 
has_non_default_machine_id()39   bool has_non_default_machine_id() const {
40     return machine_id_ != kDefaultMachineID;
41   }
machine_id()42   base::MachineID machine_id() const { return machine_id_; }
43 
44  private:
45   uid_t uid_ = base::kInvalidUid;
46   pid_t pid_ = base::kInvalidPid;
47   MachineID machine_id_ = kDefaultMachineID;
48 };
49 }  // namespace perfetto
50 
51 #endif  // INCLUDE_PERFETTO_EXT_TRACING_CORE_CLIENT_IDENTITY_H_
52