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 #include <Windows.h> 26 #include <processthreadsapi.h> 27 #elif PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA) 28 #include <zircon/process.h> 29 #include <zircon/types.h> 30 #else 31 #include <unistd.h> 32 #endif 33 34 namespace perfetto { 35 namespace base { 36 37 #if PERFETTO_BUILDFLAG(PERFETTO_OS_FUCHSIA) 38 using PlatformProcessId = zx_handle_t; GetProcessId()39inline PlatformProcessId GetProcessId() { 40 return zx_process_self(); 41 } 42 #elif PERFETTO_BUILDFLAG(PERFETTO_OS_WIN) 43 using PlatformProcessId = uint64_t; 44 inline PlatformProcessId GetProcessId() { 45 return static_cast<uint64_t>(GetCurrentProcessId()); 46 } 47 #else 48 using PlatformProcessId = pid_t; 49 inline PlatformProcessId GetProcessId() { 50 return getpid(); 51 } 52 #endif 53 54 } // namespace base 55 } // namespace perfetto 56 57 #endif // INCLUDE_PERFETTO_BASE_PROC_UTILS_H_ 58