dtrace

How can write logs to a file in btrace?

半世苍凉 提交于 2019-12-23 12:57:21
问题 I have following btrace script. I would like to record entry and exit of functions in a specific class. .. package com.sun.btrace.samples; import com.sun.btrace.BTraceUtils; import com.sun.btrace.Profiler; import com.sun.btrace.annotations.*; @BTrace class Profiling { @Property Profiler swingProfiler = BTraceUtils.Profiling.newProfiler(); @OnMethod( clazz="com.pkg.classname", method="/.*/") void entry(@ProbeMethodName(fqn=true) String probeMethod) { BTraceUtils.print("Entry" ); BTraceUtils

Failed to execute script.sh: unknown error

大城市里の小女人 提交于 2019-12-22 17:19:00
问题 I wanted to use DTrace to see "what syscalls are made by my shell script". I made a very simple shell script, shell.sh , and gave it execute privileges: #!/bin/bash grep 1 <<< 123 I cd 'd into its directory, and ran this simple DTrace script: sudo dtrace -n 'syscall:::entry /pid == $target/ { @[probefunc] = count(); }' -c ./trace-me.sh I get this error output: dtrace: failed to execute ./trace-me.sh: unknown error What happened here? I've run csrutil enable --without dtrace . The DTrace

TSA方法

白昼怎懂夜的黑 提交于 2019-12-22 13:40:32
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 来源 有两种基本的性能分析方法可以应对大部分性能问题。一是面向资源的USE方法,它提供了识别常见瓶颈和错误的检查清单。二是面向线程的TSA方法,用于识别线程性能不佳的原因。我在今年(译者注:时为2014年)Velocity会议的《Stop The Guessing》演讲上总结出了TSA方法。这一方法同时也在我《系统性能》一书的《应用程序》章节里进行了介绍。 作为USE方法的补充,TSA方法具有不同的视角:线程而非资源。TSA提供了分析工作的出发点,并将调查范围缩小到了错误周边。TSA方法可以应用到任何操作系统,它从一个我们想要回答的问题的答案发展而来:每个线程的时间都用到哪里了? 我在近期的系统性能课程上教授了这个方法,课程帮助了我的学生——大多是系统管理员——快速解决一些列性能问题。我使用了这种方法很多年,在企业和云生产环境下,解决了数不清的性能问题。 总结 TSA(Thread State Analysis)方法可以总结为: 对每个重要线程,度量不同状态下线程花费的总时间。 使用适当的工具,按频率从高到底逐一分析线程状态。 我使用“线程”这一词汇来表示操作系统运行实体,它可以是线程、任务或进程。重要线程可以是应用线程或内核线程。 线程时间被分割为几个互斥状态。下列6个状态基于通用操作系统内核

How to view call stack with dtrace

╄→гoц情女王★ 提交于 2019-12-21 02:36:03
问题 How to view call stack, return value and arguments of the simply program below, with dtrace /** Trival code **/ #include <stdio.h> int foo (int *a, int *b) { *a = *b; *b = 4; return 0; } int main (void) { int a, b; a = 1; b = 2; foo (&a, &b); printf ("Value a: %d, Value b: %d\n", a, b); return 0; } 回答1: First off, here's the script: pid$target::foo:entry { ustack(); self->arg0 = arg0; self->arg1 = arg1; printf("arg0 = 0x%x\n", self->arg0); printf("*arg0 = %d\n", *(int *)copyin(self->arg0, 4))

How to trace a program from its very beginning without running it as root

风格不统一 提交于 2019-12-20 12:24:55
问题 I'm writing a tool that calls through to DTrace to trace the program that the user specifies. If my tool uses dtrace -c to run the program as a subprocess of DTrace, not only can I not pass any arguments to the program, but the program runs with all the privileges of DTrace—that is, as root (I'm on Mac OS X). This makes certain things that should work break, and obviously makes a great many things that shouldn't work possible. The other solution I know of is to start the program myself, pause

ltrace equivalent for osx?

狂风中的少年 提交于 2019-12-18 11:45:30
问题 osx has the really powerful dtrace/ktrace/dtruss tools - however i'm not willing to invest the time necessary to learn dealing with them right now. what's the easiest way to get the equivalent functionality of linux ltrace (and possibly strace) on OSX? 回答1: No answer for ltrace (except perhaps "work out how to use dtrace" :-) ), but for system call tracing ala strace, dtruss is a pretty good front end to dtrace. e.g. dtruss df -h # run and examine the "df -h" command dtruss -p 1871 # examine

How can I get dtrace to run the traced command with non-root priviledges?

▼魔方 西西 提交于 2019-12-18 10:14:23
问题 OS X lacks linux's strace , but it has dtrace which is supposed to be so much better. However, I miss the ability to do simple tracing on individual commands. For example, on linux I can write strace -f gcc hello.c to caputre all system calls, which gives me the list of all the filenames needed by the compiler to compile my program (the excellent memoize script is built upon this trick) I want to port memoize on the mac, so I need some kind of strace . What I actually need is the list of

Equivalent of strace -feopen < command > on mac os X

[亡魂溺海] 提交于 2019-12-17 08:01:48
问题 This is useful for debugging (hence programming related). On linux, we can use the command strace -feopen python myfile.py to figure out which python modules and shared objects are loaded. Is there an equivalent one-liner on macOS X? 回答1: I suppose you meant strace -fetrace=open ? dtruss -f -t open python myfile.py 来源: https://stackoverflow.com/questions/1925978/equivalent-of-strace-feopen-command-on-mac-os-x

Equivalent of strace -feopen < command > on mac os X

半腔热情 提交于 2019-12-17 08:01:33
问题 This is useful for debugging (hence programming related). On linux, we can use the command strace -feopen python myfile.py to figure out which python modules and shared objects are loaded. Is there an equivalent one-liner on macOS X? 回答1: I suppose you meant strace -fetrace=open ? dtruss -f -t open python myfile.py 来源: https://stackoverflow.com/questions/1925978/equivalent-of-strace-feopen-command-on-mac-os-x

Define DTrace compatible structs for Objective-C objects

烂漫一生 提交于 2019-12-13 15:50:21
问题 I'm trying to write a DTrace script that will show me the parameter passed to -[NSURLConnection sendSynchronousRequest:returningResponse:error:] and I can't find a struct that works for extracting the string out of the passed in NSString parameter. This question has an answer that works for OS X applications, but it does not work for my application which is using the iOS simulator. Although I'm looking for a solution to this specific example, I'm much more interested in learning the best way