麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > OS > 安卓 > 正文

Oprofile分析(android oprofile性能分析)

2024-06-28 13:24:34
字體:
供稿:網(wǎng)友
OPRofile分析(android oprofile性能分析)

一、內(nèi)核支持: make menuconfig

1、評(píng)測菜單中啟用 Oprofile ,在 .config 文件中設(shè)置?CONFIG_PROFILING=y?和?CONFIG_OPROFILE=y2、Kernel Feature->[]Enable hardware performance counter support for perf events不要勾選3、在boot options->console=ttyFIQ0 androidboot.console=ttyFIQ0 init=/init profile=1二、修改源碼將kernel/arch/arm/oprofile中的common.文件修改

/**                                 * @file common.c                                 *                                 * @remark Copyright 2004 Oprofile Authors                                 * @remark Copyright 2010 ARM Ltd.                                 * @remark Read the file COPYING                                 *                                 * @author Zwane Mwaikambo                                 * @author Will Deacon [move to perf]                                 */                                                                #include <linux/cpumask.h>                                #include <linux/err.h>                                #include <linux/errno.h>                                #include <linux/init.h>                                #include <linux/mutex.h>                                #include <linux/oprofile.h>                                #include <linux/perf_event.h>                                #include <linux/platform_device.h>                                #include <linux/slab.h>                                #include <asm/stacktrace.h>                                #include <linux/uaccess.h>                                                                #include <asm/perf_event.h>                                #include <asm/ptrace.h>                                                                #ifdef CONFIG_HW_PERF_EVENTS                                /*                                 * Per performance monitor configuration as set via oprofilefs.                                 */                                struct op_counter_config {                                    unsigned long count;                                unsigned long enabled;                                unsigned long event;                                unsigned long unit_mask;                                unsigned long kernel;                                unsigned long user;                                struct perf_event_attr attr;                            };                                                                static int op_arm_enabled;                                static DEFINE_MUTEX(op_arm_mutex);                                                                static struct op_counter_config *counter_config;                                static struct perf_event **perf_events[nr_cpumask_bits];                                static int perf_num_counters_bak;                                                                /*                                 * Overflow callback for oprofile.                                 */                                static void op_overflow_handler(struct perf_event *event, int unused,                                            struct perf_sample_data *data, struct pt_regs *regs)                    {                                    int id;                                u32 cpu = smp_processor_id();                                                                for (id = 0; id < perf_num_counters_bak; ++id)                                    if (perf_events[cpu][id] == event)                                    break;                                                        if (id != perf_num_counters_bak)                                    oprofile_add_sample(regs, id);                            else                                    pr_warning("oprofile: ignoring spurious overflow "                                        on cpu %u/n, cpu);                }                                                                /*                                 * Called by op_arm_setup to create perf attributes to mirror the oprofile                                 * settings in counter_config. Attributes are created as `pinned' events and                                 * so are permanently scheduled on the PMU.                                 */                                static void op_perf_setup(void)                                {                                    int i;                                u32 size = sizeof(struct perf_event_attr);                                struct perf_event_attr *attr;                                                                for (i = 0; i < perf_num_counters_bak; ++i) {                                    attr = &counter_config[i].attr;                                memset(attr, 0, size);                                attr->type        = PERF_TYPE_RAW;                        attr->size        = size;                        attr->config        = counter_config[i].event;                        attr->sample_period    = counter_config[i].count;                            attr->pinned        = 1;                    }                            }                                                                static int op_create_counter(int cpu, int event)                                {                                    int ret = 0;                                struct perf_event *pevent;                                                                if (!counter_config[event].enabled || (perf_events[cpu][event] != NULL))                                    return ret;                                                            pevent = perf_event_create_kernel_counter(&counter_config[event].attr,                                                      cpu, NULL,                                  op_overflow_handler);                                            if (IS_ERR(pevent)) {                                    ret = PTR_ERR(pevent);                            } else if (pevent->state != PERF_EVENT_STATE_ACTIVE) {                                    pr_warning("oprofile: failed to enable event %d "                                        on CPU %d/n, event, cpu);                        ret = -EBUSY;                            } else {                                    perf_events[cpu][event] = pevent;                            }                                                                return ret;                            }                                                                static void op_destroy_counter(int cpu, int event)                                {                                    struct perf_event *pevent = perf_events[cpu][event];                                                                if (pevent) {                                    perf_event_release_kernel(pevent);                                perf_events[cpu][event] = NULL;                            }                            }                                                                /*                                 * Called by op_arm_start to create active perf events based on the                                 * perviously configured attributes.                                 */                                static int op_perf_start(void)                                {                                    int cpu, event, ret = 0;                                                                for_each_online_cpu(cpu) {                                    for (event = 0; event < perf_num_counters_bak; ++event) {                                    ret = op_create_counter(cpu, event);                                if (ret)                                    goto out;                        }                            }                                                            out:                                    return ret;                            }                                                                /*                                 * Called by op_arm_stop at the end of a profiling run.                                 */                                static void op_perf_stop(void)                                {                                    int cpu, event;                                                                for_each_online_cpu(cpu)                                    for (event = 0; event < perf_num_counters_bak; ++event)                                    op_destroy_counter(cpu, event);                    }                                                                char *op_name_from_perf_id(void)                                {                                    enum arm_perf_pmu_ids id = armpmu_get_pmu_id();                                                                switch (id) {                                case ARM_PERF_PMU_ID_XSCALE1:                                    return "arm/xscale1";                            case ARM_PERF_PMU_ID_XSCALE2:                                    return "arm/xscale2";                            case ARM_PERF_PMU_ID_V6:                                    return "arm/armv6";                            case ARM_PERF_PMU_ID_V6MP:                                    return "arm/mpcore";                            case ARM_PERF_PMU_ID_CA8:                                    return "arm/armv7";                            case ARM_PERF_PMU_ID_CA9:                                    return "arm/armv7-ca9";                            default:                                    return NULL;                            }                            }                                                                static int op_arm_create_files(struct super_block *sb, struct dentry *root)                                {                                    unsigned int i;                                                                for (i = 0; i < perf_num_counters_bak; i++) {                                    struct dentry *dir;                                char buf[4];                                                                snprintf(buf, sizeof buf, "%d", i);                                dir = oprofilefs_mkdir(sb, root, buf);                                oprofilefs_create_ulong(sb, dir, "enabled", &counter_config[i].enabled);                                oprofilefs_create_ulong(sb, dir, "event", &counter_config[i].event);                                oprofilefs_create_ulong(sb, dir, "count", &counter_config[i].count);                                oprofilefs_create_ulong(sb, dir, "unit_mask", &counter_config[i].unit_mask);                                oprofilefs_create_ulong(sb, dir, "kernel", &counter_config[i].kernel);                                oprofilefs_create_ulong(sb, dir, "user", &counter_config[i].user);                            }                                                                return 0;                            }                                                                static int op_arm_setup(void)                                {                                    spin_lock(&oprofilefs_lock);                                op_perf_setup();                                spin_unlock(&oprofilefs_lock);                                return 0;                            }                                                                static int op_arm_start(void)                                {                                    int ret = -EBUSY;                                                                mutex_lock(&op_arm_mutex);                                if (!op_arm_enabled) {                                    ret = 0;                                op_perf_start();                                op_arm_enabled = 1;                            }                                mutex_unlock(&op_arm_mutex);                                return ret;                            }                                                                static void op_arm_stop(void)                                {                                    mutex_lock(&op_arm_mutex);                                if (op_arm_enabled)                                    op_perf_stop();                            op_arm_enabled = 0;                                mutex_unlock(&op_arm_mutex);                            }                                                                #ifdef CONFIG_PM                                static int op_arm_suspend(struct platform_device *dev, pm_message_t state)                                {                                    mutex_lock(&op_arm_mutex);                                if (op_arm_enabled)                                    op_perf_stop();                            mutex_unlock(&op_arm_mutex);                                return 0;                            }                                                                static int op_arm_resume(struct platform_device *dev)                                {                                    mutex_lock(&op_arm_mutex);                                if (op_arm_enabled && op_perf_start())                                    op_arm_enabled = 0;                            mutex_unlock(&op_arm_mutex);                                return 0;                            }                                                                static struct platform_driver oprofile_driver = {                                    .driver        = {                            .name        = "arm-oprofile",                    },                                .resume        = op_arm_resume,                        .suspend    = op_arm_suspend,                        };                                                                static struct platform_device *oprofile_pdev;                                                                static int __init init_driverfs(void)                                {                                    int ret;                                                                ret = platform_driver_register(&oprofile_driver);                                if (ret)                                    goto out;                                                            oprofile_pdev =    platform_device_register_simple(                                        oprofile_driver.driver.name, 0, NULL, 0);                    if (IS_ERR(oprofile_pdev)) {                                    ret = PTR_ERR(oprofile_pdev);                                platform_driver_unregister(&oprofile_driver);                            }                                                            out:                                    return ret;                            }                                                                static void  exit_driverfs(void)                                {                                    platform_device_unregister(oprofile_pdev);                                platform_driver_unregister(&oprofile_driver);                            }                                #else                                static int __init init_driverfs(void) { return 0; }                                #define exit_driverfs() do { } while (0)                                #endif /* CONFIG_PM */                                                                static int report_trace(struct stackframe *frame, void *d)                                {                                    unsigned int *depth = d;                                                                if (*depth) {                                    oprofile_add_trace(frame->pc);                                (*depth)--;                            }                                                                return *depth == 0;                            }                                                                /*                                 * The registers we're interested in are at the end of the variable                                 * length saved register structure. The fp points at the end of this                                 * structure so the address of this struct is:                                 * (struct frame_tail *)(xxx->fp)-1                                 */                                struct frame_tail {                                    struct frame_tail *fp;                                unsigned long sp;                                unsigned long lr;                            } __attribute__((packed));                                                                static struct frame_tail* user_backtrace(struct frame_tail *tail)                                {                                    struct frame_tail buftail[2];                                                                /* Also check accessibility of one struct frame_tail beyond */                                if (!access_ok(VERIFY_READ, tail, sizeof(buftail)))                                    return NULL;                            if (__copy_from_user_inatomic(buftail, tail, sizeof(buftail)))                                    return NULL;                                                            oprofile_add_trace(buftail[0].lr);                                                                /* frame pointers should strictly progress back up the stack                                 * (towards higher addresses) */                                if (tail + 1 >= buftail[0].fp)                                    return NULL;                                                            return buftail[0].fp-1;                            }                                                                static void arm_backtrace(struct pt_regs * const regs, unsigned int depth)                                {                                    struct frame_tail *tail = ((struct frame_tail *) regs->ARM_fp) - 1;                                                                if (!user_mode(regs)) {                                    struct stackframe frame;                                frame.fp = regs->ARM_fp;                                frame.sp = regs->ARM_sp;                                frame.lr = regs->ARM_lr;                                frame.pc = regs->ARM_pc;                                walk_stackframe(&frame, report_trace, &depth);                                return;                            }                                                                while (depth-- && tail && !((unsigned long) tail & 3))                                    tail = user_backtrace(tail);                        }                                                                int __init oprofile_arch_init(struct oprofile_Operations *ops)                                {                                    int cpu, ret = 0;                                                                perf_num_counters_bak = armpmu_get_max_events();                                                                counter_config = kcalloc(perf_num_counters_bak,                                        sizeof(struct op_counter_config), GFP_KERNEL);                                                        if (!counter_config) {                                    pr_info("oprofile: failed to allocate %d "                                        counters/n, perf_num_counters_bak);                        return -ENOMEM;                            }                                                                ret = init_driverfs();                                if (ret) {                                    kfree(counter_config);                                return ret;                            }                                                                for_each_possible_cpu(cpu) {                                    perf_events[cpu] = kcalloc(perf_num_counters_bak,                                        sizeof(struct perf_event *), GFP_KERNEL);                        if (!perf_events[cpu]) {                                    pr_info("oprofile: failed to allocate %d perf events "                                        for cpu %d/n, perf_num_counters_bak, cpu);                        while (--cpu >= 0)                                    kfree(perf_events[cpu]);                            return -ENOMEM;                            }                            }                                                                ops->backtrace        = arm_backtrace;                        ops->create_files    = op_arm_create_files;                            ops->setup        = op_arm_setup;                        ops->start        = op_arm_start;                        ops->stop        = op_arm_stop;                        ops->shutdown        = op_arm_stop;                        ops->cpu_type        = op_name_from_perf_id();                                                        if (!ops->cpu_type)                                    ret = -ENODEV;                            else                                    pr_info("oprofile: using %s/n", ops->cpu_type);                                                            return ret;                            }                                                                void oprofile_arch_exit(void)                                {                                    int cpu, id;                                struct perf_event *event;                                                                if (*perf_events) {                                    exit_driverfs();                                for_each_possible_cpu(cpu) {                                    for (id = 0; id < perf_num_counters_bak; ++id) {                                    event = perf_events[cpu][id];                                if (event != NULL)                                    perf_event_release_kernel(event);                        }                                kfree(perf_events[cpu]);                            }                            }                                                                if (counter_config)                                    kfree(counter_config);                        }                                                                #else                                int __init oprofile_arch_init(struct oprofile_operations *ops)                                {                                    pr_info("oprofile: hardware counters not available/n");                                return -ENODEV;                            }                                void oprofile_arch_exit(void) {}                                #endif /* CONFIG_HW_PERF_EVENTS */

三、相關(guān) kernel/sched.c--------profile_hit(SCHED_PROFILING, __builtin_return_address(0)); 下面是對profile的解釋:Linux -- profile內(nèi)核版本2.6.18-RC7profile只是內(nèi)核的一個(gè)調(diào)試性能的工具,這個(gè)可以通過menuconfig中的Instrumentation Support->profile打開。1. 如何使用profile:首先確認(rèn)內(nèi)核支持profile,然后在內(nèi)核啟動(dòng)時(shí)加入以下參數(shù):profile=1或者其它參數(shù), 新的內(nèi)核支持profile=schedule 12. 內(nèi)核啟動(dòng)后會(huì)創(chuàng)建/proc/profile文件,這個(gè)文件可以通過readprofile讀取,如readprofile -m /proc/kallsyms | sort -nr > ~/cur_profile.log,或者readprofile -r -m /proc/kallsyms |sort -nr,或者readprofile -r && sleep 1 && readprofile -m /proc/kallsyms |sort -nr >~/cur_profile.log3. 讀取/proc/profile可獲得哪些內(nèi)容?根據(jù)啟動(dòng)配置profile=?的不同,獲取的內(nèi)容不同:如果配置成profile=? 可以獲得每個(gè)函數(shù)執(zhí)行次數(shù),用來調(diào)試函數(shù)性能很有用如果設(shè)置成profile=schedule ?可以獲得每個(gè)函數(shù)調(diào)用schedule的次數(shù),用來調(diào)試schedule很有用

四、總結(jié)一下:opcontrol –init 加載模塊, mout /dev/oprofile 創(chuàng)建必需的文件和目錄opcontrol --no-vmlinux 或者 opcontrol --vmlinux=/boot/vmlinux-`uname -r` 決定是否對 kernel 進(jìn)行 profilingopcontrol --list-events //命令可以查看此結(jié)構(gòu)中支持的事件opcontrol --event=CPU_CLK_UNHALTED:5000 --event=DATA_CACHE_MISSES:1000 --event=INSTRUCTION_CACHE_MISSES:1000 --event=MEMORY_REQUESTS:1000opcontrol --reset 清楚當(dāng)前會(huì)話中的數(shù)據(jù)opcontrol --start 開始 profiling./wls 運(yùn)行應(yīng)用程序, oprofile 會(huì)對它進(jìn)行 profiling通過opcontrol --event=L2_CACHE_MISS:500 --event=L1_DTLB_MISS_AND_L2_DTLB_HIT:500opcontrol --dump 把收集到的數(shù)據(jù)寫入文件 --event=.........命令來進(jìn)行事件的設(shè)置;opcontrol --stop 停止 profiling 此命令--event參數(shù)必須依次給出,無論有多少個(gè),不可分行,切記opcotrol -h 關(guān)閉守護(hù)進(jìn)程 oprofiledopcontrol --shutdown 停止 oprofiledopcontrol --deinit 卸載模塊常用的是 3→7 這幾個(gè)過程,得到性能數(shù)據(jù)之后,可以使用 opreport, opstack, opgprof, opannotate幾個(gè)工具進(jìn)行分析,我常用的是opreport, opannotate 進(jìn)行分析。

五、示例與常見問題解訣Command format :$:tager board, #:Host1.Extract opf.tar.gz and busybox.tar.gz ($: tar -zxvf ***.tar.gz)2.Use adb push opf to /data/opf and busybox to /data/busybox(#: adb push opf /data/opf and #: adb push busybox /data/busybox)3.Run $:export PATH=$PATH:/data/opf$: is command to begin4.Run $:opcontrol --initRemark: if target board have oprofile,please delete the files(path:/system/xbin)Question:grep: /etc/mtab: No such file or directorygrep: /etc/mtab: No such file or directoryKernel support not available, missing opcontrol --init as rootAnswer:a.$:mount -o remount rw /b.$:mount -o rw,remount -t yaffs2 /dev/block/mmcblk0p9 /systemc.$:touch /system/etc/mtab or touch /etc/mtabd.$:echo nodev /dev/oprofile oprofilefs rw 0 0 > /system/etc/mtab or /etc/mtabe.make sure mtab the nodev $:cat /system/etc/mtab 5.$:opcontrol --initQuestion:cat: can't open '/dev/oprofile/cpu_type': No such file or directoryUnable to open cpu_type file for readingMake sure you have done opcontrol --initcpu_type 'unset' is not validyou should upgrade oprofile or force the use of timer modeAnswer:a.$:mkdir /dev/oprofile (if not exist)b.mount -t oprofilefs nodev /dev/oprofile6.$:opcontrol --session-dir=/data/first --no-vmlinux --callgraph=57.$:opcontrol --startQuestion:oprofile: could not open unit mask description file /home/henry/workspace/opf/pc/build/oprofile/share/oprofile//arm/armv7-ca9/unit_masksUsing default event: CPU_CYCLES:100000:0:1:1oprofile: could not open unit mask description file /home/henry/workspace/opf/pc/build/oprofile/share/oprofile//arm/armv7-ca9/unit_masksAnswer:a.To target board running $:mkdir -p /home/henry/workspace/opf/pc/build/oprofileb.Extract share.tar.gzc.Use ADB push share (#:adb push share /home/henry/workspace/opf/pc/build/oprofile/share)8.Run App to profile9.$:opcontrol --dump10.$:opcontrol --stop11.$:opreport --session-dir=/data/first -l /data/test/test$:opreport --session-dir=/data/first -l >log$:opreport --session-dir=/data/first -l /data/data/Service/lib/libXXX.so >logXXX$:opreport --session-dir=/data/first -l /data/data/Service/lib/libBBB.so >logBBB12.$:opcontrol --reset13.opcontrol --shutdownRemark: $:opcontrol --shutdown and $:opcontrol --init only execution once


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 成人毛片100部 | 懂色av懂色aⅴ精彩av | 国产一区二区三区在线免费 | 天天舔天天插 | 色猫av | 精品国产一级毛片 | 亚洲免费永久 | 少妇一级淫片高潮流水电影 | 午夜久久久精品一区二区三区 | 国产精品九九久久一区hh | 请播放一级毛片 | 日韩电影av在线 | 午夜视频色 | 久久日韩在线 | 国产精品自拍啪啪 | 亚洲国产高清一区 | 激情亚洲一区二区 | 国产污污视频 | 最新久久免费视频 | 国产色爱综合网 | 香蕉国产片 | 亚洲最大av网站 | 国产亚洲美女精品久久久2020 | 爱操影院| 欧美日韩一 | 国产伦久视频免费观看视频 | 久久国产夫妻视频 | 欧美77| 欧美日本日韩 | 热re91久久精品国产99热 | 亚洲午夜在线 | 欧美高清一级片 | 毛片午夜 | 精品国产乱码久久久久久久久 | 日本高清无遮挡 | 91一区二区三区久久久久国产乱 | 女18一级大黄毛片免费女人 | 久久精品国产99国产精品亚洲 | 国产欧美在线一区二区三区 | 羞羞视频免费网站含羞草 | 天天碰天天操 |