Coverage Report

Created: 2024-11-21 13:41

/root/doris/be/src/util/os_util.h
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
// This file is copied from
18
// https://github.com/apache/impala/blob/branch-2.9.0/be/src/util/os-util.h
19
// and modified by Doris
20
21
#pragma once
22
23
#include <cstdint>
24
#include <string>
25
26
#include "common/status.h"
27
28
namespace doris {
29
30
// Utility methods to read interesting values from /proc.
31
// TODO: Get stats for parent process.
32
33
// Container struct for statistics read from the /proc filesystem for a thread.
34
struct ThreadStats {
35
    int64_t user_ns;
36
    int64_t kernel_ns;
37
    int64_t iowait_ns;
38
39
    // Default constructor zeroes all members in case structure can't be filled by
40
    // GetThreadStats.
41
0
    ThreadStats() : user_ns(0), kernel_ns(0), iowait_ns(0) {}
42
};
43
44
// Populates ThreadStats object using a given buffer. The buffer is expected to
45
// conform to /proc/<pid>/task/<tid>/stat layout; an error will be returned otherwise.
46
//
47
// If 'name' is supplied, the extracted thread name will be written to it.
48
Status parse_stat(const std::string& buffer, std::string* name, ThreadStats* stats);
49
50
// Populates ThreadStats object for a given thread by reading from
51
// /proc/<pid>/task/<tid>/stat. Returns OK unless the file cannot be read or is in an
52
// unrecognised format, or if the kernel version is not modern enough.
53
Status get_thread_stats(int64_t tid, ThreadStats* stats);
54
55
// Disable core dumps for this process.
56
//
57
// This is useful particularly in tests where we have injected failures and don't
58
// want to generate a core dump from an "expected" crash.
59
void disable_core_dumps();
60
61
} // namespace doris