File: bpf-shared-globals.h

package info (click to toggle)
systemtap 5.1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 47,964 kB
  • sloc: cpp: 80,838; ansic: 54,757; xml: 49,725; exp: 43,665; sh: 11,527; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (78 lines) | stat: -rw-r--r-- 2,398 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// bpf globals functionality shared between translator and stapbpf
// Copyright (C) 2016-2021 Red Hat Inc.
//
// This file is part of systemtap, and is free software.  You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.

#ifndef BPF_SHARED_GLOBALS_H
#define BPF_SHARED_GLOBALS_H

namespace bpf {

// PR23476 List of percpu stat fields (see struct stat_data in runtime/stat.h).
std::vector<globals::stat_field> globals::stat_fields {
  "count", "sum", // for @count(), @sum(), @avg()
  // TODO: also "shift"
  // TODO: "min", "max", // for @min(), @max()
  // TODO: "avg_s", "_M2", "variance", "variance_s", // for @variance()
  // TODO: "histogram", // PR24424 for @hist_linear(), @hist_log()
};

// XXX Use the map for this field when iterating keys or testing inclusion:
std::string globals::stat_iter_field = "count";

globals::interned_stats_map
globals::intern_stats_map(const globals::stats_map &sm) {
  globals::interned_stats_map ism;
  for (globals::stat_field sf : globals::stat_fields)
    {
      auto it = sm.find(sf);
      assert (it != sm.end());
      ism.push_back(it->second);
    }
  return ism;
}

globals::stats_map
globals::deintern_stats_map(const globals::interned_stats_map &ism) {
  globals::stats_map sm;
  for (unsigned i = 0; i < std::min(ism.size(), globals::stat_fields.size()); i++)
    {
      globals::stat_field sf = globals::stat_fields[i];
      globals::map_idx map_id = ism[i];
      sm[sf] = map_id;
    }
  return sm;
}

globals::interned_foreach_info
globals::intern_foreach_info(const globals::foreach_info &fi) {
  globals::interned_foreach_info ifi{
    (uint64_t)fi.sort_direction,
    (uint64_t)fi.sort_column,
    (uint64_t)fi.keysize,
    (uint64_t)fi.sort_column_size,
    (uint64_t)fi.sort_column_ofs,
  };
  return ifi;
}

globals::foreach_info
globals::deintern_foreach_info(const globals::interned_foreach_info &ifi) {
  assert(ifi.size() == globals::n_foreach_info_fields);
  // XXX could handle older versions depending on ifi.size()
  // eventually we'll need a magic string for .bo versioning
  globals::foreach_info fi;
  fi.sort_direction = (int)ifi[0];
  fi.sort_column = (unsigned)ifi[1];
  fi.keysize = (size_t)ifi[2];
  fi.sort_column_size = (size_t)ifi[3];
  fi.sort_column_ofs = (int)ifi[4];
  return fi;
}

};

#endif