zoukankan      html  css  js  c++  java
  • 使用Golang进行性能分析(Profiling)

    转自:http://www.cppblog.com/sunicdavy/archive/2015/04/11/210308.html

    本文介绍游戏服务器的性能分析, web服务器性能分析不在本文分析范畴之内

    Golang编写的服务器可以方便的通过内建性能分析, 输出图表仔细查找原因, 非常的方便, 如下图

    1. 获取一个性能分析的封装库

       go get github.com/davecheney/profile
       2. 在工程内import这个组件    

    3. 在main中添加启动和停止入口

    func main() {
        defer profile.Start(profile.CPUProfile).Stop()
     
        // ... your main code here ...
    }

    4. 重新编译工程, 运行

    5. 注意观察启动后, 命令行里的字段, 类似于

    2013/08/08 16:45:58 profile: cpu profiling enabled, /tmp/profile882806532/cpu.pprof
    后面的路径就是pprof性能分析文件的位置, 启动机器人进行多次服务器测试用例, 停止机器人, Ctrl+C中断服务器
      6.将cpu.pprof拷贝到你的游戏exe所在位置
      7.下载并安装Graphviz, 这是将分析数据变成上图的图形化工具
      8.调用Graphviz制作文档
     go tool pprof --pdf gamesvc.exe cpu.pprof > report.pdf
    如果dot没有找到, 可以在执行前添加路径
    set path==%path%;"c:Program Files (x86)Graphviz2.38in"
  • 相关阅读:
    BOM操作
    重绘和回流
    css3动画 --- Transition
    css3动画 --- Animation
    flex布局
    读书笔记之python深入面向对象编程
    读书笔记之python面向对象编程的四大支柱
    git基础使用01
    python读取列表中的每个数据,@DDT,@Data(*data),@unpack使用
    python单元测试_读取excel表中的数据
  • 原文地址:https://www.cnblogs.com/sevenyuan/p/7132955.html
Copyright © 2011-2022 走看看