--- /dev/null
+package file_summary_by_instance
+
+import (
+ "errors"
+
+ // "github.com/sjmudd/pstop/lib"
+)
+
+// provide a mapping from filename to table.schema etc
+
+var (
+ mapped_name map[string]string
+ total, matched int
+)
+
+func init() {
+ // setup on startup
+ mapped_name = make(map[string]string)
+}
+
+func get_from_cache(key string) (result string, err error) {
+ total++
+ if result, ok := mapped_name[key]; ok {
+ matched++
+ // lib.Logger.Println("matched/total:", matched, total)
+ return result, nil
+ } else {
+ // lib.Logger.Println("matched/total:", matched, total)
+ return "", errors.New("Not found")
+ }
+}
+
+func save_to_cache(key, value string) string {
+ mapped_name[key] = value
+ return value
+}
import (
"database/sql"
+ "fmt"
"time"
"github.com/sjmudd/pstop/lib"
}
func (t File_summary_by_instance) Description() string {
- return "File I/O by filename (file_summary_by_instance)"
+ count := t.count_rows()
+ return fmt.Sprintf("File I/O by filename (file_summary_by_instance) %4d row(s) ", count)
}
// create a new structure and include various variable values:
return n
}
+
+func (t File_summary_by_instance) count_rows() int {
+ var count int
+ for row := range t.results {
+ if t.results[row].SUM_TIMER_WAIT > 0 {
+ count++
+ }
+ }
+ return count
+}
path := t.FILE_NAME
+ if cached_result, err := get_from_cache(path); err == nil {
+ return cached_result
+ }
+
// FIXME and make this work.
// re4 := regexp.MustCompile(re_encoded)
// if m4 := re4.FindStringSubmatch(path); m4 != nil {
if m1 := re_table_file.FindStringSubmatch(path); m1 != nil {
// we may match temporary tables so check for them
if m2 := re_temp_table.FindStringSubmatch(m1[2]); m2 != nil {
- return "<temp_table>"
+ return save_to_cache(path, "<temp_table>")
}
// we may match partitioned tables so check for them
if m3 := re_part_table.FindStringSubmatch(m1[2]); m3 != nil {
- return m1[1] + "." + m3[1] // <schema>.<table> (less partition info)
+ return save_to_cache(path, m1[1]+"."+m3[1]) // <schema>.<table> (less partition info)
}
- return m1[1] + "." + m1[2] // <schema>.<table>
+ return save_to_cache(path, m1[1]+"."+m1[2]) // <schema>.<table>
}
if re_ibdata.MatchString(path) == true {
- return "<ibdata>"
+ return save_to_cache(path, "<ibdata>")
}
if re_redo_log.MatchString(path) == true {
- return "<redo_log>"
+ return save_to_cache(path, "<redo_log>")
}
if re_binlog.MatchString(path) == true {
- return "<binlog>"
+ return save_to_cache(path, "<binlog>")
}
if re_db_opt.MatchString(path) == true {
- return "<db_opt>"
+ return save_to_cache(path, "<db_opt>")
}
if re_slowlog.MatchString(path) == true {
- return "<slow_log>"
+ return save_to_cache(path, "<slow_log>")
}
if re_auto_cnf.MatchString(path) == true {
- return "<auto_cnf>"
+ return save_to_cache(path, "<auto_cnf>")
}
// relay logs are a bit complicated. If a full path then easy to
// identify,but if a relative path we may need to add $datadir,
}
re_relay_log := relay_log + `\.(\d{6}|index)$`
if regexp.MustCompile(re_relay_log).MatchString(path) == true {
- return "<relay_log>"
+ return save_to_cache(path, "<relay_log>")
}
}
if re_pid_file.MatchString(path) == true {
- return "<pid_file>"
+ return save_to_cache(path, "<pid_file>")
}
if re_error_msg.MatchString(path) == true {
- return "<errmsg>"
+ return save_to_cache(path, "<errmsg>")
}
if re_charset.MatchString(path) == true {
- return "<charset>"
+ return save_to_cache(path, "<charset>")
}
- return path
+ return save_to_cache(path, path)
}
// Convert the imported "table" to a merged one with merged data.