通过复杂目录(代码、文件、php 脚本等)诊断缓慢的 grep 或 ack 搜索,以便更快地重复使用
我正在使用 ack (有时作为 ack-grep 分发)来搜索复杂的代码、图像目录,谁知道还有什么,而且它的反应非常慢。我如何诊断它正在搜索的内容导致速度变慢,以便我可以让它忽略它们?
我刚刚意识到我的 ack-grep 缓慢的原因可能会因为同样的原因而使 grep 缓慢,所以我更改了标题的措辞以引用两者。
当前 ack-grep 命令别名:
function view ()
{
echo "ack-grep -i $@ // ignoring third-party directories"
ack-grep -i --ignore-dir=third-party --ignore-dir="unclean-files" --ignore-dir=FCKeditor --ignore-dir=smarty --ignore-dir=codepress --ignore-dir=yui "$@"
}
因此,我通过该别名对某些字符串进行不区分大小写的搜索,例如查看“哎呀!必填字段”
,忽略某些目录。
我想我真正可以使用的是 grep 或 ack-grep 的“详细”模式,这样我就可以直观地看到它悬挂的子目录,因为它们搜索速度很慢。
I'm using ack (sometimes distributed as ack-grep) to search through a complex directory of code, images, who knows what else, and it's reacting pretty slowly. How can I diagnose what it is searching through that is making it slow, so that I can have it ignore 'em?
I just realized that the reasons that my ack-grep are slow will probably make grep slow for the same reason, so I've changed the wording of the title to refer to both.
Current ack-grep command alias:
function view ()
{
echo "ack-grep -i $@ // ignoring third-party directories"
ack-grep -i --ignore-dir=third-party --ignore-dir="unclean-files" --ignore-dir=FCKeditor --ignore-dir=smarty --ignore-dir=codepress --ignore-dir=yui "$@"
}
So I do a case-insensitive search on some string via that alias, e.g. view "Oops! Required fields"
, ignoring certain directories.
I guess what I could really use is a "verbose" mode to either grep or ack-grep, so that I can visually see subdirectories that it hangs around on because they're slow to search.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最终使用 -L 开关使其输出所有匹配的文件,以便快速直观地诊断问题。仅使用以下命令结构:
ack-grep -L "哎呀!必填字段未全部完成。"
Ended up using the -L switch to make it output all the files that it matches, for quick visual diagnosis of problems. Used just the command structure below:
ack-grep -L "Oops! Required fields were not all completed."
你在寻找什么?如果它只是特定类型的源(假设您正在寻找变量),请使用适当的开关(对于 perl,使用 --perl 等)。如果你有大量的资源,那么无论你做什么都需要一段时间。
Ack-grep 的智能程度取决于您的描述。另外,你的正则表达式有多复杂?正则表达式有开销,如果您只是搜索某个名称,请不要使用正则表达式。您不应该使用锤子来松开螺栓。
What are you searching for? If it's just source of a particular type (say you're looking for a variable), use the appropriate switch (for perl, use --perl, etc). If you have tons of source, it's gonna take a while regardless of what you do.
Ack-grep is only as smart as you tell it to be. Also, how complex is your regex? Regex has overhead, and if you're just searching for a name of something, don't use regex. You shouldn't use a hammer to loosen a bolt.