{"id":17981162,"url":"https://github.com/xin053/hsperfdata","last_synced_at":"2025-10-30T08:07:31.102Z","repository":{"id":34362275,"uuid":"137046147","full_name":"xin053/hsperfdata","owner":"xin053","description":"golang parser for java HotSpot virtual meachine performance data V2","archived":false,"fork":false,"pushed_at":"2023-05-09T17:53:45.000Z","size":40,"stargazers_count":12,"open_issues_count":1,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-15T01:32:50.044Z","etag":null,"topics":["go","hotspot","hsperfdata","jvm"],"latest_commit_sha":null,"homepage":"https://xin053.github.io/hsperfdata","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xin053.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-12T09:08:22.000Z","updated_at":"2025-01-21T03:28:52.000Z","dependencies_parsed_at":"2024-06-19T01:26:11.238Z","dependency_job_id":"70487b06-df4d-4249-b0b3-c36ddd9e3fff","html_url":"https://github.com/xin053/hsperfdata","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/xin053/hsperfdata","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xin053%2Fhsperfdata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xin053%2Fhsperfdata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xin053%2Fhsperfdata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xin053%2Fhsperfdata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xin053","download_url":"https://codeload.github.com/xin053/hsperfdata/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xin053%2Fhsperfdata/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281770019,"owners_count":26558441,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-30T02:00:06.501Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","hotspot","hsperfdata","jvm"],"created_at":"2024-10-29T18:08:30.475Z","updated_at":"2025-10-30T08:07:31.068Z","avatar_url":"https://github.com/xin053.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hsperfdata\r\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fxin053%2Fhsperfdata.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fxin053%2Fhsperfdata?ref=badge_shield)\r\n\r\n## What's this?\r\n\r\nThis is a golang parser for the newest V2 java HotSpot virtual machine performance data, support all platform theoretically.\r\n\r\n## What's hsperfdata file?\r\n\r\nIt is a log directory created by JVM while running your code. By default it is created inside the tmp folder of the operating system that you are using! This directory is a part of Java Performance counter. And the file in this directory is named by the pid number of java process.\r\n\r\nFor example, if you are running a java process which pid is `1111`, the hsperfdata file is `%TEMP%/hsperfdata_\u003cyourusername\u003e/1111` on `windows`, `/tmp/hsperfdata_\u003cyourusername\u003e/1111` on `linux`.\r\n\r\nYou can disable creating this directory by using `-XX:-UsePerfData` or `-XX:+PerfDisableSharedMem` which is not recommended.\r\n\r\n## Used as a library\r\n\r\n**First, you should get the file path string of the hsperfdata file that you want to parser, then use `ReadPerfData` function to parser the hsperfdata file**\r\n\r\nThere are several functions to get the path, include `PerfDataPath(pid string)`, `PerfDataPaths(pids []string)`, `UserPerfDataPaths(user string)`, `CurrentUserPerfDataPaths()`, `AllPerfDataPaths()`, `DataPathsByProcessName(processName string)`.\r\n\r\nFor how to use these functions, look at [`hsperfdata function documentation`](https://pkg.go.dev/github.com/xin053/hsperfdata#section-documentation) or you can just read the [`hsperfdata.go`](./hsperfdata.go) to figure out how to use them, the source code is easy to read through.\r\n\r\nThere is a demo using this project as a go library:\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"log\"\r\n\t\"sort\"\r\n\r\n\t\"github.com/xin053/hsperfdata\"\r\n)\r\n\r\nfunc main() {\r\n\tfilePaths, err := hsperfdata.DataPathsByProcessName(\"java\")\r\n\tif err != nil {\r\n\t\tlog.Fatal(err)\r\n\t}\r\n\r\n\tfor pid := range filePaths {\r\n\t\tentryMap, err := hsperfdata.ReadPerfData(filePaths[pid], true)\r\n\t\tif err != nil {\r\n\t\t\tlog.Fatal(\"open fail\", err)\r\n\t\t}\r\n\r\n\t\tvar keys []string\r\n\t\tfor k := range entryMap {\r\n\t\t\tkeys = append(keys, k)\r\n\t\t}\r\n\r\n\t\tsort.Strings(keys)\r\n\r\n\t\tfor _, key := range keys {\r\n\t\t\tfmt.Printf(\"%s=%v\\n\", key, entryMap[key])\r\n\t\t}\r\n\t}\r\n}\r\n```\r\n\r\n## Used as a command\r\n\r\nThere is a demo [`hstat.go`](./cmd/hstat.go)\r\n\r\n### build hstat yourself\r\n\r\n```shell\r\n# go1.12+\r\ngo build .\\cmd\\hstat.go\r\n\r\n# Usage: hstat pid\r\n# if you have a java process which pid is 1111, then run this\r\nhstat 1111\r\n```\r\n\r\n### use the release package\r\n\r\ndownload the executable from the release page, then here you go!\r\n\r\n## Want deeper?\r\n\r\n### java HotSpot virtual machine performance data structures\r\n\r\n```go\r\n// perfdataHeader http://openjdk.java.net/groups/serviceability/jvmstat/sun/jvmstat/perfdata/monitor/AbstractPerfDataBufferPrologue.html\r\n// source code https://github.com/dmlloyd/openjdk/blob/jdk/jdk/src/jdk.internal.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/AbstractPerfDataBufferPrologue.java\r\ntype perfdataHeader struct {\r\n    Magic     uint32 // magic number - 0xcafec0c0\r\n    ByteOrder byte   // big_endian == 0, little_endian == 1\r\n    Major     byte   // major version numbers\r\n    Minor     byte   // minor version numbers\r\n    // ReservedByte byte   // used as Accessible flag at performance data V2\r\n}\r\n\r\n// prologue http://openjdk.java.net/groups/serviceability/jvmstat/sun/jvmstat/perfdata/monitor/v2_0/PerfDataBufferPrologue.html\r\n// source code https://github.com/dmlloyd/openjdk/blob/jdk/jdk/src/jdk.internal.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/v2_0/PerfDataBufferPrologue.java\r\ntype bufferPrologueV2 struct {\r\n    Accessible   byte  // Accessible flag at performance data V2\r\n    Used         int32 // number of PerfData memory bytes used\r\n    Overflow     int32 // number of bytes of overflow\r\n    ModTimestamp int64 // time stamp of the last structural modification\r\n    EntryOffset  int32 // offset of the first PerfDataEntry\r\n    NumEntries   int32 // number of allocated PerfData entries\r\n}\r\n\r\n// entryHeader http://openjdk.java.net/groups/serviceability/jvmstat/sun/jvmstat/perfdata/monitor/v2_0/PerfDataBuffer.html\r\n// source code https://github.com/dmlloyd/openjdk/blob/jdk/jdk/src/jdk.internal.jvmstat/share/classes/sun/jvmstat/perfdata/monitor/v2_0/PerfDataBuffer.java\r\ntype entryHeader struct {\r\n    EntryLength  int32 // entry length in bytes\r\n    NameOffset   int32 // offset to entry name, relative to start of entry\r\n    VectorLength int32 // length of the vector. If 0, then scalar.\r\n    DataType     byte  // JNI field descriptor type\r\n    Flags        byte  // miscellaneous attribute flags 0x01 - supported\r\n    DataUnits    byte  // unit of measure attribute\r\n    DataVar      byte  // variability attribute\r\n    DataOffset   int32 // offset to data item, relative to start of entry.\r\n}\r\n```\r\n\r\n**You can read the source code `hsperfdata.go` to get more information, have a good time!**\r\n\r\n**You can open a issue if you have any questions.**\r\n\r\n## Attention\r\n\r\nThe newest java HotSpot virtual machine performance data structures was V2 when I wrote this code, so these data structures may change from release to release, so this parser code only support JVM performance data V2. If there is new version, please open a issue or pull request, thx.\r\n\r\n## Reference link\r\n\r\n1. http://openjdk.java.net/groups/serviceability/jvmstat/index.html\r\n2. https://github.com/tokuhirom/go-hsperfdata\r\n3. https://github.com/njwhite/telegraf/blob/master/plugins/inputs/hsperfdata/hsperfdata.go\r\n4. https://github.com/twitter/commons/blob/master/src/python/twitter/common/java/perfdata/bin/jammystat.py\r\n5. https://github.com/YaSuenag/hsbeat/blob/master/module/hotspot/hsperfdata/parser.go\r\n\r\n## License\r\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fxin053%2Fhsperfdata.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fxin053%2Fhsperfdata?ref=badge_large)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxin053%2Fhsperfdata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxin053%2Fhsperfdata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxin053%2Fhsperfdata/lists"}