Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 147590
b: refs/heads/master
c: a0055ae
h: refs/heads/master
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo authored and Ingo Molnar committed Jun 2, 2009
1 parent 0c968d2 commit cace1ef
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 71 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ea5cc87c63b49c133d15ec2911bb2e49e8124516
refs/heads/master: a0055ae2a4e13db9534c438cf8f3896181da6afc
2 changes: 2 additions & 0 deletions trunk/Documentation/perf_counter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ LIB_H += util/quote.h
LIB_H += util/util.h
LIB_H += util/help.h
LIB_H += util/strbuf.h
LIB_H += util/string.h
LIB_H += util/run-command.h
LIB_H += util/sigchain.h
LIB_H += util/symbol.h
Expand All @@ -315,6 +316,7 @@ LIB_OBJS += util/rbtree.o
LIB_OBJS += util/run-command.o
LIB_OBJS += util/quote.o
LIB_OBJS += util/strbuf.o
LIB_OBJS += util/string.o
LIB_OBJS += util/usage.o
LIB_OBJS += util/wrapper.o
LIB_OBJS += util/sigchain.o
Expand Down
56 changes: 32 additions & 24 deletions trunk/Documentation/perf_counter/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "util/util.h"
#include "util/parse-options.h"
#include "util/parse-events.h"
#include "util/string.h"

#include <sched.h>

Expand Down Expand Up @@ -165,12 +166,10 @@ static pid_t pid_synthesize_comm_event(pid_t pid)
{
struct comm_event comm_ev;
char filename[PATH_MAX];
pid_t spid, ppid;
char bf[BUFSIZ];
int fd, nr, ret;
char comm[18];
int fd, ret;
size_t size;
char state;
char *field, *sep;

snprintf(filename, sizeof(filename), "/proc/%d/stat", pid);

Expand All @@ -185,20 +184,22 @@ static pid_t pid_synthesize_comm_event(pid_t pid)
}
close(fd);

/* 9027 (cat) R 6747 9027 6747 34816 9027 ... */
memset(&comm_ev, 0, sizeof(comm_ev));
nr = sscanf(bf, "%d %s %c %d %d ",
&spid, comm, &state, &ppid, &comm_ev.pid);
if (nr != 5) {
fprintf(stderr, "couldn't get COMM and pgid, malformed %s\n",
filename);
exit(EXIT_FAILURE);
}
field = strchr(bf, '(');
if (field == NULL)
goto out_failure;
sep = strchr(++field, ')');
if (sep == NULL)
goto out_failure;
size = sep - field;
memcpy(comm_ev.comm, field, size++);
field = strchr(sep + 4, ' ');
if (field == NULL)
goto out_failure;
comm_ev.pid = atoi(++field);
comm_ev.header.type = PERF_EVENT_COMM;
comm_ev.tid = pid;
size = strlen(comm);
comm[--size] = '\0'; /* Remove the ')' at the end */
--size; /* Remove the '(' at the begin */
memcpy(comm_ev.comm, comm + 1, size);
size = ALIGN(size, sizeof(uint64_t));
comm_ev.header.size = sizeof(comm_ev) - (sizeof(comm_ev.comm) - size);

Expand All @@ -208,6 +209,11 @@ static pid_t pid_synthesize_comm_event(pid_t pid)
exit(-1);
}
return comm_ev.pid;
out_failure:
fprintf(stderr, "couldn't get COMM and pgid, malformed %s\n",
filename);
exit(EXIT_FAILURE);
return -1;
}

static void pid_synthesize_mmap_events(pid_t pid, pid_t pgid)
Expand All @@ -223,23 +229,25 @@ static void pid_synthesize_mmap_events(pid_t pid, pid_t pgid)
exit(EXIT_FAILURE);
}
while (1) {
char bf[BUFSIZ];
unsigned char vm_read, vm_write, vm_exec, vm_mayshare;
char bf[BUFSIZ], *pbf = bf;
struct mmap_event mmap_ev = {
.header.type = PERF_EVENT_MMAP,
};
unsigned long ino;
int major, minor;
int n;
size_t size;
if (fgets(bf, sizeof(bf), fp) == NULL)
break;

/* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
sscanf(bf, "%llx-%llx %c%c%c%c %llx %x:%x %lu",
&mmap_ev.start, &mmap_ev.len,
&vm_read, &vm_write, &vm_exec, &vm_mayshare,
&mmap_ev.pgoff, &major, &minor, &ino);
if (vm_exec == 'x') {
n = hex2u64(pbf, &mmap_ev.start);
if (n < 0)
continue;
pbf += n + 1;
n = hex2u64(pbf, &mmap_ev.len);
if (n < 0)
continue;
pbf += n + 3;
if (*pbf == 'x') { /* vm_exec */
char *execname = strrchr(bf, ' ');

if (execname == NULL || execname[1] != '/')
Expand Down
1 change: 1 addition & 0 deletions trunk/Documentation/perf_counter/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "util/cache.h"
#include "util/rbtree.h"
#include "util/symbol.h"
#include "util/string.h"

#include "perf.h"

Expand Down
27 changes: 16 additions & 11 deletions trunk/Documentation/perf_counter/util/parse-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "parse-options.h"
#include "parse-events.h"
#include "exec_cmd.h"
#include "string.h"

int nr_counters;

Expand Down Expand Up @@ -105,22 +106,26 @@ static __u64 match_event_symbols(const char *str)
__u64 config, id;
int type;
unsigned int i;
char mask_str[4];
const char *sep, *pstr;

if (sscanf(str, "r%llx", &config) == 1)
if (str[0] == 'r' && hex2u64(str + 1, &config) > 0)
return config | PERF_COUNTER_RAW_MASK;

switch (sscanf(str, "%d:%llu:%2s", &type, &id, mask_str)) {
case 3:
if (strchr(mask_str, 'k'))
pstr = str;
sep = strchr(pstr, ':');
if (sep) {
type = atoi(pstr);
pstr = sep + 1;
id = atoi(pstr);
sep = strchr(pstr, ':');
if (sep) {
pstr = sep + 1;
if (strchr(pstr, 'k'))
event_mask[nr_counters] |= EVENT_MASK_USER;
if (strchr(mask_str, 'u'))
if (strchr(pstr, 'u'))
event_mask[nr_counters] |= EVENT_MASK_KERNEL;
case 2:
return EID(type, id);

default:
break;
}
return EID(type, id);
}

for (i = 0; i < ARRAY_SIZE(event_symbols); i++) {
Expand Down
38 changes: 3 additions & 35 deletions trunk/Documentation/perf_counter/util/symbol.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "util.h"
#include "../perf.h"
#include "string.h"
#include "symbol.h"

#include <libelf.h>
Expand Down Expand Up @@ -122,39 +123,6 @@ size_t dso__fprintf(struct dso *self, FILE *fp)
return ret;
}

static int hex(char ch)
{
if ((ch >= '0') && (ch <= '9'))
return ch - '0';
if ((ch >= 'a') && (ch <= 'f'))
return ch - 'a' + 10;
if ((ch >= 'A') && (ch <= 'F'))
return ch - 'A' + 10;
return -1;
}

/*
* While we find nice hex chars, build a long_val.
* Return number of chars processed.
*/
static int hex2long(char *ptr, unsigned long *long_val)
{
const char *p = ptr;
*long_val = 0;

while (*p) {
const int hex_val = hex(*p);

if (hex_val < 0)
break;

*long_val = (*long_val << 4) | hex_val;
p++;
}

return p - ptr;
}

static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter)
{
struct rb_node *nd, *prevnd;
Expand All @@ -166,7 +134,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter)
goto out_failure;

while (!feof(file)) {
unsigned long start;
__u64 start;
struct symbol *sym;
int line_len, len;
char symbol_type;
Expand All @@ -180,7 +148,7 @@ static int dso__load_kallsyms(struct dso *self, symbol_filter_t filter)

line[--line_len] = '\0'; /* \n */

len = hex2long(line, &start);
len = hex2u64(line, &start);

len++;
if (len + 2 >= line_len)
Expand Down

0 comments on commit cace1ef

Please sign in to comment.