int main(int argc, char **argv) { const char *usage = "%s string\n\n" " Returns the geopm_hash() of the input string.\n" " this is useful for determining the region name\n" " from the region_id printed in the trace.\n" " Note the mpi-runtime and epoch regions have\n" " special region IDs:\n" " mpi-runtime: 4611686018427387904\n" " epoch: 9223372036854775808\n\n"; if (argc == 1 || strncmp("-h", argv[1], strlen("-h")) == 0 || strncmp("--help", argv[1], strlen("--help")) == 0) { printf(usage, argv[0]); } else { printf("%llu\n", (unsigned long long)geopm_crc32_str(0, argv[1])); } return 0; }
uint64_t ProfileTable::key(const std::string &name) { uint64_t result = 0; int err = pthread_mutex_lock(&(m_key_map_lock)); if (err) { throw Exception("ProfileTable::key(): pthread_mutex_lock()", err, __FILE__, __LINE__); } auto key_map_it = m_key_map.find(name); err = pthread_mutex_unlock(&(m_key_map_lock)); if (err) { throw Exception("ProfileTable::key(): pthread_mutex_unlock()", err, __FILE__, __LINE__); } if (key_map_it != m_key_map.end()) { result = key_map_it->second; } else { result = geopm_crc32_str(0, (char *)(&name.front())); if (!result) { throw Exception("ProfileTable::key(): CRC 32 hashed to zero!", GEOPM_ERROR_RUNTIME, __FILE__, __LINE__); } err = pthread_mutex_lock(&(m_key_map_lock)); if (err) { throw Exception("ProfileTable::key(): pthread_mutex_lock()", err, __FILE__, __LINE__); } if (m_key_set.find(result) != m_key_set.end()) { throw Exception("ProfileTable::key(): String hash collision", GEOPM_ERROR_RUNTIME, __FILE__, __LINE__); } m_key_set.insert(result); m_key_map.insert(std::pair<const std::string, uint64_t>(name, result)); m_key_map_last = m_key_map.begin(); err = pthread_mutex_unlock(&(m_key_map_lock)); if (err) { throw Exception("ProfileTable::key(): pthread_mutex_unlock()", err, __FILE__, __LINE__); } } return result; }