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

How to detect if a function performs IO operations?

本文关键字:是否 执行 IO 操作 函数 何检测 检测      更新时间:2023-10-16

有没有可以查找的指标来了解函数是否执行I/O操作?主要的目标平台是Linux(Ubuntu,或者它的一些变体(。

最明显的方法是有一个这样的函数/库的目录,并检查其中是否存在函数。然而,我想知道如何首先构建这样的目录。

例如,printf最终会写入标准输出,因此它会计数。从USB端口读取的功能也会起作用。但他们有什么共同点吗,即使我必须挖掘到最底层?


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

标准C++当然没有从USB读取的函数,但让我们暂时忽略这个细节。

哪些函数执行"真实"I/O的问题可以在标准C++中通过询问哪些库函数具有可观察的副作用来近似。这直接指向一组输入/输出头,当然现在还有<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