Coverage Report

Created: 2026-05-24 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/perfetto/include/perfetto/base/proc_utils.h
Line
Count
Source
1
/*
2
 * Copyright (C) 2019 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_BASE_PROC_UTILS_H_
18
#define INCLUDE_PERFETTO_BASE_PROC_UTILS_H_
19
20
#include <stdint.h>
21
22
#include "perfetto/base/build_config.h"
23
24
#if PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
25
extern "C" {
26
// Prototype extracted from the Windows SDK to avoid including windows.h.
27
__declspec(dllimport) unsigned long __stdcall GetCurrentProcessId();
28
}
29
#elif PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA)
30
#include <zircon/process.h>
31
#include <zircon/types.h>
32
#else
33
#include <unistd.h>
34
#endif
35
36
namespace perfetto {
37
namespace base {
38
39
#if PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA)
40
using PlatformProcessId = zx_handle_t;
41
inline PlatformProcessId GetProcessId() {
42
  return zx_process_self();
43
}
44
#elif PERFETTO_BUILDFLAG(PERFETTO_OS_WIN)
45
using PlatformProcessId = uint64_t;
46
inline PlatformProcessId GetProcessId() {
47
  return static_cast<uint64_t>(GetCurrentProcessId());
48
}
49
#else
50
using PlatformProcessId = pid_t;
51
423
inline PlatformProcessId GetProcessId() {
52
423
  return getpid();
53
423
}
54
#endif
55
56
}  // namespace base
57
}  // namespace perfetto
58
59
#endif  // INCLUDE_PERFETTO_BASE_PROC_UTILS_H_