代码之家  ›  专栏  ›  技术社区  ›  afsantos

如何检测函数是否执行IO操作?

  •  0
  • afsantos  · 技术社区  · 6 年前

    是否有任何指标可以让我了解函数是否执行I/O操作? 主要的目标平台是Linux(Ubuntu,或者它的一些变种)。

    最明显的方法是拥有这样的函数/库的目录,并检查其中是否存在该函数。不过,我想知道我怎么能在一开始就建立这样一个目录。

    例如, printf 最终写入标准输出,因此它将被计算在内。从USB端口读取数据的函数也会计算在内。但他们有什么共同点吗,即使我必须挖到最底层?


    这可能与问题无关,但理想情况下,我可以利用这些函数的一些模式,以便使用工具自动识别它们。我只是不知道要找什么低级指令。

    1 回复  |  直到 6 年前
        1
  •  2
  •   MSalters    6 年前

    标准C++当然没有从USB中读取的功能,但是让我们暂时忽略它的细节。

    函数执行“真实”I/O的问题可以在标准C++中通过询问库函数有哪些来近似。 observable side effects . 直接指向 Input/Output headers 现在当然还有 <filesystem> .

    (从C++引用复制:)

    <iosfwd>    forward declarations of all classes in the input/output library
    <ios>       std::ios_base class, std::basic_ios class template and several typedefs
    <istream>   std::basic_istream class template and several typedefs
    <ostream>   std::basic_ostream, std::basic_iostream class templates and several typedefs
    <iostream>  several standard stream objects
    <fstream>   std::basic_fstream, std::basic_ifstream, std::basic_ofstream class templates and several typedefs
    <sstream>   std::basic_stringstream, std::basic_istringstream, std::basic_ostringstream class templates and several typedefs
    <syncstream> (since C++20)  std::basic_osyncstream, std::basic_syncbuf, and typedefs
    <strstream> (deprecated)    std::strstream, std::istrstream, std::ostrstream
    <iomanip>   Helper functions to control the format of input and output
    <streambuf> std::basic_streambuf class template
    <cstdio>    C-style input-output functions